· 5 years ago · Aug 21, 2020, 04:56 PM
1load /usr/lib64/tcl8.5/sqlite3/libtclsqlite3.so Sqlite3
2
3namespace eval shelladmin {
4 variable database "./shelladmin.db"
5
6 variable dbpeak "./peak.db"
7
8 variable channel "#shells"
9
10 variable url "http://www.uniredlatina.com"
11
12 variable hours_use 336
13
14 bind pub - "!activar" shelladmin::aprobar
15 bind pub - "!renovar" shelladmin:keep
16 bind pub - "!info" shelladmin::info
17
18 bind pub m "!reg" shelladmin::reg
19 bind pub m "!ban" shelladmin::banacc
20
21 bind pub - "!help" shelladmin::help
22 bind pub - "!peak" shelladmin::peak
23
24 bind pub m "!uptime" shelladmin:uptime
25
26 bind join - * shelladmin::join
27
28 set randomanswers {
29 {Procesando...}
30 {Espera un momento...}
31 {Notificando a el_loco_01}
32 }
33
34 setudef flag shelladmin
35}
36
37proc shelladmin::aprobar { nick uhost hand chan text } {
38
39 if {![channel get $chan shelladmin]} { return 0 }
40
41 set accountid [lindex $text 0]
42
43 if {$accountid == ""} {
44 puthelp "PRIVMSG $chan :$nick, escribe: $::lastbind \002cuenta\002"
45 return 0
46 }
47
48 if {![shelladmin::findaccount $accountid]} {
49 puthelp "PRIVMSG $chan :$nick, necesitas registrar una cuenta en la web."
50 } elseif {[shelladmin::statusaccount $accountid] == 1} {
51 puthelp "PRIVMSG $chan :$nick, tu cuenta ya se encuentra activada."
52 } elseif {[shelladmin::statusaccount $accountid] == 2} {
53 puthelp "PRIVMSG $chan :$nick, espera! parece que \002$accountid\002 hizo algunas cosas malas, como actividades ilegales (AutoBan)"
54 } else {
55 puthelp "PRIVMSG $chan :[lindex $shelladmin::randomanswers [rand [llength $shelladmin::randomanswers]]]"
56 puthelp "PRIVMSG $chan :Configurando cuenta..."
57 puthelp "PRIVMSG $chan :$nick, tu cuenta ha sido aprobada y activada , visita $shelladmin::url para"
58 puthelp "PRIVMSG $chan :mas informacion acerca de tu cuenta y de como acceder a ella."
59 puthelp "PRIVMSG $chan :Tu cuenta expirara en $shelladmin::hours_use horas a menos que regreses a este canal"
60 puthelp "PRIVMSG $chan :y escribas el comando: \002!renovar $accountid\002, antes del tiempo de expiracion."
61 shelladmin::activate $accountid
62 putlog "Creando nueva cuenta... ($accountid)"
63 }
64}
65
66proc shelladmin::shelp {nick uhost hand chan text} {
67 global botnick
68
69 if {![channel get $chan shelladmin]} { return 0 }
70
71 puthelp "PRIVMSG $chan :$nick, Hola! soy \002$botnick\002!. Registrate en $shelladmin::url y sigue las instrucciones."
72 puthelp "PRIVMSG $chan :Mis comandos son: !activar !renovar !info"
73}
74
75proc shelladmin::keep {nick uhost hand chan text} {
76}
77
78proc shelladmin::calcexpiration {time} {
79 set diff [expr {$time - [clock seconds]}]
80 set horas [expr $diff / 3600]
81 if {$horas < 0 } {
82 return "Menos de 1 hora."
83 } else {
84 return "$horas horas."
85 }
86}
87
88proc shelladmin::info {nick uhost hand chan text} {
89 set accountid [lindex $text 0]
90
91 if {$accountid == ""} {
92 puthelp "PRIVMSG $chan :$nick, escribe: $::lastbind \002cuenta\002"
93 return 0
94 }
95
96 if {![shelladmin::findaccount $accountid]} {
97 puthelp "PRIVMSG $chan :$nick, Ese usuario no existe."
98 return 0
99 }
100
101 set timereg [shelladmin::getregtime $accountid]
102 set lastupdate [shelladmin::getlastupdate $accountid]
103 set duration [shelladmin::getduration $accountid]
104 set timeexpiration [shelladmin::calcexpiration $duration]
105
106 puthelp "PRIVMSG $chan :$nick, Tu shell ha sido activada desde [clock format $timereg -format "%B %d, %Y, %l:%M %p"]. y la ultima renovacion fue en [clock format $lastupdate -format "%B %d, %Y, %l:%M %p"] tu shell tiene $timeexpiration antes de expirar. Necesitaras escribir el comando: \002!renovar $nick\002 para renovar tu cuenta por $shelladmin::hours_use horas."
107}
108
109proc shelladmin::peak {nick uhost hand chan text} {
110
111 if {![channel get $chan shelladmin]} { return 0 }
112
113 set fd [open $shelladmin::dbpeak "r"]
114 set peak [gets $fd]
115 close $fd
116 puthelp "PRIVMSG $chan :$nick, he visto un pico de $peak de personas en $chan"
117}
118
119proc shelladmin:uptime {nick uhost hand chan text} {
120 putserv "PRIVMSG $chan :[shelladmin::genuptime]"
121}
122
123proc shelladmin::join {nick uhost hand chan} {
124
125 if {![channel get $chan shelladmin]} { return 0 }
126
127 shelladmin::updatepeak
128}
129
130proc shelladmin::activate {accountid} {
131
132 sqlite3 sdb $shelladmin::database
133 sdb eval {UPDATE shelladmin SET status=1 WHERE accountid=$accountid}
134 sdb close
135}
136
137proc shelladmin::banacc {nick uhost hand chan text} {
138 set accountid [lindex $text 0]
139
140 if {$accountid == ""} {
141 puthelp "NOTICE $nick :\002Sintaxis:\002 $::lastbind \002cuenta\002"
142 return 0
143 }
144
145 sqlite3 sdb $shelladmin::database
146 sdb eval {UPDATE shelladmin SET status=2 WHERE accountid=$accountid}
147 sdb close
148
149 puthelp "PRIVMSG $shelladmin::channel :Administracion de cuentas: Abuso detectado desde: $accountid"
150 puthelp "PRIVMSG $shelladmin::channel :Administracion de cuentas: Suspendiendo cuenta..."
151 puthelp "PRIVMSG $shelladmin::channel :Administracion de cuentas: $accountid ha sido rechazado."
152 puthelp "PRIVMSG $shelladmin::channel :Administracion de cuentas: Procesando..."
153 puthelp "PRIVMSG $shelladmin::channel :Administracion de cuentas: El usuario esta baneado porque hizo cosas malas, como actividades ilegales (autoban)"
154
155 puthelp "NOTICE $nick :La cuenta \002$accountid\002 ha sido baneada."
156}
157
158proc shelladmin::updatepeak {} {
159 set fp [open $shelladmin::dbpeak "r"]
160 set peak [read $fp]
161 close $fp
162
163 set fp [open $shelladmin::dbpeak "w"]
164 puts $fp [expr $peak + 1]
165 close $fp
166}
167
168proc shelladmin::reg {nick uhost hand chan text} {
169 set accountid [lindex $text 0]
170
171 if {$accountid == ""} {
172 puthelp "NOTICE $nick :\002Sintaxis:\002 $::lastbind \002cuenta\002"
173 return 0
174 }
175
176 if {![shelladmin::findaccount $accountid]} {
177 shelladmin::adduser $accountid
178 puthelp "NOTICE $chan :La cuenta \002$accountid\002 ha sido creada (falta de activacion)"
179 }
180}
181
182proc shelladmin::adduser {accountid} {
183 sqlite3 sdb $shelladmin::database
184 set now [clock seconds]
185 set bonus [clock add $now $shelladmin::hours_use hours]
186 sdb eval {INSERT INTO shelladmin (accountid,regtime,duration,lastupdatetime,status) VALUES ($accountid,$now,$bonus,$now,0)}
187 sdb close
188}
189
190proc shelladmin::statusaccount {accountid} {
191 sqlite3 sdb $shelladmin::database
192
193 set status [sdb eval {SELECT status FROM shelladmin WHERE accountid=$accountid}]
194 sdb close
195
196 return $status
197}
198
199proc shelladmin::findaccount {accountid} {
200 sqlite3 sdb $shelladmin::database
201
202 if {[llength [sdb eval {SELECT accountid FROM shelladmin WHERE accountid=$accountid}]] == 0} {
203 sdb close
204 return 0
205 }
206 sdb close
207
208 return 1
209}
210
211proc shelladmin::getregtime {accountid} {
212 sqlite3 sdb $shelladmin::database
213
214 set regtime [sdb eval {SELECT regtime FROM shelladmin WHERE accountid=$accountid}]
215 sdb close
216
217 return $regtime
218}
219
220proc shelladmin::getduration {accountid} {
221 sqlite3 sdb $shelladmin::database
222
223 set duration [sdb eval {SELECT duration FROM shelladmin WHERE accountid=$accountid}]
224 sdb close
225
226 return $duration
227}
228
229proc shelladmin::getlastupdate {accountid} {
230 sqlite3 sdb $shelladmin::database
231
232 set lastupdate [sdb eval {SELECT lastupdatetime FROM shelladmin WHERE accountid=$accountid}]
233 sdb close
234
235 return $lastupdate
236}
237
238proc shelladmin::genuptime { } {
239 if {[catch {exec uptime} uptime]} { set uptime "Uptime no disponible." }
240 if {[catch {exec uname -o} machine]} { set machine [unames] }
241 if {[catch {exec hostname} hostname]} { set hostname [info hostname] }
242 return "Uptime para $hostname ($machine): es $uptime"
243}
244
245if {![file exists $shelladmin::database]} {
246 sqlite3 sdb $shelladmin::database
247
248 sdb eval {CREATE TABLE shelladmin (id INTEGER PRIMARY KEY AUTOINCREMENT, accountid TEXT NOT NULL COLLATE NOCASE, regtime INTEGER NOT NULL, duration INTEGER NOT NULL, lastupdatetime INTEGER NOT NULL, status INTEGER NOT NULL)}
249 sdb close
250}
251
252if {![file exists $shelladmin::dbpeak]} {
253 set fp [open $shelladmin::dbpeak "w"]
254 puts $fp "0"
255 close $fp
256}
257
258putlog "\002Shell Admin v1.0 - Loaded\002"