Advertisement
Guest User

Untitled

a guest
Oct 20th, 2011
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.43 KB | None | 0 0
  1. # +-------------------------------------------------------------------------------------+
  2. # | |
  3. # | a&a (light) script v0.04.00 Beta 1 |
  4. # | |
  5. # +-------------------------------------------------------------------------------------+
  6. # | |
  7. # | Creative Commons Copyright 2002-2009 by UniversaliA aka aqwzsx |
  8. # | http://ascript.name |
  9. # | |
  10. # +-------------------------------------------------------------------------------------+
  11. # | |
  12. # | Website @ http://ascript.name |
  13. # | Forum & support @ http://ascript.name/forum |
  14. # | Features & bugs @ http://ascript.name/bugs |
  15. # | |
  16. # +-------------------------------------------------------------------------------------+
  17. # | |
  18. # | #a&a & #botlending @ Undernet/Quakenet IRC |
  19. # | |
  20. # +-------------------------------------------------------------------------------------+
  21. ############ Parser ##################################
  22.  
  23. proc a:parser {nick uhost hand chan dir comm arg} {
  24.  
  25. if { [check:b:gl $hand]} {return}
  26.  
  27. set option [lindex $arg 0]
  28. set chan1st $chan
  29.  
  30. global settings
  31.  
  32. if { [string match "#*" $option]} {set args [lrange $arg 1 end]; set chan $option} { set args $arg}
  33.  
  34. set comm [a:com:alias -check $comm $chan]
  35.  
  36. if {![a:command -exists $comm] || [a:com:status -inactive $comm $chan] || \
  37. ($settings(flood) && [a:flood -commands $chan $hand $uhost $nick $dir])} {return}
  38.  
  39. set x "[split $nick] [split $hand] [split $chan1st] $dir"
  40.  
  41. if { [validchan $chan] } {
  42. if {![botonchan $chan] && ![string match {|[suU]} [a:command -level $comm]] && ![regexp -nocase -- {^(purge|comeback|templeave|xremuser|xban|xkick|stats|chaninfo|chanset|suspend|admins|list|enable|disable)$} $comm]} {
  43. if { [check:v:ch $hand $chan]} {a:tell $x 21 "$chan"; putcmdlog "<<$hand>> $nick!$uhost $chan INACTIVE CHAN ($chan)"}
  44. return
  45. }
  46. } elseif {![string equal $comm join] && ![string equal $comm stats]} {
  47. if { [check:v:gl $hand]} {a:tell $x 20 "$chan"}
  48. return
  49. }
  50.  
  51. if { [check:S:ch $hand $chan] && ![check:N:gl $hand]} { a:tell $x 149; return}
  52.  
  53. set mix "[split $uhost]"
  54.  
  55.  
  56. switch -glob -- [a:command -level $comm] {
  57. {|[us]} {set report [catch {[a:command -proc $comm] $hand $chan $args $x $mix} execute]}
  58. |* {if { [check:[string index [a:command -level $comm] 1]:ch $hand $chan] && [a:authorised $nick $uhost $hand]} { set report [catch {[a:command -proc $comm] $hand $chan $args $x $mix} execute]} {return}}
  59. default {if { [check:[a:command -level $comm]:gl $hand] && [a:authorised $nick $uhost $hand]} { set report [catch {[a:command -proc $comm] $hand $chan $args $x $mix} execute]} {return}}
  60. }
  61.  
  62. putcmdlog "<<$hand>> $nick!$uhost $chan [string toupper $comm] $execute"
  63.  
  64. if {$report && $settings(tcl_error_warn)} {a:announce -permowner ERROR "<<$hand>> $nick!$uhost $chan $dir >>> [a:command -proc $comm] >>> $comm $args >>> $::errorInfo"}
  65. }
  66.  
  67. proc a:parse:anti {nick uhost hand chan text args} {
  68.  
  69. if {![validchan $chan] || ![botisop $chan] || [check:fo:ch $hand $chan $nick]} {return}
  70.  
  71. if { [channel get $chan antipub] && [string match "*#*" $text]} {set why "antipub" } elseif {
  72. [channel get $chan anticolour] && [string match *\003* $text]} {set why "anticolour" } elseif {
  73. [channel get $chan antirepeat] && [a:flood -repeat $chan $hand $uhost $text]} {set why "antirepeat" } elseif {
  74. [channel get $chan antinotice] && [string equal [lindex $args 0] notice]} {set why "antinotice" } elseif {
  75. [channel get $chan antiunderline] && [string match *\037* $text]} {set why "antiunderline"} elseif {
  76. [channel get $chan antibold] && [string match *\002* $text]} {set why "antibold" } elseif {
  77. [channel get $chan antireverse] && [string match *\026* $text]} {set why "antireverse" } elseif {
  78. [channel get $chan antiurl] && ([string match *www.*.* $text] || [string match *http://*.* $text])} {set why "antiurl" } else {return}
  79.  
  80. global username
  81.  
  82. newchanban $chan [a:maskhost -host $uhost] $username "channel $why protection enabled" [channel get $chan ban-time] sticky
  83. putcmdlog "<<${username}>> $why protection -- $chan ${nick}!${uhost}"
  84. }
  85.  
  86. proc a:flood {cmd chan {hand ""} {uhost ""} {nick ""} {arg ""}} {
  87. global flood username
  88.  
  89. switch -- $cmd {
  90. -commands {
  91. if {![isdynamic $chan] && [string equal $arg pub]} {return 0} elseif {
  92. ![info exists flood(10s,chan,${chan})]} {set flood(10s,chan,${chan}) 1} {incr flood(10s,chan,${chan})}
  93.  
  94. if {![info exists flood(30s,uhost,${uhost})]} {set flood(30s,uhost,${uhost}) 1} {incr flood(30s,uhost,${uhost})}
  95.  
  96. if { $flood(30s,uhost,${uhost}) <= $flood(user) || ([check:v:ch $hand $chan] && \
  97. ($flood(30s,uhost,${uhost}) <= $flood(user,local) || [check:v:gl $hand]) && \
  98. $flood(30s,uhost,${uhost}) <= $flood(user,global)) } {
  99. if { $flood(10s,chan,${chan}) > $flood(channel)} {return 1} {return 0}
  100. }
  101.  
  102. a:log actions "BOT - antiflood protection -- ignoring ${nick}!${uhost}"
  103.  
  104. set host "*!*@[lindex [split $uhost @] 1]"
  105.  
  106. if {![info exists flood(24h,host,$host)]} {set flood(24h,host,$host) 1} {incr flood(24h,host,$host)}
  107. if { $flood(24h,host,$host) > 3} {newignore $host $username "commands flood from this host" 1440} elseif {
  108. ![check:v:ch $hand $chan]} {newignore $uhost $username "commands flood from this host" 360 } elseif {
  109. ![check:v:gl $hand]} {newignore $uhost $username "commands flood from this host" 60 } else {
  110. newignore $uhost $username "commands flood from this host" 15
  111. }
  112. return 1
  113. }
  114. -topic { if {![info exists flood(1m,topic,$chan,$uhost)]} {set flood(1m,topic,$chan,$uhost) 1; return 0}; incr flood(1m,topic,$chan,$uhost)
  115. if { $flood(1m,topic,$chan,$uhost) > $flood(topic)} {
  116. if { [matchattr $hand f|f $chan]} {chattr $hand -f|-f $chan; setuser $hand XTRA _FLAG "[unixtime] -f $chan $username"}
  117. newchanban $chan *!${uhost} ${username} "channel topic protection enabled" [channel get $chan ban-time] sticky
  118. return 1} {return 0}
  119. }
  120. -need { global need
  121. if {![info exists need(1h,need,$chan)]} {set need(1h,need,$chan) 0; return 0}; incr need(1h,need,$chan)
  122. if { $need(1h,need,$chan) > 6} {array unset need 1h,need,$chan; return 1} {return 0}
  123. }
  124. -modes { if { [check:m:ch $hand $chan] || [isbotnick $nick] || !$flood(modes)} {return 0}
  125. if {![info exists flood(1m,modes,$chan,$uhost)]} {set flood(1m,modes,$chan,$uhost) 1; return 0} ; incr flood(1m,modes,$chan,$uhost)
  126. if { $flood(1m,modes,$chan,$uhost) > $flood(modes)} {
  127. if { [matchattr $hand |f $chan]} {chattr $hand |-f $chan}
  128. newchanban $chan *!${uhost} ${username} "channel modes protection enabled" [channel get $chan ban-time] sticky
  129. return 1} {return 0}
  130. }
  131. -repeat { if {![info exists flood(1m,repeat,$chan,$uhost,$nick)]} {set flood(1m,repeat,$chan,$uhost,$nick) 1; return 0} ; incr flood(1m,repeat,$chan,$uhost,$nick)
  132. if {$flood(1m,repeat,$chan,$uhost,$nick) > 2} {return 1} {return 0}
  133. }
  134. default {return 0}
  135. }
  136. }
  137.  
  138. proc a:level {x c g h l {talk 1}} {
  139.  
  140. set f [lindex $x 1]
  141. set h [lindex $h 0]
  142.  
  143. if {![validuser $f] || [string equal -nocase $f $h] || ![check:v:ch $h $c]} {return 1}
  144.  
  145. global settings
  146.  
  147. if { [check:x:xx $h] && ![check:x:xx $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) FOUNDER"}; return 0 } elseif {
  148. [check:N:gl $h] && ![check:N:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) MANAGER"}; return 0 } elseif {
  149. [check:L:gl $h] && ![check:N:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h GLOBALY LOCKED"} ; return 0 } elseif {
  150. [check:B:gl $h] && ![check:N:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) BOT"} ; return 0 } elseif {
  151. [check:n:gl $h] && ![check:N:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) OWNER"} ; return 0 } elseif {
  152. [check:m:gl $h] && ![check:n:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) MASTER"} ; return 0 } elseif {
  153. [check:o:gl $h] && ![check:m:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) OP"} ; return 0 } elseif {
  154. [check:l:gl $h] && ![check:o:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) HALFOP"} ; return 0 } elseif {
  155. [check:v:gl $h] && ![check:l:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h $settings(suppchan) HELPER"} ; return 0 } elseif {
  156. [check:P:gl $h] && ![check:v:gl $f]} {if {$talk} { a:tell $x 164 "�$l� $g $h GLOBALY PROTECTED"} ; return 0 } elseif {
  157. [check:N:ch $h $c] && ![check:m:gl $f] } {if {$talk} { a:tell $x 164 "�$l� $g $h $c MANAGER"} ; return 0 } elseif {
  158. [check:L:ch $h $c] && ![matchattr $f mN|N $c] } {if {$talk} { a:tell $x 164 "�$l� $g $h LOCALY LOCKED"} ; return 0 } elseif {
  159. [check:n:ch $h $c] && ![matchattr $f mN|N $c] } {if {$talk} { a:tell $x 164 "�$l� $g $h $c OWNER"} ; return 0 } elseif {
  160. [check:m:ch $h $c] && ![matchattr $f mN|nN $c] } {if {$talk} { a:tell $x 164 "�$l� $g $h $c MASTER"} ; return 0 } elseif {
  161. [check:o:ch $h $c] && ![matchattr $f oN|mN $c] } {if {$talk} { a:tell $x 164 "�$l� $g $h $c OP"} ; return 0 } elseif {
  162. [check:l:ch $h $c] && ![matchattr $f lN|oN $c] } {if {$talk} { a:tell $x 164 "�$l� $g $h $c OP"} ; return 0 } elseif {
  163. [check:v:ch $h $c] && ![matchattr $f lN|lN $c] } {if {$talk} { a:tell $x 164 "�$l� $g $h $c VOICE"} ; return 0 } else {return 1}
  164. }
  165.  
  166. ############ Command proc ############################
  167.  
  168. proc a:command {cmd {com ""} {proc ""} {help ""} {usage ""} {level ""}} {
  169. global comm
  170.  
  171. set com [string tolower $com]
  172. set proc [string tolower $proc]
  173.  
  174. switch -exact -- $cmd {
  175. -level { return $comm($com,level)}
  176. -exists { return [info exists comm($com,commands)]}
  177. -proc { return $comm($com,proc)}
  178. -help { return $comm($com,help)}
  179. -usage { return $comm($com,usage)}
  180. -all { set temp ""; foreach w [array names comm *,commands] {lappend temp $comm($w)}; return $temp}
  181. -unload { if {[info exists comm]} {unset comm}}
  182. -add { set comm($com,commands) "$com"
  183. set comm($com,level) "$level"
  184. set comm($com,help) "$help"
  185. set comm($com,usage) "$usage"
  186. set comm($com,proc) "$proc"
  187. }
  188. default { return 0}
  189. }
  190. }
  191.  
  192. proc a:com:status {cmd {com ""} {chan ""} {mix ""}} {
  193. global status
  194.  
  195. set com [string tolower $com]
  196. set chan [string tolower $chan]
  197.  
  198. switch -exact -- $cmd {
  199. -disabled {if {([info exists status($chan,$com,disabled)] || [info exists status($chan,all,disabled)]) && ![string equal -nocase $com enable]} {return 1} {return 0}}
  200. -inactive {if {([info exists status($chan,$com,disabled)] || [info exists status($chan,all,disabled)] || [info exists status(global,$com,disabled)] || [info exists status(global,all,disabled)]) && ![string equal $com enable]} {return 1} {return 0}}
  201. -disable {if { [string equal $com -all]} {catch {array unset status *,$chan,disabled }; set status($chan,all,disabled) 1} {set status($chan,$com,disabled) 1}}
  202. -enable {if { [string equal $com -all]} {catch {array unset status *,$chan,disabled }} {catch {unset status($chan,$com,disabled)}}}
  203. -clean {catch {array unset status $com,*}}
  204. -autoclean {set list ""; foreach chan [channels] {if { [llength [set a [array get status $chan,*]]]} {lappend list $a}}; catch {array unset status}; array set status [join $list]; return 1}
  205. -array {set status(version) $::settings(numversion); return [list array set status [array get status]]}
  206. default {return 0}
  207. }
  208. }
  209.  
  210. proc a:com:alias {cmd {com ""} {chan ""} {mix ""}} {
  211. global alias
  212.  
  213. set com [string tolower $com]
  214. set chan [string tolower $chan]
  215.  
  216. switch -exact -- $cmd {
  217. -check {if {[info exists alias($chan,$com)]} {return $alias($chan,$com)} {return $com}}
  218. -exists {return [info exists alias($chan,$com)]}
  219. -add {set alias($chan,$com) $mix}
  220. -remove {if {[string equal -nocase $com -all]} {catch {array unset alias $chan,*}} {catch {array unset alias $chan,$com}}}
  221. -list {set list ""; foreach x [array names alias $com,*] {lappend list "$alias($x) [lindex [split $x ,] 1]," }; return [string trimright [join [lsort $list]] ,]}
  222. -count {return [llength [array names alias $com,*]]}
  223. -clean {catch {array unset alias $com,*}}
  224. -autoclean {set list ""; foreach chan [channels] {if { [llength [set a [array get alias ${chan},*]]]} {lappend list $a}}; catch {array unset alias}; array set alias [join $list]; return 1}
  225. -array {set alias(version) $::settings(numversion); return [list array set alias [array get alias]]}
  226. default {return 0}
  227. }
  228. }
  229.  
  230. ############ Output procs ############################
  231.  
  232. proc a:announce {com a {b ""} {c ""} {d ""}} {
  233. global owner settings
  234.  
  235. switch -exact -- [string tolower $com] {
  236.  
  237. -home { if {$settings(report)} { a:tell "{} * [split $settings(homechan)] pub" $a $b }}
  238. -chan { a:tell "{} * [split $b] pub" $a $c}
  239. -owner { foreach manager [userlist R&N $b] {sendnote $a $manager "[a:translate $manager $b $c $d]"}}
  240. -user { if { [check:R:gl $b]} {sendnote $a $b "[a:translate $b $settings(homechan) $c $d]"}}
  241. -permowner {foreach manager [split $owner ", "] {if {[check:R:gl $manager]} {sendnote $a $manager $b}}}
  242. }
  243. }
  244.  
  245. #a part of code (c) hex@forestnet.org
  246. proc a:tell {x id {arg ""}} {
  247. global say botnick
  248.  
  249. set nick [lindex $x 0]
  250. set hand [lindex $x 1]
  251. set chan [lindex $x 2]
  252. set dir [lindex $x 3]
  253. set q [getuser $hand XTRA _LANG_OUT]
  254.  
  255. if {$q == ""} {set z $say(lang.1.${id})} else { set z $say(lang.${q}.${id})}
  256.  
  257. set txt [a:lang $z $arg]
  258.  
  259. switch -exact -- [getuser $hand XTRA _COL_OUT] {
  260. none {set txt [string map {%B {} %b {} %r {} %u {} %% {}} $txt]}
  261. bold {set txt [string map {%B \002 %b \002 %r \002 %u \002 %% \002} $txt]}
  262. 1 {set txt [string map {%B \002 %b \00302\002 %r \00304\002 %u \037 %% \002\003} $txt]}
  263. 2 {set txt [string map {%B \002 %b \00306 %r \00315 %u \037 %% \003} $txt]}
  264. default {set txt [string map {%B \002 %b \00302 %r \00304 %u \037 %% \003} $txt]}
  265. }
  266.  
  267. set msgmax [expr 495 - [string length "$botnick![getchanhost $botnick] $chan $nick"]]
  268.  
  269. while {$txt != ""} {
  270.  
  271. if { [string length $txt] > $msgmax} {
  272. set msg [string range $txt 0 [string last \x20 [string range $txt 0 $msgmax]]]
  273. set txt [string trim [string range $txt [string length $msg] end]]} {
  274. set msg "$txt"
  275. set txt ""
  276. }
  277.  
  278. switch -exact -- $dir {
  279.  
  280. pub {
  281. switch -exact -- [getuser $hand XTRA _PUB_OUT] {
  282.  
  283. msg {puthelp "PRIVMSG $nick :$msg"}
  284. note {puthelp "NOTICE $nick :$msg"}
  285. default {puthelp "PRIVMSG $chan :$nick $msg"}
  286. }
  287. }
  288.  
  289. msg {
  290. switch -exact -- [getuser $hand XTRA _MSG_OUT] {
  291.  
  292. chan {puthelp "PRIVMSG $chan :$nick $msg"}
  293. note {puthelp "NOTICE $nick :$msg"}
  294. default {puthelp "PRIVMSG $nick :$msg"}
  295. }
  296. }
  297. }
  298. }
  299. }
  300.  
  301. proc a:translate {hand chan id {arg ""}} {
  302. global say
  303.  
  304. set lang [getuser $hand XTRA _LANG_OUT]
  305.  
  306. if {$lang == ""} {set talk $say(lang.1.${id})} else {
  307. set talk $say(lang.${lang}.${id})}
  308. return [a:lang $talk $arg]
  309. }
  310.  
  311. proc a:lang {x y} {
  312.  
  313. set c [string last � $x]
  314. if {![string length $y] || !$c=="-1"} {return $x}
  315. set a -1
  316. set b -1
  317. set y [string map {� \{ � \} } [split $y]]
  318. set z ""
  319.  
  320. for {set i 0} { $i < [string length $x] } { incr i } {
  321. if {[string index $x $i] == "�" } { incr b
  322. if {$i!=$c} {
  323. append z "[lindex $y $b]" } {
  324. append z "[join [lrange $y $b end]]" }} {
  325. append z "[string index $x $i]" }}
  326.  
  327. return "$z"
  328. }
  329.  
  330. ############ Check access level ######################
  331.  
  332. proc check:x:xx {hand} { global owner ; if { [matchattr $hand N ] && ([lsearch -exact [split [string tolower $owner] ", "] [string tolower $hand]] != -1)} {return 1} else {return 0}}
  333.  
  334. proc check:Q:gl {hand} {return [matchattr $hand Q ]}
  335. proc check:A:gl {hand} {return [matchattr $hand A ]}
  336. proc check:R:gl {hand} {return [matchattr $hand R ]}
  337. proc check:I:gl {hand} {return [matchattr $hand I ]}
  338. proc check:W:gl {hand} {return [matchattr $hand W ]}
  339. proc check:L:gl {hand} {return [matchattr $hand L ]}
  340. proc check:S:gl {hand} {return [matchattr $hand S ]}
  341. proc check:X:gl {hand} {return [matchattr $hand XN]}
  342. proc check:P:gl {hand} {return [matchattr $hand P ]}
  343. proc check:H:gl {hand} {return [matchattr $hand H ]}
  344. proc check:N:gl {hand} {return [matchattr $hand N ]}
  345. proc check:n:gl {hand} {return [matchattr $hand nN]}
  346. proc check:m:gl {hand} {return [matchattr $hand m ]}
  347. proc check:o:gl {hand} {return [matchattr $hand o ]}
  348. proc check:l:gl {hand} {return [matchattr $hand l ]}
  349. proc check:B:gl {hand} {return [matchattr $hand B ]}
  350. proc check:b:gl {hand} {return [matchattr $hand b ]}
  351. proc check:v:gl {hand} {return [matchattr $hand vl]}
  352. proc check:s:gl {hand} {return [matchattr $hand vl]}
  353. proc check:d:gl {hand} {return [matchattr $hand d ]}
  354. proc check:k:gl {hand} {return [matchattr $hand k ]}
  355.  
  356. proc check:U:ch {hand chan} {return [validuser $hand]}
  357. proc check:S:ch {hand chan} {return [matchattr $hand S|S $chan] }
  358. proc check:L:ch {hand chan} {return [matchattr $hand L|L $chan] }
  359. proc check:P:ch {hand chan} {return [matchattr $hand P|P $chan] }
  360. proc check:H:ch {hand chan} {return [matchattr $hand H|H $chan] }
  361. proc check:X:ch {hand chan} {return [matchattr $hand XN|XN $chan] }
  362. proc check:N:ch {hand chan} {return [matchattr $hand m|N $chan] }
  363. proc check:n:ch {hand chan} {return [matchattr $hand m|nN $chan] }
  364. proc check:m:ch {hand chan} {return [matchattr $hand o|m $chan] }
  365. proc check:o:ch {hand chan} {return [matchattr $hand o|o $chan] }
  366. proc check:l:ch {hand chan} {return [matchattr $hand l|l $chan] }
  367. proc check:v:ch {hand chan} {return [matchattr $hand vl|vl $chan] }
  368. proc check:p:ch {hand chan} {return [matchattr $hand p|p $chan] }
  369.  
  370. proc check:f:ch {hand chan nick} { if { [matchattr $hand fvloPHBNW|fnPHN $chan] || [isbotnick $nick] || $nick == ""} {return 1} else {return 0}}
  371. proc check:fo:ch {hand chan nick} { if { [matchattr $hand fvloPHBNW|floPHN $chan] || [isbotnick $nick] || $nick == "" || [isop $nick $chan]} {return 1} else {return 0}}
  372.  
  373. ############ Procs ###################################
  374.  
  375. proc a:check {cmd {a ""} {b ""} {c ""}} {
  376.  
  377. switch -exact -- $cmd {
  378. -now { if { [string equal -nocase $a !] || [string equal -nocase $a -now]} {return 1} {return 0}}
  379. -info { if { [string equal -nocase $a ?] || [string equal -nocase $a info]} {return 1} {return 0}}
  380. -host { return [regexp -- {.+!+[^@]+@[^@][[:alnum:]*-\.\?]+[[:alnum:]*]$} $a]}
  381. -ip { return [regexp -- {^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$} $a]}
  382. -regx { set c ""; foreach x [chanlist $b] {if {[string match -nocase $a $x]} {lappend c $x}}; return $c}
  383. -digit { if { [scan $a "%f%s" f g] == 1} {return 1} {return 0}}
  384. -mail { return [string match -nocase *?@?*.??* $a]}
  385. -url { return [string match -nocase http://?*.??* $a]}
  386. -reason { return [regexp -- {^(flood-(deop|kick|ban|chan|bot)|no-(op|access|ppl|need)|take|invite|key|limit|abuse|banned|opless|blacklist|other)$} $a]}
  387. default { return 0}
  388. }
  389. }
  390.  
  391. proc a:validate {cmd a {b ""}} {
  392.  
  393. switch -exact -- $cmd {
  394. -hand {if { [validuser $a]} {return $a} {return *}}
  395. -digit {if { [scan $a "%f%s" f g] == 1} {return $a} {return 0}}
  396. -secret { if {![channel get $a secret] || ![isdynamic $b] || [string equal -nocase $a $b]} {return $a} {return +secret}}
  397. default {return 0}
  398. }
  399. }
  400.  
  401. proc a:modify {cmd x a {b ""}} {
  402.  
  403. switch -exact -- $cmd {
  404. -nick {return "[split $a] [split [lindex $x 1]] [split [lindex $x 2]] [split [lindex $x 3]]"}
  405. -hand {return "[split [lindex $x 0]] [split $a] [split [lindex $x 2]] [split [lindex $x 3]]"}
  406. -nickhand {return "[split $a] [split $b] [split [lindex $x 2]] [split [lindex $x 3]]"}
  407. default {return 0}
  408. }
  409. }
  410.  
  411. proc a:replace {cmd a b {c ""} {d ""}} {
  412.  
  413. switch -exact -- $cmd {
  414. -nick {regsub -all -nocase -- %nick% $a $b a; return "$a"}
  415. -chan {regsub -all -nocase -- %chan% $a $b a; return "$a"}
  416. -all {regsub -all -nocase -- %nick% $a $b a; regsub -all -nocase -- %from% $a $c a; return "$a"}
  417. }
  418. }
  419.  
  420. proc iif {a b {c ""}} {if {$a} {return $b} {return $c}}
  421. proc a:set {var value} {
  422.  
  423. if { [string match *(* $var]} {global [lindex [split $var (] 0]} {global $var}
  424.  
  425. if {![info exists $var]} {return nnnnnnnnnnn} {return yyyyyyyyyyyy}
  426. }
  427.  
  428. #copyright for -ip2short & -bytes2kb uknown (taken a lot of time ago from web)
  429.  
  430. proc a:fix {cmd {a ""}} {
  431.  
  432. switch -exact -- $cmd {
  433.  
  434. -ip2short {return "[expr ($a >> 24) & 255].[expr ($a >> 16) & 255].[expr ($a >> 8) & 255].[expr $a & 255]"}
  435. -bytes2kb {if {wide($a) < 1000} {return ${a}b}
  436. foreach unit {K M G T P E} {
  437. set a [expr {$a/1024.}]
  438. if {$a < 1000} {
  439. set a [string range $a 0 3]
  440. regexp {(.+)\.$} $a -> a
  441. return $a$unit
  442. }
  443. }
  444. return Inf
  445. }
  446. default {return 0}
  447. }
  448. }
  449.  
  450. proc a:maskhost {cmd {a ""} {b ""} {c ""}} {
  451.  
  452. switch -exact -- $cmd {
  453.  
  454. -host {if {[string match -nocase *@*.users.*.org $a]} { return "*!*[join [regexp -inline -- {@[^@].+} $a]]"} elseif {
  455. [regexp {^.+@\w.+\d[\.-]\d.+[[:alpha:]]$} $a]} { return "*![regexp -inline -- {^[^\@]+} $a]@*[regexp -inline -- {\.[^\.]+\.[^\.]+$} $a]"} else {
  456. return [maskhost $a]}}
  457. -uhost {if {[string match -nocase *@*.users.*.org $a]} { return "*!*[join [regexp -inline -- {@[^@].+} $a]]"} else {return *!$a}}
  458. default {return "*!*[join [regexp -inline -- {@[^@].+} $a]]"}
  459. }
  460. }
  461.  
  462. proc a:deluser {x f g} {
  463.  
  464. if {[onchan $f [lindex $x 2]]} {
  465. if { [nick2hand $f] != "*"} { return [nick2hand $f] } elseif {
  466. [validuser $f]} {
  467. if {[a:check -now $g]} { return $f } else {
  468. a:tell $x 22 $f ; return 0 }} else {
  469. a:tell $x 23 $f ; return 0 }} elseif {
  470. [validuser $f] } { return $f } else {
  471. a:tell $x 23 $f ; return 0
  472. }
  473. }
  474.  
  475. proc a:adduser {x f g h} {
  476. global one settings
  477.  
  478. if { [onchan $f $h]} {
  479. if { [validuser [nick2hand $f]]} { return [nick2hand $f]} elseif {
  480. [validuser $f]} {
  481. if { [a:check -now $g]} { return $f } else { a:tell $x 22 $f; return 0}
  482. } else {
  483. if { [string length $f] > $::handlen } {a:tell $x 46 $f; return 0}
  484. set host [a:maskhost -uhost [getchanhost $f]]
  485. adduser $f $host; chattr $f $settings(flags_default); set one 1
  486. a:tell $x 24 $f ; return $f
  487. }
  488. } elseif { [validuser $f]} { return $f
  489. } else { a:tell $x 25 $f ; return 0
  490. }
  491. }
  492.  
  493. proc a:log {cmd text} {
  494. global botnet log username
  495.  
  496. if {![info exists log($cmd)]} {set log($cmd) 1}
  497.  
  498. putloglev $log($cmd) * "\[$username\] [string toupper $cmd] $text"
  499. }
  500.  
  501. proc a:getxtra {cmd b {c ""}} {
  502.  
  503. switch -exact -- $cmd {
  504. -ctime {return [ctime [lindex [split [getuser $b XTRA $c]] 0]]}
  505. -uhost {return [lindex [split [getuser $b XTRA $c]] 1]}
  506. -hand {return [lindex [split [getuser $b XTRA $c]] 2]}
  507. default {return [split [getuser $cmd XTRA $b]]}
  508. }
  509. }
  510.  
  511. proc a:botnet:get {} {
  512. }
  513.  
  514. proc a:botnet:put {} {
  515. }
  516.  
  517. proc a:counterspy {chan} {
  518.  
  519. if { [channel get $chan inactive] && ![channel get $chan suspended] && ![string match -nocase *[list channel set $chan -inactive]* [utimers]]} {channel set $chan -inactive}
  520. }
  521.  
  522. proc a:opless {chan} {
  523.  
  524. if {![botisop $chan] && ![channel get $chan locked]} {foreach z [chanlist $chan] {if {[isop $z $chan] } {a:announce -chan $chan 125 "$chan [a:maskhost -uhost [lindex [split $::botname !] 1]]"; break}}}
  525. }
  526.  
  527. proc iif {a b {c ""}} {
  528.  
  529. if {$a} {return $b} {return $c}
  530. }
  531.  
  532. ############ Authorisation check #####################
  533.  
  534. proc a:authorised {nick uhost hand} {
  535. global botnick settings
  536.  
  537. if {![validuser $hand]} {return 0} elseif {
  538. [check:Q:gl $hand] && [string equal -nocase [a:getxtra -uhost $hand _AUTH] ${nick}!${uhost}]} {return 1} elseif {
  539. [string match -nocase [getuser $hand XTRA _PERMIDENT] $nick!$uhost]} {return 1} else {
  540. a:tell "[split $nick] [split $hand] [split $settings(homechan)] msg" 5 $botnick; return 0}
  541. }
  542.  
  543. ############ Help procs ##############################
  544.  
  545. proc a:help {x comm} {
  546. global botnick settings
  547.  
  548. if { $comm == ""} {a:tell $x 145 "$botnick ${settings(cmdpfix)} $botnick ${settings(cmdpfix)}"} elseif {
  549. [a:command -exists $comm]} {a:tell $x [a:command -help $comm] $settings(compage)${comm}
  550. } else {a:tell $x 18 $comm}
  551. }
  552.  
  553. proc a:usage {x comm} {
  554. global botnick settings
  555.  
  556. if { $comm == ""} {a:tell $x 146 "$botnick ${settings(cmdpfix)} $botnick ${settings(cmdpfix)}"} elseif {
  557. [a:command -exists $comm]} {a:tell $x [a:command -usage $comm] "${settings(cmdpfix)} $settings(compage)${comm}"
  558. } else {a:tell $x 18 $comm}
  559. }
  560.  
  561. ############ Bind procs ##############################
  562.  
  563. proc a:bind:msgm {nick uhost hand arg} {
  564. global settings
  565.  
  566. set dir msg
  567. set arg [split [string trim $arg]]
  568. set com [lindex $arg 0]
  569. set chan [lindex $arg 1]
  570.  
  571. if { [string match "#*" $chan]} { set chan $chan ; set args [lrange $arg 2 end]} else {set chan $settings(homechan) ; set args [lrange $arg 1 end]}
  572.  
  573. a:parser $nick $uhost $hand $chan $dir $com $args
  574. }
  575.  
  576. proc a:bind:msg:promote {nick uhost hand arg} {
  577. global owner
  578.  
  579. if { [llength [userlist N]] || ![validuser $hand] || ![matchattr $hand n]|| ![info exists owner]} {return}
  580.  
  581. if { [lsearch -exact [split [string tolower $owner] ", "] [string tolower $hand]] != -1} {
  582. chattr $hand +Nf
  583. puthelp "NOTICE $nick :YOU ARE THE MANAGER ON THIS BOT NOW"
  584. catch { unbind msg n|- promote a:bind:msg:promote }
  585. }
  586. }
  587.  
  588. proc a:bind:act {nick uhost hand chan keyword arg} {
  589.  
  590. if { [channel get $chan antiaction] && [botisop $chan] && ![check:fo:ch $hand $chan $nick]} {
  591. global username
  592. newchanban $chan [a:maskhost -host $uhost] $username "channel antiaction protection enabled" [channel get $chan ban-time] sticky
  593. return
  594. }
  595.  
  596. a:bind:pubm $nick $uhost $hand $chan $arg
  597.  
  598. global settings
  599. if { $settings(cmd_me)} {a:bind:botnick $nick $uhost $hand $chan $arg}
  600. }
  601.  
  602. proc a:bind:pubm {nick uhost hand chan arg} { a:parse:anti $nick $uhost $hand $chan $arg }
  603.  
  604. proc a:bind:cmdpfix {nick uhost hand chan arg} {
  605.  
  606. set arg [split [string trim $arg]]
  607.  
  608. a:parser $nick $uhost $hand $chan pub [string range [lindex $arg 0] 1 end] [lrange $arg 1 end]
  609. }
  610.  
  611. proc a:bind:botnick {nick uhost hand chan arg} {
  612.  
  613. set arg [split [string trim $arg]]
  614.  
  615. a:parser $nick $uhost $hand $chan pub [lindex $arg 0] [lrange $arg 1 end]
  616. }
  617.  
  618. proc a:bind:for {nick uhost hand chan arg} {
  619.  
  620. set who [expr [string first : $arg] -1]
  621. set go 0
  622.  
  623. global botnick
  624.  
  625. foreach x [string range $arg 4 $who] {
  626. if { [string match -nocase $x $botnick]} {
  627.  
  628. set cmd [expr $who + 2]
  629. set temp [string wordend $arg $cmd]
  630.  
  631. a:parser $nick $uhost $hand $chan pub [string trim [string range $arg $cmd $temp]] [split [string trim [string range $arg $temp end]]]
  632.  
  633. break
  634. }
  635. }
  636. }
  637.  
  638. proc a:bind:skip {nick uhost hand chan arg} {
  639.  
  640. set who [expr [string first : $arg] -1]
  641.  
  642. global botnick
  643.  
  644. foreach x [string range $arg 4 $who] {if { [string match -nocase $x $botnick]} {return}}
  645.  
  646. set cmd [expr $who + 2]
  647. set temp [string wordend $arg $cmd]
  648.  
  649. a:parser $nick $uhost $hand $chan pub [string trim [string range $arg $cmd $temp]] [split [string trim [string range $arg $temp end]]]
  650. }
  651.  
  652. proc a:bind:notice {nick uhost hand arg dest} {
  653.  
  654. if { [validchan $dest]} {a:parse:anti $nick $uhost $hand $dest $arg notice}
  655. }
  656.  
  657. ############ Connect IRC #############################
  658.  
  659. proc a:routine:preconnect {type} {
  660. global nick altnick settings
  661.  
  662. if {$settings(counterspy)} {
  663. set nick "[string range $settings(nick) 0 6][rand 99999]"
  664. set altnick "[string range $settings(nick) 0 6][rand 99999]"
  665. }
  666. }
  667.  
  668. proc a:routine:connect {type} {
  669. global botnick username settings
  670.  
  671. putquick "MODE $botnick $settings(server_modes)"
  672. if {$settings(counterspy)} {foreach z [channels] {channel set $z +inactive}; channel set $settings(homechan) -inactive}
  673. bind pub -|- $botnick a:bind:botnick; putcmdlog "<<${username}>> BIND ROUTINE -- $botnick"
  674. if { $settings(away) != ""} {puthelp "AWAY :${settings(away)}"}
  675. foreach w [userlist Q] {chattr $w -Q}
  676. }
  677.  
  678. proc a:routine:userfile {type} {
  679.  
  680. if { [userlist N] == ""} {
  681. bind msg n|- promote a:bind:msg:promote
  682. }
  683.  
  684. if { [userlist R] == "" && [llength [userlist -b]] > 0} {
  685. foreach user [userlist -b] {chattr $user +R}
  686. }
  687. }
  688.  
  689. proc a:routine:userfile:clean { } {
  690. global settings username
  691.  
  692. if {!$settings(auto_clean_users)} { return "FAILED: disabled in config"}
  693.  
  694. set e 0
  695.  
  696. foreach u [userlist -vlfLNB&-N&-ha] {
  697.  
  698. if {![handonchan $u] && [expr [unixtime] - [a:validate -digit [lindex [getuser $u LASTON] 0]]] > [expr $settings(auto_clean_users) * 86400] } {
  699. deluser $u; incr e
  700. }
  701. }
  702.  
  703. putcmdlog "<<${username}>> AUTO CLEANING USERLIST ROUTINE -- $e user(s) erased"
  704. }
  705.  
  706. ############ Timed routines ##########################
  707.  
  708. proc a:timed:10:seconds {} {
  709. global flood
  710.  
  711. if { [info exists flood] } { array unset flood chan,*; array unset flood 10s,*}
  712.  
  713. utimer 10 a:timed:10:seconds
  714. }
  715.  
  716. proc a:timed:30:seconds {} {
  717. global flood
  718.  
  719. if { [info exists flood]} { array unset flood 30s,*}
  720.  
  721. utimer 30 a:timed:30:seconds
  722. }
  723.  
  724. proc a:timed:01:minutes {min hour day month year} {
  725. global flood
  726.  
  727.  
  728. if {![string match *a:timed:30:seconds* [utimers]]} {a:timed:30:seconds}
  729. if {![string match *a:timed:10:seconds* [utimers]]} {a:timed:10:seconds}
  730. if { [info exists flood]} {array unset flood 1m,*}
  731.  
  732. foreach chan [channels] {
  733. if { [channel get $chan limit] && [botisop $chan]} {
  734.  
  735. if {![set floatmargin [channel get $chan floatmargin]]} {set floatmargin 3}
  736. if {![set floatgrace [channel get $chan floatgrace]] } {set floatgrace 1}
  737. set floatmax [channel get $chan floatmax]
  738. set onchan [llength [chanlist $chan]]
  739. set limit_to_set [expr $floatmargin + $onchan]
  740.  
  741. if { [string match *l* [lindex [getchanmode $chan] 0]]} {
  742. set setlimit [string range [getchanmode $chan] [expr [string last " " [getchanmode $chan]] + 1] end]
  743. } else {
  744. set setlimit 0
  745. }
  746.  
  747. if {!$floatmax || $limit_to_set <= $floatmax } {
  748. if { [expr {abs([expr $limit_to_set - $setlimit])}] > $floatgrace || [expr $setlimit - $onchan] < 1 } {pushmode $chan "+l" "$limit_to_set"}
  749. } elseif {!$setlimit || $setlimit > $floatmax || $limit_to_set > $floatmax} {pushmode $chan "+l" "$floatmax"}
  750. }
  751.  
  752. set idledeop [channel get $chan idle-deop]
  753. if { $idledeop && [botisop $chan]} {
  754. foreach nick [chanlist $chan] {
  755. if { [isop $nick $chan] && [getchanidle $nick $chan] >= $idledeop && ![isbotnick $nick] && ![matchattr [nick2hand $nick $chan] aB|a $chan]} {pushmode $chan -o $nick; pushmode $chan +v $nick}
  756.  
  757. }
  758. }
  759. }
  760. }
  761.  
  762. proc a:timed:10:minutes {min hour day month year} {
  763.  
  764. }
  765.  
  766. proc a:timed:01:hours {min hour day month year} {
  767. global username need
  768.  
  769. putcmdlog "<<${username}>> TIMED ROUTINE -- 1 HOUR"
  770.  
  771. if { [info exists need]} {array unset need 1h,*}
  772.  
  773. foreach chan [string tolower [channels]] {
  774.  
  775. if { [botonchan $chan]} {
  776. a:opless $chan
  777. if { [channel get $chan topic] && [channel get $chan enforcetopic]} {puthelp "TOPIC $chan :[stats:channel -get $chan topictext]"}
  778. } else {
  779. a:counterspy $chan}
  780. }
  781. }
  782.  
  783. proc a:timed:24:hours {min hour day month year} {
  784. global username flood
  785.  
  786. putcmdlog "<<${username}>> TIMED ROUTINE -- 24 HOURS"
  787.  
  788. if { [info exists flood]} {array unset flood 24h,* }
  789.  
  790. a:routine:userfile:clean
  791. pub:backup
  792. }
  793.  
  794. proc a:timed:10:days {min hour day month year} {
  795. global stack
  796.  
  797. a:log routines "TIMED - 10 DAYS"
  798. a:log routines "FILES - BACKING UP -- 10 DAYS"
  799.  
  800. foreach file $stack(files,back) {
  801. if { [file exists ${file}~bak]} {file copy -force -- ${file}~bak ${file}~~ak} elseif {
  802. [file exists ${file}] } {file copy -force -- ${file} ${file}~~ak}
  803. }
  804. }
  805.  
  806. proc a:timed:30:days {min hour day month year} {
  807. global stack
  808.  
  809. a:log routines "TIMED - 30 DAYS"
  810. a:log routines "FILES - BACKING UP -- 30 DAYS"
  811.  
  812. foreach file $stack(files,back) {
  813. if { [file exists ${file}~~ak]} {file copy -force -- ${file}~~ak ${file}~~~k} elseif {
  814. [file exists ${file}~bak]} {file copy -force -- ${file}~bak ${file}~~~k} elseif {
  815. [file exists ${file}] } {file copy -force -- ${file} ${file}~~~k}
  816. }
  817. }
  818.  
  819. ##### Stack routines ###################
  820. proc a:exe {type bind chan hand} {
  821. global stack
  822.  
  823. switch -exact -- $type {
  824. proc {
  825. if { [llength $stack($bind)] > 0} {
  826.  
  827. foreach exe $stack($bind) {
  828.  
  829. [lindex $exe 0] $bind $chan $hand
  830. }
  831. }
  832. }
  833. default {return 0}
  834. }
  835. }
  836.  
  837. proc a:bind {type bind process} {
  838. global stack
  839.  
  840. switch -exact -- $type {
  841. proc {lappend stack($bind) [split $process]}
  842. file {lappend stack(files,back) $process}
  843. default {return 0}
  844. }
  845. }
  846.  
  847. if { [info exists stack] } {unset stack}
  848.  
  849. a:bind file backup $userfile
  850. a:bind file backup $chanfile
  851. a:bind file backup $notefile
  852.  
  853. ##### Files routines ###################
  854.  
  855. proc a:files:restore {file} {
  856.  
  857. if { [file exists ${file}~bak]} {
  858. a:log routines "FILES - RESTORE from BACKUP -- $file"
  859. file copy ${file}~bak $file} elseif {
  860. [file exists ${file}~~ak]} {
  861. a:log routines "FILES - RESTORE from BACKUP -- $file"
  862. file copy ${file}~~ak $file} elseif {
  863. [file exists ${file}~~~k]} {
  864. a:log routines "FILES - RESTORE from BACKUP -- $file"
  865. file copy ${file}~~~k $file} else {
  866. a:log routines "FILES - CREATE NEW -- $file"
  867. }
  868. }
  869.  
  870. ############ Sign procs ##############################
  871.  
  872. proc a:bind:joins {nick uhost hand chan} {
  873. global settings username
  874.  
  875. if { $settings(lonely) && [check:B:gl $hand] && ![isbotnick $nick] && ![channel get $chan locked]} {
  876. putcmdlog "<<${username}>> AUTO purge CHAN ROUTINE -- $chan chan removed, joined $settings(suppchan) BOT ($hand)"
  877. stats:channel -set $chan purgetime [unixtime]
  878. stats:channel -set $chan purgewhom $username
  879. stats:channel -set $chan purgewhy "another $settings(suppchan) BOT joinned ($hand)"
  880. putquick "part $chan :automated chan part, reason: another $settings(suppchan) BOT joinned ($hand)\; for any help apply on $settings(suppchan) & $settings(homepage)"
  881. channel remove $chan} elseif {
  882. [channel get $chan op] && [botisop $chan] } {pushmode $chan +o $nick} elseif {
  883. [channel get $chan voice] && [botisop $chan] } {pushmode $chan +v $nick
  884. }
  885. }
  886.  
  887. proc a:bind:sign {nick uhost hand chan arg} {
  888.  
  889. if {![isbotnick $nick]} {
  890. a:parse:anti $nick $uhost $hand $chan $arg
  891. if { [check:Q:gl $hand] && [string equal -nocase [a:getxtra -uhost $hand _AUTH] ${nick}!${uhost}]} {
  892. chattr $hand -Q
  893. putcmdlog "<<$hand>> $nick!$uhost $chan SIGNED OFF"
  894. }
  895. }
  896. }
  897.  
  898. proc a:bind:parts {nick uhost hand chan arg} {
  899.  
  900. if {![isbotnick $nick]} {
  901. a:parse:anti $nick $uhost $hand $chan $arg
  902. if { [check:Q:gl $hand] && ![onchan $nick] && [string equal -nocase [a:getxtra -uhost $hand _AUTH] ${nick}!${uhost}]} {
  903. chattr $hand -Q
  904. putcmdlog "<<$hand>> $nick!$uhost $chan PART all channels"
  905. }
  906. }
  907. }
  908.  
  909. proc a:bind:nick {nick uhost hand chan newnick} {
  910. global username
  911.  
  912. if { [isbotnick $nick]} {
  913. catch { unbind pub -|- $nick a:bind:botnick }
  914. bind pub -|- $newnick a:bind:botnick
  915. putcmdlog "<<$username>> BIND ROUTINE -- $nick >> $newnick"
  916. } elseif {
  917. [check:Q:gl $hand] && [string equal -nocase [a:getxtra -uhost $hand _AUTH] ${nick}!${uhost}]} {
  918. putcmdlog "<<$hand>> $nick!$uhost $chan CHANGED NICK to $newnick"
  919. setuser $hand XTRA _AUTH "[lindex [getuser $hand XTRA _AUTH] 0] ${newnick}!${uhost}"
  920. }
  921. }
  922.  
  923. return "core"
  924.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement