-
Notifications
You must be signed in to change notification settings - Fork 7
/
Request.tcl
349 lines (319 loc) · 12.1 KB
/
Request.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
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
#################################################################################
# dZSbot/ngBot - Request Plug-in v0.2.5 #
#################################################################################
#
# Requirements:
# - NickDb.tcl installed and operational.
# - cpt-request.sh
#
# Description:
# - Can create/fill/wipe/del requests from either within glftpd, or from irc (if
# using NickDb.tcl)
# - Thanks to NickDb, we will know which user is actually making the request. Old
# requestscripts always used the irc nickname. This might prevent trouble.
#
# Important notes:
# - This script is not finished, but it is working. It's not using the nicest
# code either, but it should be easy to modify it to suit your own needs.
# - If you have some feedback on my crappy code, please tell me on irc:
# compieter@EFnet. Feature requests/suggestions are always welcome, but please
# note that i (try to) have a social life too.
#
# Installation:
# 1. copy cpt-request.sh to your glftpd/bin directory
# http://compieter.nl.eu.org/scripts/cpt-request.sh
#
# 2. Edit the configuration options below.
#
# 3. Add the following to your eggdrop.conf:
# source pzs-ng/plugins/Request.tcl
#
# 4. Add the following lines to your dZSbot.conf (the default settings for REQUEST should be okay):
# set variables(REQFILL) "%releasename %u_name %g_name %u_tagline %u_requester %g_requester"
# set variables(REQWIPE) "%releasename %u_name %g_name %u_tagline %u_requester %g_requester"
# set variables(REQDEL) "%releasename %u_name %g_name %u_tagline"
# set variables(FILLEDMSG) "%date %u_requester %g_requester %u_filler %g_filler %releasename"
# set variables(REQMSG) "%msg"
#
# set disable(REQFILL) 0
# set disable(REQWIPE) 0
# set disable(REQDEL) 0
# set disable(REQMSG) 0
# set disable(FILLEDMSG) 0
#
# 5. Add the following line to your theme file (defaults for REQUEST are okay again):
# announce.REQFILL = "[%b{filled}] %b{%u_name} of %g_name just filled %b{%releasename} for %b{%u_requester}."
# announce.REQWIPE = "[%b{r-wipe}] %b{%u_name} of %g_name just reqwiped %b{%releasename}. Too bad %b{%u_requester} ;)"
# announce.REQDEL = "[%b{reqdel}] %b{%u_name} of %g_name just deleted his request (%b{%releasename})."
# announce.REQMSG = "[%b{reqmsg}] %msg"
# announce.FILLEDMSG = "Hello %u_requester. Your request(%releasename) has been filled by %b{%u_filler} on %b{%date}. Go give him/her a nice hug."
#
# 6. Add "REQFILL REQWIPE REQDEL REQMSG FILLEDMSG" to the msgtypes(DEFAULT) array (in dZSbot.conf
# or dZSbot.conf.defaults. Please note that .defaults will be overwritten on updates)
#
# 7. Rehash or restart your eggdrop for the changes to take effect.
#
#################################################################################
namespace eval ::ngBot::plugin::Request {
variable ns [namespace current]
## Config Settings ###############################
##
## Choose one of two settings, the first when using ngBot, the second when using dZSbot
variable np [namespace qualifiers [namespace parent]]
#variable np ""
##
## Path to your requestscript. Please note that only cpt-request works with
## this tcl, but maybe tur will change his script?
variable reqscript "/glftpd/bin/cpt-request.sh"
##
## Permissions! who can request?
## Leave the default to allow siteops, nukers and users with flag +J to request
variable permsrequest "1 A J =siteops"
##
## Permissions! who can wipe requests?
## Leave the default to allow siteops, nukers and users with flag +J to wipe
variable permswipe "1 =siteops"
##
## Display debug information? It's not really usable info, best to disable it
variable debug False
##################################################
namespace import ${np}::plugin::NickDb::*
# bind evnt -|- prerehash [namespace current]::DeInit
interp alias {} IsTrue {} string is true -strict
interp alias {} IsFalse {} string is false -strict
if {[string equal "" $np]} {
bind evnt -|- prerehash ${ns}::deinit
}
####
# init
#
# Called on initialization; registers the event handler. Yeah, nothing fancy.
#
proc init {} {
variable ns
## Bind event callbacks.
bind pub -|- !request ${ns}::Request
bind pub -|- !reqwipe ${ns}::Reqwipe
bind pub -|- !reqdel ${ns}::Reqdel
bind pub -|- !reqfill ${ns}::Reqfill
bind pub -|- !reqfilled ${ns}::Reqfill
bind pub -|- !requests ${ns}::Reqlist
# bind join -|- "*" ${ns}::OnJoin
putlog "\[ngBot\] Request :: Loaded successfully."
return
}
####
# deinit
#
# Called on rehash; unregisters the event handler.
#
proc deinit {args} {
variable ns
## Remove event callbacks.
catch {unbind pub -|- "!request" ${ns}::Request}
catch {unbind pub -|- "!reqwipe" ${ns}::Reqwipe}
catch {unbind pub -|- "!reqdel" ${ns}::Reqdel}
catch {unbind pub -|- "!reqfill" ${ns}::Reqfill}
catch {unbind pub -|- "!reqfilled" ${ns}::Reqfill}
catch {unbind pub -|- "!requests" ${ns}::Reqlist}
#catch {unbind evnt -|- prerehash ${ns}::DeInit}
catch {unbind join -|- "*" ${ns}::OnJoin}
namespace delete $ns
return
}
####
# GetInfo
#
# gets $group and $flags from the userfile
#
proc GetInfo {ftpUser groupVar flagsVar} {
variable np
global ${np}::location
upvar $groupVar group $flagsVar flags
set group ""; set flags ""
if {![catch {set handle [open "$location(USERS)/$ftpUser" r]} error]} {
set data [read $handle]
close $handle
foreach line [split $data "\n"] {
switch -exact -- [lindex $line 0] {
"FLAGS" {set flags [lindex $line 1]}
"GROUP" {set group [lindex $line 1]}
}
}
return 1
} else {
putlog "\[ngBot\] error: Unable to open user file for \"$ftpUser\" ($error)."
return 0
}
}
####
# Request
#
# Add a new request
#
proc Request {nick host handle channel text} {
variable np
global ${np}::location
variable reqscript
variable debug
variable permsrequest
set ftpUser [GetFtpUser $nick]
if {[string equal "" $nick]} {return}
if {[GetInfo $ftpUser group flags]} {
if {[${np}::rightscheck $permsrequest $ftpUser $group $flags]} {
foreach line [split [exec $reqscript $ftpUser add $text] "\n"] {
if {[IsFalse $debug]} {
if { [lindex $line 0] != "DEBUG:" } {
puthelp "PRIVMSG $channel :$line"
}
} elseif { [lindex $line 0] == "REQMSG:" } {
${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
} else {
puthelp "PRIVMSG $channel :$line"
}
}
} else {
set line "Sorry, you're not allowed to request."
# ${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
puthelp "PRIVMSG $channel :$line"
}
} else {
set line "Sorry, you don't exist. Try inviting yourself again."
# ${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
puthelp "PRIVMSG $channel :$line"
}
}
####
# Reqwipe
#
# Wipes requests! isn't it amazing?
#
proc Reqwipe {nick host handle channel text} {
variable np
global ${np}::location
variable reqscript
variable debug
variable permswipe
set ftpUser [GetFtpUser $nick]
if {[string equal "" $nick]} {return}
if {[GetInfo $ftpUser group flags]} {
if {[${np}::rightscheck $permswipe $ftpUser $group $flags]} {
foreach line [split [exec $reqscript $ftpUser wipe $text] "\n"] {
if {[IsFalse $debug]} {
if { [lindex $line 0] != "DEBUG:" } {
puthelp "PRIVMSG $channel :$line"
}
} elseif { [lindex $line 0] == "REQMSG:" } {
${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
} else {
puthelp "PRIVMSG $channel :$line"
}
}
} else {
set line "Sorry, you're not allowed to wipe requests."
puthelp "PRIVMSG $channel :$line"
# ${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
}
}
}
####
# Reqdel
#
# Deletes requests! things keep on getter better and better
#
variable np
proc Reqdel {nick host handle channel text} {
variable reqscript
variable debug
set ftpUser [GetFtpUser $nick]
if {[string equal "" $nick]} {return}
foreach line [split [exec $reqscript $ftpUser del $text] "\n"] {
if {[IsFalse $debug]} {
if { [lindex $line 0] != "DEBUG:" } {
puthelp "PRIVMSG $channel :$line"
}
} elseif { [lindex $line 0] == "REQMSG:"} {
${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
} else {
puthelp "PRIVMSG $channel :$line"
}
}
}
####
# Reqfill
#
# You know the drill.
#
variable np
proc Reqfill {nick host handle channel text} {
variable reqscript
variable debug
set ftpUser [GetFtpUser $nick]
if {[string equal "" $nick]} {return}
foreach line [split [exec $reqscript $ftpUser fill $text] "\n"] {
if {[IsFalse $debug]} {
if { [lindex $line 0] != "DEBUG:" } {
puthelp "PRIVMSG $channel :$line"
}
} elseif { [lindex $line 0] == "REQMSG:" } {
${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
} else {
puthelp "PRIVMSG $channel :$line"
}
}
}
####
# Reqlist
#
# Lists all the requests
#
proc Reqlist {nick host handle channel text} {
variable reqscript
variable debug
set ftpUser [GetFtpUser $nick]
if {[string equal "" $nick]} {return}
foreach line [split [exec $reqscript $ftpUser list $text] "\n"] {
if {[IsFalse $debug]} {
if { [lindex $line 0] != "DEBUG:" } {
putquick "PRIVMSG $channel :$line"
}
} else {
# ${np}::sndall REQMSG DEFAULT [ng_format "REQMSG" "DEFAULT" \"$line\"]
putquick "PRIVMSG $channel :$line"
}
}
}
####
# OnJoin
#
# Called when a user joins the channel.
#
proc OnJoin {nick host handle channel} {
variable reqscript
global announce
## Lookup the user's FTP user name.
set ftpUser [GetFtpUser $nick]
if {[string equal "" $nick]} {return}
set status [exec $reqscript $ftpUser joincheck]
if {[string equal "" $status]} {return}
set date [lindex $status 0]
set requester [lindex $status 1]
set requesterg [lindex $status 2]
set filler [lindex $status 3]
set fillerg [lindex $status 4]
set release [lindex $status 5]
set output [replacebasic $announce(FILLEDMSG) "FILLEDMSG"]
set output [replacevar $output "%date" $date]
set output [replacevar $output "%u_requester" $requester]
set output [replacevar $output "%g_requester" $requesterg]
set output [replacevar $output "%u_filler" $filler]
set output [replacevar $output "%g_filler" $fillerg]
set output [replacevar $output "%releasename" $release]
set output [themereplace $output "none"]
puthelp "NOTICE $nick :$output"
#return 1
}
}
if {[string equal "" $::ngBot::plugin::Request::np]} {
::ngBot::plugin::Request::init
}