-
Notifications
You must be signed in to change notification settings - Fork 0
/
learn.tcl
261 lines (204 loc) · 5.78 KB
/
learn.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
# description: store some various information, new information can be added by public command !add and after
# you can view this info by typing ? <command_name>
# use: run script, and use !help on the channel, only op can add, replace, delete, rename, append
# if you want to allow normal users to add/del/rep etc. you have to change bind from o|o to -|-
# Author: tomekk
# e-mail: tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
# tradotto in italiano da Carlin0 <[email protected]>
#
# Version 0.6
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html
# added: some notices
# added: !stored command, shows stored commands
# fixed: removed !help command, now each command has its own help, just type !<command_name> without arguments
# added: now its possible to set on which channels should this script work
# if you want to use this script on your chan, type in eggdrop console (via telnet or DCC chat)
# .chanset #channel_name +learn
# and later .save
# available commands: !add, !del, !rep, !app, !ren, ? <cmd_name>, !stored
# dir with stored files
set dirname "learn.db"
################################################################################################
bind pub f|f !add add_fct
bind pub m|m !del del_fct
bind pub f|f !rep rep_fct
bind pub f|f !app app_fct
bind pub f|f !ren ren_fct
bind pub - ? show_fct
bind pub - !stored stored_cmds
bind pub - !elenco stored_cmds
setudef flag learn
if {[file exists $dirname] == 0} {
file mkdir $dirname
}
proc create_db { dbname definfo } {
if {[file exists $dbname] == 0} {
set crtdb [open $dbname a+]
puts $crtdb "$definfo"
close $crtdb
}
}
proc readdb { rdb } {
global dbout
set fs_open [open $rdb r]
gets $fs_open dbout
close $fs_open
}
proc add_fct { nick uhost hand chan arg } {
global dirname
if {![channel get $chan learn]} {
return
}
set txt [split $arg]
set cmd [string tolower [lindex $txt 0]]
set msg [join [lrange $txt 1 end]]
if {$msg != ""} {
if {[file exists $dirname/$cmd] == 0} {
create_db "$dirname/$cmd" "$msg"
putquick "NOTICE $nick :'$cmd' é stato aggiunto"
} {
putquick "NOTICE $nick :'$cmd' ha già una definizione"
}
} {
putquick "NOTICE $nick :scrivi: !add <cmd_name> <info>"
}
}
proc show_fct { nick uhost hand chan arg } {
global dbout dirname
if {![channel get $chan learn]} {
return
}
set txt [string tolower [split $arg]]
set cmd [lindex $txt 0]
if {$cmd != ""} {
foreach files $txt {
if {$files != ""} {
if {[file exists $dirname/$files] == 1} {
readdb $dirname/$files
putquick "PRIVMSG $chan :$files: $dbout"
} {
putquick "NOTICE $chan :'$files' non esiste"
}
}
}
} {
putquick "NOTICE $nick :scrivi: ? <cmd_name> ... <cmd_name>"
}
}
proc del_fct { nick uhost hand chan arg } {
global dirname
if {![channel get $chan learn]} {
return
}
set all_files [glob -tails -directory $dirname -nocomplain -type f *]
set txt [string tolower [split $arg]]
set cmd [lindex $txt 0]
if {$cmd != ""} {
if {$cmd == "all_cmds"} {
foreach xfiles $all_files {
file delete $dirname/$xfiles
putquick "NOTICE $nick :tutti i comandi sono stati cancellati"
}
}
if {$cmd != "all_cmds"} {
foreach files $txt {
if {$files != ""} {
if {[file exists $dirname/$files] == 1} {
file delete $dirname/$files
putquick "NOTICE $nick :'$cmd' é stato cancellato"
} {
putquick "NOTICE $nick :'$cmd' non esiste"
}
}
}
}
} {
putquick "NOTICE $nick :scrivi: !del all_cmds o !del <cmd_name> ... <cmd_name>"
}
}
proc rep_fct { nick uhost hand chan arg } {
global dirname
if {![channel get $chan learn]} {
return
}
set txt [split $arg]
set cmd [string tolower [lindex $txt 0]]
set msg [join [lrange $txt 1 end]]
if {$msg != ""} {
if {[file exists $dirname/$cmd] == 1} {
file delete $dirname/$cmd
create_db "$dirname/$cmd" "$msg"
putquick "NOTICE $nick :'$cmd' é stato cambiato"
} {
putquick "NOTICE $nick :'$cmd' non esiste"
}
} {
putquick "NOTICE $nick :scrivi: !rep <cmd_name> <new_info>"
}
}
proc app_fct { nick uhost hand chan arg } {
global dirname dbout
if {![channel get $chan learn]} {
return
}
set txt [split $arg]
set start [lindex $txt 0]
set cmd [string tolower [lindex $txt 1]]
set app_info [join [lrange $txt 2 end]]
if {$app_info != "" } {
if {[file exists $dirname/$cmd] == 1} {
if {$start == "fb"} {
readdb $dirname/$cmd
file delete $dirname/$cmd
create_db "$dirname/$cmd" "$app_info $dbout"
putquick "NOTICE $nick :fatto"
}
if {$start == "fe"} {
readdb $dirname/$cmd
file delete $dirname/$cmd
create_db "$dirname/$cmd" "$dbout $app_info"
putquick "NOTICE $nick :fatto"
}
} {
putquick "NOTICE $nick :'$cmd' non esiste"
}
} {
putquick "NOTICE $nick :scrivi: !app <fb|fe> <cmd_name> <info_aggiuntive> | fb - dall'inizio; fe - dalla fine;"
}
}
proc ren_fct { nick uhost hand chan arg } {
global dirname
if {![channel get $chan learn]} {
return
}
set txt [string tolower [split $arg]]
set old [lindex $txt 0]
set new [lindex $txt 1]
if {$new != ""} {
if {[file exists $dirname/$old] == 1} {
file rename $dirname/$old $dirname/$new
putquick "NOTICE $nick :'$old' é stato rinominato in '$new'"
} {
putquick "NOTICE $nick :'$cmd' non esiste"
}
} {
putquick "NOTICE $nick :scrivi: !ren <old_cmd_name> <new_cmd_name"
}
}
proc stored_cmds { nick uhost hand chan arg } {
global dirname
if {![channel get $chan learn]} {
return
}
set files [glob -tails -directory $dirname -nocomplain -type f *]
if {$files != ""} {
set names [join $files ", "]
} {
set names "nessuno"
}
putquick "NOTICE $nick :elenco comandi: $names"
}
putlog "learn.tcl loaded"