-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdefine.tcl
More file actions
369 lines (333 loc) · 13.2 KB
/
define.tcl
File metadata and controls
369 lines (333 loc) · 13.2 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
setctx sparhawk
bind pub - .custcmd listcmd
bind pub - .listcmd listcmd
bind pub - .setcmd setcmd
bind pub - .addalias aliascmd
bind pub - .appcmd appcmd
bind pub - .getcmd getcmd
bind pubm - "*" show_fct
setctx lains
bind pub - |custcmd listcmd
bind pub - |listcmd listcmd
bind pub - |setcmd setcmd
bind pub - |addalias aliascmd
bind pub - |appcmd appcmd
bind pub - |getcmd getcmd
bind pub - .custcmd listcmd
bind pub - .listcmd listcmd
bind pub - .setcmd setcmd
bind pub - .addalias aliascmd
bind pub - .appcmd appcmd
bind pub - .getcmd getcmd
bind pubm - "*" show_fct
global "dirname"
set dirname "custcmd"
proc create_db { chan cmd definfo } {
global dirname
if {[file exists $dirname] == 0} {
file mkdir $dirname
}
if {[file exists $dirname/$chan] == 0} {
file mkdir $dirname/$chan
}
if {[file exists $dirname/$chan/$cmd] == 0} {
set crtdb [open $dirname/$chan/$cmd a+]
puts $crtdb "$definfo"
close $crtdb
}
}
proc readdb { rdb } {
set fs_open [open $rdb r]
gets $fs_open dbout
close $fs_open
return $dbout
}
proc setcmd { nick userhost handle chan arg } {
global dirname
if {[isop $nick $chan] == 0 && [matchattr $handle o] == 0 } {
putnotc $nick "You need to be an op to create/edit custom channel commands"
return 0
}
set txt [split $arg]
set cmd [string tolower [lindex $txt 0]]
set cmd [string trimleft $cmd "./"]
set cmdf "${cmd}.cmd"
set msg [join [lrange $txt 1 end]]
if {$msg != ""} {
if {[file exists $dirname/$chan/${cmd}.alias] == 1} {
file delete $dirname/$chan/${cmd}.alias
putnotc $nick "Deleting alias with the name '${cmd}'"
}
if {[file exists $dirname/$chan/$cmdf] == 0} {
create_db "$chan" "$cmdf" "$msg"
putnotc $nick "Created custom command '.${cmd}' for channel $chan. Use .addalias <alias> <cmd> to create an alias."
} else {
set readdb [readdb $dirname/$chan/$cmdf]
file delete $dirname/$chan/$cmdf
create_db "$chan" "$cmdf" "$msg"
putnotc $nick "Modified custom command '.${cmd}' for channel $chan, remember .appcmd can pre/suffix existing commands. Old content:"
putnotc $nick "Custcmd '.${cmd}': $readdb"
}
} else {
if {[file exists $dirname/$chan/$cmdf] == 1 && $cmd != ""} {
set readdb [readdb $dirname/$chan/$cmdf]
file delete $dirname/$chan/$cmdf
putnotc $nick "Deleted custom command '.${cmd}' for channel $chan. Old content:"
putnotc $nick "Custcmd '.${cmd}': $readdb"
} else {
putnotc $nick "Custcmd '.${cmd}' doesn't currently exist, use .setcmd <cmd> <text>, to add it, or .custcmd to list existing commands."
}
}
}
proc setproc { chan cmd proc } {
global dirname
if {$proc != ""} {
if {[file exists $dirname/$chan/${cmd}.alias] == 1} {
file delete $dirname/$chan/${cmd}.alias
return "Deleting alias with the name '${cmd}'"
}
if {[file exists $dirname/$chan/${cmd}.cmd] == 1} {
set readdb [readdb $dirname/$chan/${cmd}.cmd]
file delete $dirname/$chan/${cmd}.cmd
return {{"Deleting cmd with the name '${cmd}'"}
{"Custcmd '.${cmd}': $readdb"}}
}
if {[file exists $dirname/$chan/${cmd}.proc] == 0} {
create_db "$chan" "${cmd}.proc" "$proc"
return "Created custom command '.${cmd}' for channel $chan."
} else {
file delete $dirname/$chan/${cmd}.proc
create_db "$chan" "${cmd}.proc" "$proc"
return "Modified custom command '.${cmd}' for channel $chan"
}
} else {
if {[file exists $dirname/$chan/${cmd}.proc] == 1 && $cmd != ""} {
set readdb [readdb $dirname/$chan/${cmd}.proc]
file delete $dirname/$chan/${cmd}.proc
return "Deleted custom command '.${cmd}' for channel $chan. Old content: $readdb"
} else {
return "Custcmd '.${cmd}' doesn't currently exist."
}
}
}
proc aliascmd { nick userhost handle chan arg } {
global dirname
if {[isop $nick $chan] == 0 && [matchattr $handle o] == 0 } {
putnotc $nick "You need to be an op to create/edit custom channel commands"
return 0
}
set txt [split $arg]
set alias [string tolower [lindex $txt 0]]
set alias [string trimleft $alias "./"]
set aliasf "${alias}.alias"
set cmd [string tolower [lindex $txt 1]]
set cmd [string trimleft $cmd "./"]
set cmdf "${cmd}.cmd"
set cmdp "${cmd}.proc"
if {$cmd != "" && $cmd != $alias} {
if {[file exists $dirname/$chan/$cmdf] == 0} {
if {[file exists $dirname/$chan/$cmdp] == 0} {
putnotc $nick "Command doesn't exist. You cannot alias a none existant command."
return 0
} else {
set cmdf $cmdp
}
}
if {[file exists $dirname/$chan/${alias}.cmd] == 1} {
set readdb [readdb $dirname/$chan/${alias}.cmd]
file delete $dirname/$chan/${alias}.cmd
putnotc $nick "Deleting command with the name '${alias}' Old content:"
putnotc $nick "Custcmd '.${alias}': $readdb"
}
if {[file exists $dirname/$chan/$aliasf] == 0} {
create_db "$chan" "$aliasf" "$cmdf"
putnotc $nick "Created alias '.${alias}' for custom command '.${cmd}' for channel $chan"
} else {
set readdb [readdb $dirname/$chan/$aliasf]
file delete $dirname/$chan/$aliasf
create_db "$chan" "$aliasf" "$cmdf"
putnotc $nick "Modified custom command alias '.${alias}' for channel $chan. Old content: $readdb"
}
} else {
if {[file exists $dirname/$chan/$aliasf] == 1 && $alias != ""} {
set readdb [readdb $dirname/$chan/$aliasf]
file delete $dirname/$chan/$aliasf
putnotc $nick "Deleted custom command alias '.${alias}' for channel $chan."
} else {
putnotc $nick "Custcmd '.${alias}' doesn't currently exist, use .setcmd <cmd> <text> to create a command or .addalias <cmd> <oldcmd> to create an alias."
}
}
}
proc bncnotc {text} { putclient ":-sBNC!core@shroudbnc.info PRIVMSG $::botnick :$text"; putmainlog "Debug: $text" }
proc show_fct { nick userhost handle chan text } {
set text [concat $text]
set command [lindex [split [string tolower $text] { }] 0]
set text [lrange [split $text { }] 1 end]
set method putchan
set target $chan
set prefix ""
if {([string index $command 0] == "|") || ([khfloodc $nick] >= 1)} {
set method putnotc
set target $nick
} elseif {([string index $command 0] != ".") && ([string index $command 0] != "+")} {
return
}
set tail [lindex $text end]
#If the last param begins with a @ then the message should be directed at that 'string'
if {[string index $tail 0] == "@"} {
set text [lrange $text 0 end-1]
set tail [string range $tail 1 end]
#If the last param began with @@ then the reply should be messaged to a player
if {[string index $tail 0] == "@"} {
set tail [string range $tail 1 end]
set validtarget [llength [split $tail {,}]]
foreach postarget [split $tail {,}] {
if {![onchan $postarget $chan]} {
set validtarget 0
}
}
set tail [join [split $tail {,}] {,}]
if {($validtarget > 0) && ([khfloodc $nick] < 1)} {
set method putnotc
set target "${nick},${tail}"
}
}
set prefix "${tail}: "
} elseif {[string index $tail end] == "@"} {
set text [lrange $text 0 end-1]
set tail [string range $tail 0 end-1]
#If the last param began with @@ then the reply should be messaged to a player
if {[string index $tail end] == "@"} {
set tail [string range $tail 0 end-1]
set validtarget [llength [split $tail {,}]]
foreach postarget [split $tail {,}] {
if {![onchan $postarget $chan]} {
set validtarget 0
}
}
set tail [join [split $tail {,}] {,}]
if {($validtarget > 0) && ($validtarget < 4) && ([khfloodc $nick] < 1)} {
set method putnotc
set target "${nick},${tail}"
}
}
set prefix "${tail}: "
}
set count 0
set return [showcmd $nick $userhost $handle $chan $chan $command [join $text { }]]
foreach line [split $return "\n"] {
incr count
if {[string length $line] > 1} {
$method $target "${prefix}${line}"
}
if {$count >= 3} { return }
}
}
proc getcmd { nick userhost handle chan text } {
if {[isop $nick $chan] == 0 && [matchattr $handle o] == 0 } {
return 0
}
set target $chan
set text [concat $text]
set command ".[lindex [split [string tolower $text] { }] 1]"
set chan [lindex [split [string tolower $text] { }] 0]
set text [lrange [split $text { }] 2 end]
set return [showcmd $nick $userhost $handle $chan $target $command $text]
if {([string index $text 0] == "|") || ([khfloodc $nick] >= 1)} {
set method putnotc
set target $nick
} else {
set method putchan
}
foreach line [split $return "\n"] {
if {[string length $line] > 1} {
$method $target $line
}
}
}
proc showcmd { nick userhost handle chan target command text } {
global dirname
set cmd [lindex [string tolower $command] 0]
set txt [string range $cmd 1 end]
set testtxt [string trimleft $txt "./"]
if {$txt != $testtxt} { return }
if {$txt != ""} {
if {([file exists $dirname/$chan/$txt.proc] == 1) && ($txt != "")} {
if {[khflood $nick] >= 2} { return }
set dbout [readdb $dirname/$chan/$txt.proc]
return [$dbout $nick $chan $text]
}
if {([file exists $dirname/$chan/$txt.cmd] == 1) && ($txt != "")} {
if {[khflood $nick] >= 2} { return }
set dbout [string map {{\n} "\n"} [readdb $dirname/$chan/$txt.cmd]]
set output ""
foreach line [split $dbout "\n"] {
if {[string length $line] > 1} {
append output "${command}: ${line}\n"
}
}
return $output
}
if {([file exists $dirname/$chan/$txt.alias] == 1) && ($txt != "")} {
set dbin [readdb $dirname/$chan/$txt.alias]
if {([file exists $dirname/$chan/$dbin] == 1) && ($dbin != "")} {
set dbin [lindex [split $dbin {.}] 0]
return [showcmd $nick $userhost $handle $chan $target ".$dbin" $text]
} else {
file delete $dirname/$chan/$txt.alias
}
}
}
}
proc appcmd { nick userhost handle chan arg } {
global dirname
if {[isop $nick $chan] == 0 && [matchattr $handle o] == 0 } {
putnotc $nick "You need to be an op to create/edit custom channel commands"
return 0
}
set txt [split $arg]
set start [lindex $txt 0]
set cmd [string tolower [lindex $txt 1]]
set cmdf "${cmd}.cmd"
set app_info [join [lrange $txt 2 end]]
if {$app_info != "" } {
if {[file exists $dirname/$chan/$cmdf] == 1} {
if {$start == "start"} {
set readdb [readdb $dirname/$chan/$cmdf]
file delete $dirname/$chan/$cmdf
create_db "$chan" "$cmdf" "$app_info $readdb"
putnotc $nick "Appended custom command '.${cmd}' for channel $chan, prefixing old text."
} elseif {$start == "end"} {
set readdb [readdb $dirname/$chan/$cmdf]
file delete $dirname/$chan/$cmdf
create_db "$chan" "$cmdf" "$readdb $app_info"
putnotc $nick "Appended custom command '.${cmd}' for channel $chan, suffixing old text."
} else {
putnotc $nick "Syntax for appending is .appcmd <start/end> <cmd> <text>"
}
} else {
create_db "$chan" "$cmdf" "$app_info"
putnotc $nick "Added custom command '.${cmd}' for channel $chan."
}
} else {
putnotc $nick "Syntax for appending is .appcmd <start/end> <cmd> <text>"
}
}
proc listcmd { nick userhost handle chan arg } {
global dirname
set cmd [glob -tails -directory $dirname/$chan -nocomplain -type f *.cmd]
set proc [glob -tails -directory $dirname/$chan -nocomplain -type f *.proc]
set cmd [lsort [string map {{.alias} {} {.cmd} {} {.proc} {}} $cmd]]
set proc [lsort [string map {{.alias} {} {.cmd} {} {.proc} {}} $proc]]
set i 0
if {[llength $cmd] < 90} {
while {$i < [llength $cmd]} {
putnotc $nick "\00304CustCmds for ${chan}:\003 [lrange $cmd $i [expr {$i + 45}]]"
incr i 46
}
} else {
putnotc $nick "\00304CustCmds for ${chan}:\003 http://sbnc.khobbits.co.uk/setcmd/commands/%23[string tolower [string trim $chan {#}]]"
}
putnotc $nick "\00304CustProc for ${chan}:\003 $proc \00304PublicCmds:\003 url log tail stats"
}
return "KHobbits magical custom commands, reloaded!"