-
Notifications
You must be signed in to change notification settings - Fork 0
/
note.etcl
executable file
·348 lines (342 loc) · 15 KB
/
note.etcl
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
###
# Usage: /msg botnick send <nick/chan[,nick/chan]> [-min level] [-max level] <message>
###
# Usage: /msg botnick read <new|all|N[n,n,n]>
###
# Usage: /msg botnick list <new|all[null]|old>
###
# Usage: /msg botnick del <all|new|n[,n,n,n]|old>
###
# Usage: /msg botnick purge
###
bind msg - send "msg_error msg_send"
bind msg - read "msg_error msg_read"
bind msg - list "msg_error msg_list"
bind msg - del "msg_error msg_del"
bind msg - purge "msg_error msg_purge"
proc msg_list {nick uhost handle text} {
global set
if {![validuser $handle]} {
return
} elseif {![nickinfo $handle auth]} {
notice $nick $handle "You are not yet authenticated."
} elseif {[nickinfo $handle userhost] != $uhost} {
notice $nick $handle "Your current userhost of '$uhost' is not the one you authenticated with."
} elseif {[string tolower [lindex $text 0]] == "new"} {
notice $nick $handle "\002***\002 Notebox contents at [ctime [unixtime]] $set(timezone) \002***\002"
notice $nick $handle "To read: \002read <number>\[,<number>\]\002 To delete: \002del <number>\[,<number>\]\002"
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] == "U"} {
if {[lindex $note 3] == ""} {
set type U
} else {
set type C
}
notice $nick $handle "[align [lindex $note 0] 3] $type [align [lindex $note 4] 15 " " R] [ctime [lindex $note 1]] $set(timezone) \002[lindex [lindex $note 3] 0]\002"
set cnt 1
}
}
if {!$cnt} {
notice $nick $handle "You have no new notes in your notebox"
}
} elseif {[string tolower [lindex $text 0]] == "" || [string tolower [lindex $text 0]] == "all"} {
notice $nick $handle "\002***\002 Notebox contents at [ctime [unixtime]] $set(timezone) \002***\002"
notice $nick $handle "To read: \002read <number>\[,<number>\]\002 To delete: \002del <number>\[,<number>\]\002"
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] == "U" && [lindex $note 3] == ""} {
set type U
} elseif {[lindex $note 2] == "U" && [lindex $note 3] != ""} {
set type C
} elseif {[lindex $note 2] == "R" && [lindex $note 3] == ""} {
set type R
} elseif {[lindex $note 2] == "R" && [lindex $note 3] != ""} {
set type c
} elseif {[lindex $note 2] == "D" && [lindex $note 3] == ""} {
set type D
} elseif {[lindex $note 2] == "D" && [lindex $note 3] != ""} {
set type d
}
notice $nick $handle "[align [lindex $note 0] 3] $type [align [lindex $note 4] 15 " " R] [ctime [lindex $note 1]] $set(timezone) \002[lindex [lindex $note 3] 0]\002"
set cnt 1
}
if {!$cnt} {
notice $nick $handle "You have no notes in your notebox"
}
} elseif {[string tolower [lindex $text 0]] == "old"} {
notice $nick $handle "\002***\002 Notebox contents at [ctime [unixtime]] $set(timezone) \002***\002"
notice $nick $handle "To read: \002read <number>\[,<number>\]\002 To delete: \002del <number>\[,<number>\]\002"
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] == "U"} {
continue
} elseif {[lindex $note 2] == "R" && [lindex $note 3] == ""} {
set type R
} elseif {[lindex $note 2] == "R" && [lindex $note 3] != ""} {
set type c
} elseif {[lindex $note 2] == "D" && [lindex $note 3] == ""} {
set type D
} elseif {[lindex $note 2] == "D" && [lindex $note 3] != ""} {
set type d
}
notice $nick $handle "[align [lindex $note 0] 3] $type [align [lindex $note 4] 15 " " R] [ctime [lindex $note 1]] $set(timezone) \002[lindex [lindex $note 3] 0]\002"
set cnt 1
}
if {!$cnt} {
notice $nick $handle "You have no old notes in your notebox"
}
} else {
notice $nick $handle "Invalid request: $text"
}
}
proc msg_read {nick uhost handle text} {
global set
if {![validuser $handle]} {
return
} elseif {![nickinfo $handle auth]} {
notice $nick $handle "You are not yet authenticated."
} elseif {[nickinfo $handle userhost] != $uhost} {
notice $nick $handle "Your current userhost of '$uhost' is not the one you authenticated with."
} elseif {[lindex $text 0] == ""} {
notice $nick $handle "Invalid request: What note numbers?"
} elseif {[string tolower [lindex $text 0]] == "new"} {
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] == "U"} {
notice $nick $handle "Note [lindex $note 0] from \002[lindex $note 4]\002 -- Sent \002[ctime [lindex $note 1]] $set(timezone)\002"
if {[lindex $note 3] == ""} {
notice $nick $handle [lindex $note 5]
} else {
notice $nick $handle "[lindex $note 4] -> \002[lindex [lindex $note 3] 0]\002 \[min: [align [lindex [lindex $note 3] 1] 3] max: [align [lindex [lindex $note 3] 2] 3]\]: [lindex $note 5]"
}
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] R \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
set cnt 1
}
}
if {!$cnt} {
notice $nick $handle "You have no new notes in your notebox"
}
} elseif {[string tolower [lindex $text 0]] == "old"} {
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] == "R" || [lindex $note 2] == "D"} {
notice $nick $handle "Note [lindex $note 0] from \002[lindex $note 4]\002 -- Sent \002[ctime [lindex $note 1]] $set(timezone)\002"
if {[lindex $note 3] == ""} {
notice $nick $handle [lindex $note 5]
} else {
notice $nick $handle "[lindex $note 4] -> \002[lindex [lindex $note 3] 0]\002 \[min: [align [lindex [lindex $note 3] 1] 3] max: [align [lindex [lindex $note 3] 2] 3]\]: [lindex $note 5]"
}
if {[lindex $note 2] == "D"} {
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] R \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
}
set cnt 1
}
}
if {!$cnt} {
notice $nick $handle "You have no old notes in your notebox"
}
} elseif {[string tolower [lindex $text 0]] == "all"} {
set cnt 0
foreach note [notelist $handle] {
notice $nick $handle "Note [lindex $note 0] from \002[lindex $note 4]\002 -- Sent \002[ctime [lindex $note 1]] $set(timezone)\002"
if {[lindex $note 3] == ""} {
notice $nick $handle [lindex $note 5]
} else {
notice $nick $handle "[lindex $note 4] -> \002[lindex [lindex $note 3] 0]\002 \[min: [align [lindex [lindex $note 3] 1] 3] max: [align [lindex [lindex $note 3] 2] 3]\]: [lindex $note 5]"
}
if {[lindex $note 2] == "D" || [lindex $note 2] == "U"} {
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] R \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
}
set cnt 1
}
if {!$cnt} {
notice $nick $handle "You have no notes in your notebox"
}
} elseif {[isnum [replace [lindex $text 0] , ""]] && ![string match *.* [lindex $text 0]]} {
foreach note [replace [lindex $text 0] , " "] {
set tmp [listfile $set(data.dir)/note.[file_change $handle] $note]
set note "$note [readfile $set(data.dir)/note.[file_change $handle] $tmp] $tmp"
if {[llength $note] > "1"} {
notice $nick $handle "Note [lindex $note 0] from \002[lindex $note 4]\002 -- Sent \002[ctime [lindex $note 1]] $set(timezone)\002"
if {[lindex $note 3] == ""} {
notice $nick $handle [lindex $note 5]
} else {
notice $nick $handle "[lindex $note 4] -> \002[lindex [lindex $note 3] 0]\002 \[min: [align [lindex [lindex $note 3] 1] 3] max: [align [lindex [lindex $note 3] 2] 3]\]: [lindex $note 5]"
}
if {[lindex $note 2] == "D" || [lindex $note 2] == "U"} {
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] R \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
}
}
}
} else {
notice $nick $handle "[lindex $text 0] is an invalid note"
}
}
proc msg_del {nick uhost handle text} {
global set
if {![validuser $handle]} {
return
} elseif {![nickinfo $handle auth]} {
notice $nick $handle "You are not yet authenticated."
} elseif {[nickinfo $handle userhost] != $uhost} {
notice $nick $handle "Your current userhost of '$uhost' is not the one you authenticated with."
} elseif {[lindex $text 0] == ""} {
notice $nick $handle "Invalid request: Which notes?"
} elseif {[string tolower [lindex $text 0]] == "all"} {
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] != "D"} {
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] D \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
incr cnt 1
}
}
if {$cnt == "0"} {
notice $nick $handle "There are no notes to delete in your notebox"
} else {
notice $nick $handle "Marked $cnt notes as being deleted"
}
} elseif {[string tolower [lindex $text 0]] == "old"} {
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] == "R" && [lindex $note 2] != "D"} {
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] D \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
incr cnt 1
}
}
if {$cnt == "0"} {
notice $nick $handle "There are no notes to delete in your notebox"
} else {
notice $nick $handle "Marked $cnt notes as being deleted"
}
} elseif {[string tolower [lindex $text 0]] == "new"} {
set cnt 0
foreach note [notelist $handle] {
if {[lindex $note 2] == "U" && [lindex $note 2] != "D"} {
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] D \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
incr cnt 1
}
}
if {$cnt == "0"} {
notice $nick $handle "There are no notes to delete in your notebox"
} else {
notice $nick $handle "Marked $cnt notes as being deleted"
}
} else {
set cnt 0
foreach note [replace [lindex $text 0] , " "] {
set tmp [listfile $set(data.dir)/note.[file_change $handle] $note]
set note "$note [readfile $set(data.dir)/note.[file_change $handle] $tmp] $tmp"
if {[llength $note] > "1" && [lindex $note 2] != "D"} {
writefile $set(data.dir)/note.[file_change $handle] [lindex $note 6] "[lindex $note 1] D \{[lindex $note 3]\} [lindex $note 4] \{[lindex $note 5]\}"
incr cnt 1
}
}
if {$cnt == "0"} {
notice $nick $handle "There are no notes to delete in your notebox"
} else {
notice $nick $handle "Marked $cnt notes as being deleted"
}
}
}
proc msg_send {nick uhost handle text} {
global set botnick
if {![validuser $handle]} {
return
} elseif {![nickinfo $handle auth]} {
notice $nick $handle "You are not yet authenticated."
} elseif {[nickinfo $handle userhost] != $uhost} {
notice $nick $handle "Your current userhost of '$uhost' is not the one you authenticated with."
} elseif {[lindex $text 0] == ""} {
notice $nick $handle "Invalid request: Send to who?"
} elseif {[lindex $text 1] == ""} {
notice $nick $handle "Invalid request: Wheres the note?"
} else {
set min 0
set max 200
set cn 1
set note ""
while {[lindex $text $cn] != ""} {
set w [string tolower [lindex $text $cn]]
set wd [string tolower [lindex $text [expr $cn + 1]]]
if {[letters $w 3 1] == "-mi" && [string length $w] <= "4" && [isnum $wd]} {
set min $wd
incr cn 2
} elseif {[letters $w 3 1] == "-ma" && [string length $w] <= "4" && [isnum $wd]} {
set max $wd
incr cn 2
} elseif {![string match -* $w]} {
set note "$note[lindex $text $cn] "
incr cn 1
} else {
incr cn 1
}
}
if {$max > "200" || $max < "0"} {
set max 200
}
if {$min > "200" || $min < "0"} {
set min 0
}
foreach target [replace [lindex $text 0] , " "] {
if {[string match #* $target] && [level $handle $target] == "0"} {
notice $nick $handle "You do not have access to $target"
} elseif {[string match #* $target] && ![changet $target active]} {
notice $nick $handle "$target is not currently currently activated."
} elseif {[string match #* $target] && [level $handle $target] < [changet $target nonote]} {
notice $nick $handle "Your level of [level $handle $target] in $target is less than the required level of [changet $target nonote] for this command"
} elseif {[string match #* $target]} {
set nnicks ""
set mnicks ""
set tnicks 0
foreach n [access $target] {
if {[level $n $target] >= $min && [level $n $target] <= $max} {
writefile $set(data.dir)/note.[file_change $n] [unixtime]$handle[rand 9] "[unixtime] U {$target $min $max} $handle {$note}"
incr tnicks 1
if {[notify $n] && [nickinfo $n interface]} {
set mnicks $mnicks,$n
} elseif {[notify $n] && ![nickinfo $n interface]} {
set nnicks $nnicks,$n
}
}
}
if {$nnicks != ""} {
notice $nnicks "" "You just received a channel note from $nick \[$handle\]. \002/msg $botnick read new\002"
}
if {$mnicks != ""} {
msg $mnicks "You just received a channel note from $nick \[$handle\]. \002/msg $botnick read new\002"
}
notice $nick $handle "$tnicks people on $target received your note"
} elseif {![validuser $target]} {
notice $nick $handle "$target is not a valid nickname."
} elseif {[validuser $target]} {
writefile $set(data.dir)/note.[file_change $target] [unixtime]$handle[rand 9] "[unixtime] U {} $handle {$note}"
if {[notify $target]} {
notice $target $target "You just received a note from $nick \[$handle\]. \002/msg $botnick read [llength [notelist $target]]\002"
notice $nick $handle "$target is online, and note has been delivered"
} else {
notice $nick $handle "Your note has been stored in $target's notebox"
}
} else {
script_error msg_send "else at end of statement is wrong."
}
}
}
}
proc msg_purge {nick uhost handle text} {
global set
if {![validuser $handle]} {
return
} elseif {![nickinfo $handle auth]} {
notice $nick $handle "You are not yet authenticated."
} elseif {[nickinfo $handle userhost] != $uhost} {
notice $nick $handle "Your current userhost of '$uhost' is not the one you authenticated with."
} else {
foreach note [notelist $handle] {
if {[lindex $note 2] == "D"} {
remfile $set(data.dir)/note.[file_change $handle] [lindex $note 6]
}
}
notice $nick $handle "Purged notes marked as 'D'eleted"
}
}