-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoinmsg.tcl
102 lines (78 loc) · 2.81 KB
/
joinmsg.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Name JoinMsg
# Author wilk wilkowy
# Description Sends message to users joining a channel
# Version 1.1 (2018..2019-04-25)
# License GNU GPL v2 or any later version
# Support https://www.quizpl.net
# Channel flags: joinmsg
namespace eval joinmsg::c {
# Users having such flags are ignored and receive no invitation message. (use "" to disable)
variable ignored_users "I|I"
# Protect against join floods, in seconds. (0 - off)
variable antiflood_delay 2
# Messages sent to joining users. Chosen randomly from list. Use *lowercase* channel names, nicks, handles and hosts!
# Available placeholders: #NICK#, #HAND#, #CHAN#
# Three types of messages are supported:
# message(chan,&handle) [list "..."] - this is sent to joining user recognized for this handle
# message(chan,nick) [list "..."] - this is sent to joining user with this nick
# message(chan) [list "..."] - this is default greeting message (sent if none of above were found)
variable message
#set message(#...) [list "..."]
}
# #################################################################### #
namespace eval joinmsg {
variable version "1.1"
variable changed "2019-04-25"
variable author "wilk"
namespace eval v {
variable flood_gate
}
proc on_join {nick uhost hand chan} {
set now [unixtime]
if {![channel get $chan joinmsg] ||
($c::ignored_users ne "" && [matchattr $hand $c::ignored_users $chan]) ||
([info exists v::flood_gate($chan)] && ($now - $v::flood_gate($chan) < $c::antiflood_delay))} { return }
set v::flood_gate($chan) $now
set lchan [string tolower $chan]
set lnick [string tolower $nick]
set lhand [string tolower $hand]
if {$hand ne "" && $hand ne "*" && [info exists c::message($lchan,&$lhand)] && [llength $c::message($lchan,&$lhand)] > 0} {
set msg [lrandom $c::message($lchan,&$lhand)]
} elseif {[info exists c::message($lchan,$lnick)] && [llength $c::message($lchan,$lnick)] > 0} {
set msg [lrandom $c::message($lchan,$lnick)]
} elseif {[info exists c::message($lchan)] && [llength $c::message($lchan)] > 0} {
set msg [lrandom $c::message($lchan)]
} else {
return
}
if {$msg ne ""} {
putlog "JoinMsg: on-join message for $nick ($hand) on $chan"
sendmsg $chan [string map [list "#NICK#" $nick "#HAND#" $hand "#CHAN#" $chan] $msg]
}
}
# -=-=-=-=-=-
proc init {} {
variable version; variable author
set ns [namespace current]
if {![info exists ::wilk::version]} {
uplevel #0 source [file dirname [info script]]/wilk.tcl
}
namespace import ::wilk::*
::wilk::register $ns
setudef flag joinmsg
bind join - * ${ns}::on_join
putlog "JoinMsg v$version by $author"
}
proc unload {{keepns 0}} {
set ns [namespace current]
catch { unbind join - * ${ns}::on_join }
if {!$keepns} {
namespace delete $ns
}
}
proc uninstall {} {
unload
deludef flag joinmsg
}
init
}