-
Notifications
You must be signed in to change notification settings - Fork 0
/
topiclock.tcl
105 lines (79 loc) · 2.76 KB
/
topiclock.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
103
104
105
# Name Topic Lock
# Author wilk wilkowy
# Description Prevents topic changes by unpriviledged users
# Version 1.0 (2021..2021-06-27)
# License GNU GPL v2 or any later version
# Support https://www.quizpl.net
# Channel flags: topiclock
# Info:
# - linked bots are allowed to change topic
# - bots/helpers are chosen randomly for each topic bounce
# - if use_botnet is 1 then you need to have this script loaded on all bots and enabled for the same channels
namespace eval topiclock::c {
# Users having such flags can change topic. (use "" to disable)
variable ignored_users "m|n"
# Set to 1 if you have a linked botnet so the bot to fix the topic will be rolled by a dice.
# This requires all bots to have topiclock.tcl loaded and +topiclock channel flag, otherwise put them in ignored_bots.
variable use_botnet 1
# This bots will be removed from dice roll if use_botnet == 1.
variable ignored_bots [list]
# Put here *handles* of other bots considered as master topic bouncers for this one, while any of them is present on channel with @ then this bot will not recover changed topic.
variable master_bots [list]
}
# #################################################################### #
namespace eval topiclock {
variable version "1.0"
variable changed "2021-06-27"
variable author "wilk"
namespace eval v {
variable topic
}
proc on_topic {nick uhost hand chan topic} {
if {![channel get $chan topiclock]} { return }
if {![info exists v::topic($chan)] ||
$nick eq "*" ||
[isbotnick $nick] ||
($c::ignored_users ne "" && [matchattr $hand $c::ignored_users $chan]) ||
([matchattr $hand "b" $chan] && [islinked $nick])
} then {
set v::topic($chan) $topic
return
}
if {$topic ne $v::topic($chan) &&
(($c::use_botnet && [myturn "topiclock$nick$uhost$hand$topic" $chan 1 1 $c::ignored_bots]) ||
(!$c::use_botnet && ![chanhasop $chan $c::master_bots]))
} then {
if {[botisop $chan]} {
settopic $chan $v::topic($chan)
putlog "TopicLock: protected topic on $chan changed by $nick ($hand)"
} else {
putlog "TopicLock: unable to protect topic - need ops ($chan)"
}
}
}
# -=-=-=-=-=-
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 topiclock
bind topc - * ${ns}::on_topic
putlog "TopicLock v$version by $author"
}
proc unload {{keepns 0}} {
set ns [namespace current]
catch { unbind topc - * ${ns}::on_topic }
if {!$keepns} {
namespace delete $ns
}
}
proc uninstall {} {
unload
deludef flag topiclock
}
init
}