Advertisement
Guest User

.

a guest
Oct 26th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.83 KB | None | 0 0
  1. # .chanset #channel +seen -- to work#
  2. set bs(limit) 8000
  3. set bs(nicksize) 12
  4. set bs(no_pub) ""
  5. set bs(quiet_chan) ""
  6. set bs(no_log) ""
  7. set bs(log_only) ""
  8. set bs(cmdchar) "!"
  9. set bs(flood) 4:15
  10. set bs(ignore) 1
  11. set bs(ignore_time) 2
  12. set bs(smartsearch) 1
  13. set bs(logqueries) 1
  14. set bs(path) ""
  15.  
  16. if {[bind msg -|- help] != "*msg:help"} {bind msg -|- help *msg:help} ; #this is to fix a bind I didn't intend to use in a prev version (which screwed up msg'd help). Sorry!
  17. proc bs_filt {data} {
  18. regsub -all -- \\\\ $data \\\\\\\\ data ; regsub -all -- \\\[ $data \\\\\[ data ; regsub -all -- \\\] $data \\\\\] data
  19. regsub -all -- \\\} $data \\\\\} data ; regsub -all -- \\\{ $data \\\\\{ data ; regsub -all -- \\\" $data \\\\\" data ; return $data
  20. }
  21. proc bs_flood_init {} {
  22. global bs bs_flood_array ; if {![string match *:* $bs(flood)]} {putlog "$bs(version): var bs(flood) not set correctly." ; return}
  23. set bs(flood_num) [lindex [split $bs(flood) :] 0] ; set bs(flood_time) [lindex [split $bs(flood) :] 1] ; set i [expr $bs(flood_num) - 1]
  24. while {$i >= 0} {set bs_flood_array($i) 0 ; incr i -1 ; }
  25. } ; bs_flood_init
  26. proc bs_flood {nick uhost} {
  27. global bs bs_flood_array ; if {$bs(flood_num) == 0} {return 0} ; set i [expr $bs(flood_num) - 1]
  28. while {$i >= 1} {set bs_flood_array($i) $bs_flood_array([expr $i - 1]) ; incr i -1} ; set bs_flood_array(0) [unixtime]
  29. if {[expr [unixtime] - $bs_flood_array([expr $bs(flood_num) - 1])] <= $bs(flood_time)} {
  30. putlog "$bs(version): Flood detected from $nick." ; if {$bs(ignore)} {newignore [join [maskhost *!*[string trimleft $uhost ~]]] $bs(version) flood $bs(ignore_time)} ; return 1
  31. } {return 0}
  32. }
  33. if {[lsearch -exact [bind time -|- "*2 * * * *"] bs_timedsave] > -1} {unbind time -|- "*2 * * * *" bs_timedsave} ; #backup frequency can be lower
  34. proc bs_read {} {
  35. global bs_list userfile bs
  36. if {![string match */* $userfile]} {set name [lindex [split $userfile .] 0]} {
  37. set temp [split $userfile /] ; set temp [lindex $temp [expr [llength $temp]-1]] ; set name [lindex [split $temp .] 0]
  38. }
  39. if {![file exists $bs(path)bs_data.$name]} {
  40. if {![file exists $bs(path)bs_data.$name.bak]} {
  41. putlog "Old seen data not found!" ; putlog "If this is the first time you've run the script, don't worry." ; putlog "If there *should* be a data file from past runs of this script... worry." ; return
  42. } {exec cp $bs(path)bs_data.$name.bak $bs(path)bs_data.$name ; putlog " Old seen data not found! Using backup data."}
  43. } ; set fd [open $bs(path)bs_data.$name r]
  44. set bsu_ver "" ; set break 0
  45. while {![eof $fd]} {
  46. set inp [gets $fd] ; if {[eof $fd]} {break} ; if {[string trim $inp " "] == ""} {continue}
  47. if {[string index $inp 0] == "#"} {set bsu_version [string trimleft $inp #] ; continue}
  48. if {![info exists bsu_version] || $bsu_version == "" || $bsu_version < $bs(updater)} {
  49. putlog "Updating database to new version of bseen..."
  50. #bugfix (b) - loading the wrong updater version
  51. if {[source scripts/bseen_updater1.4.2.tcl] != "ok"} {set temp 1} {set temp 0}
  52. if {$temp || [bsu_go] || [bsu_finish]} {
  53. putlog "A serious problem was encountered while updating the bseen database."
  54. if {$temp} {putlog " The updater script could not be found."}
  55. putlog "It is *not* safe to run the bot w/ a bseen database that is not matched to this version of bseen."
  56. putlog "If you can't find the problem, the only option is to remove the bs_data.$name and bs_data.$name.bak files. Then restart the bot."
  57. putlog "Because this is a potential crash point in the bot, the bot will now halt." ; die "critical error in bseen encountered"
  58. } ; set break 1 ; break
  59. }
  60. set nick [lindex $inp 0] ; set bs_list([string tolower $nick]) $inp
  61. } ; close $fd
  62. if {$break} {bs_read} {putlog "Done loading [array size bs_list] seen records."}
  63. }
  64.  
  65. ###
  66. #Must check to make sure the version didn't change during a .rehash
  67. proc bs_update {} {
  68. global bs
  69. putlog "A new version of bseen is dynamically being loaded."
  70. putlog " Verifying the integrity of the database across versions..."
  71. bs_save ; bs_read
  72. }
  73. set bs(updater) 10402 ; set bs(version) module
  74. if {[info exists bs_list]} {
  75. #a rehash was done
  76. if {[info exists bs(oldver)]} {
  77. if {$bs(oldver) < $bs(updater)} {bs_update} ;# old ver found
  78. } {bs_update} ;# pre- 1.4.0
  79. }
  80. set bs(oldver) $bs(updater)
  81. putlog "+ LOADED seen $bs(version)"
  82. if {![info exists bs_list] || [array size bs_list] == 0} {putlog "Loading seen database..." ; bs_read}
  83.  
  84. ###
  85.  
  86. bind time - "12 * * * *" bs_timedsave
  87. proc bs_timedsave {min b c d e} {bs_save}
  88. proc bs_save {} {
  89. global bs_list userfile bs ; if {[array size bs_list] == 0} {return}
  90. if {![string match */* $userfile]} {set name [lindex [split $userfile .] 0]} {
  91. set temp [split $userfile /] ; set temp [lindex $temp [expr [llength $temp]-1]] ; set name [lindex [split $temp .] 0]
  92. }
  93. if {[file exists $bs(path)bs_data.$name]} {catch {exec cp -f $bs(path)bs_data.$name $bs(path)bs_data.$name.bak}}
  94. set fd [open $bs(path)bs_data.$name w] ; set id [array startsearch bs_list] ; putlog "Backing up seen data..."
  95. puts $fd "#$bs(updater)"
  96. while {[array anymore bs_list $id]} {set item [array nextelement bs_list $id] ; puts $fd "$bs_list($item)"} ; array donesearch bs_list $id ; close $fd
  97. }
  98. #bugfix -- support new PART in egg1.5.x+
  99. if {[string trimleft [lindex $version 1] 0] >= 1050000} {
  100. bind part -|- * bs_part
  101. } {
  102. if {[lsearch -exact [bind part -|- *] bs_part] > -1} {unbind part -|- * bs_part}
  103. bind part -|- * bs_part_oldver
  104. }
  105. proc bs_part_oldver {a b c d} {bs_part $a $b $c $d ""}
  106. #bugfix - new bs_part proc
  107. proc bs_part {nick uhost hand chan reason} {bs_add $nick "[list $uhost] [unixtime] part $chan [split $reason]"}
  108. bind join -|- * bs_join
  109. proc bs_join {nick uhost hand chan} {bs_add $nick "[list $uhost] [unixtime] join $chan"}
  110. bind sign -|- * bs_sign
  111. proc bs_sign {nick uhost hand chan reason} {bs_add $nick "[list $uhost] [unixtime] quit $chan [split $reason]"}
  112. bind kick -|- * bs_kick
  113. proc bs_kick {nick uhost hand chan knick reason} {bs_add $knick "[getchanhost $knick $chan] [unixtime] kick $chan [list $nick] [list $reason]"}
  114. bind nick -|- * bs_nick
  115. proc bs_nick {nick uhost hand chan newnick} {set time [unixtime] ; bs_add $nick "[list $uhost] [expr $time -1] nick $chan [list $newnick]" ; bs_add $newnick "[list $uhost] $time rnck $chan [list $nick]"}
  116. bind splt -|- * bs_splt
  117. proc bs_splt {nick uhost hand chan} {bs_add $nick "[list $uhost] [unixtime] splt $chan"}
  118. bind rejn -|- * bs_rejn
  119. proc bs_rejn {nick uhost hand chan} {bs_add $nick "[list $uhost] [unixtime] rejn $chan"}
  120. bind chon -|- * bs_chon
  121. proc bs_chon {hand idx} {foreach item [dcclist] {if {[lindex $item 3] != "CHAT"} {continue} ; if {[lindex $item 0] == $idx} {bs_add $hand "[lindex $item 2] [unixtime] chon" ; break}}}
  122. if {[lsearch -exact [bind chof -|- *] bs_chof] > -1} {unbind chof -|- * bs_chof} ; #this bind isn't needed any more
  123. bind chjn -|- * bs_chjn
  124. proc bs_chjn {bot hand channum flag sock from} {bs_add $hand "[string trimleft $from ~] [unixtime] chjn $bot"}
  125. bind chpt -|- * bs_chpt
  126. proc bs_chpt {bot hand args} {set old [split [bs_search ? [string tolower $hand]]] ; if {$old != "0"} {bs_add $hand "[join [string trim [lindex $old 1] ()]] [unixtime] chpt $bot"}}
  127.  
  128. if {[string trimleft [lindex $version 1] 0] > 1030000} {bind away -|- * bs_away}
  129. proc bs_away {bot idx msg} {
  130. global botnet-nick
  131. if {$bot == ${botnet-nick}} {set hand [idx2hand $idx]} {return}
  132. set old [split [bs_search ? [string tolower $hand]]]
  133. if {$old != "0"} {bs_add $hand "[join [string trim [lindex $old 1] ()]] [unixtime] away $bot [bs_filt [join $msg]]"}
  134. }
  135. bind dcc n|- unseen bs_unseen
  136. proc bs_unseen {hand idx args} {
  137. global bs_list
  138. set tot 0 ; set chan [string tolower [lindex $args 0]] ; set id [array startsearch bs_list]
  139. while {[array anymore bs_list $id]} {
  140. set item [array nextelement bs_list $id]
  141. if {$chan == [string tolower [lindex $bs_list($item) 4]]} {incr tot ; lappend remlist $item}
  142. }
  143. array donesearch bs_list $id ; if {$tot > 0} {foreach item $remlist {unset bs_list($item)}}
  144. putlog "$hand removed $chan from the bseen database. $tot entries removed."
  145. putidx $idx "$chan successfully removed. $tot entries deleted from the bseen database."
  146. }
  147. bind bot -|- bs_botsearch bs_botsearch
  148. proc bs_botsearch {from cmd args} {
  149. global botnick ; set args [join $args]
  150. set command [lindex $args 0] ; set target [lindex $args 1] ; set nick [lindex $args 2] ; set search [bs_filt [join [lrange $args 3 e]]]
  151. if {[string match *\\\** $search]} {
  152. set output [bs_seenmask bot $nick $search]
  153. if {$output != "No matches were found." && ![string match "I'm not on *" $output]} {putbot $from "bs_botsearch_reply $command \{$target\} {$nick, $botnick says: [bs_filt $output]}"}
  154. } {
  155. set output [bs_output bot $nick [bs_filt [lindex $search 0]] 0]
  156. if {$output != 0 && [lrange [split $output] 1 4] != "I don't remember seeing"} {putbot $from "bs_botsearch_reply $command \{$target\} {$nick, $botnick says: [bs_filt $output]}"}
  157. }
  158. }
  159. if {[info exists bs(bot_delay)]} {unset bs(bot_delay)}
  160. bind bot -|- bs_botsearch_reply bs_botsearch_reply
  161. proc bs_botsearch_reply {from cmd args} {
  162. global bs ; set args [join $args]
  163. if {[lindex [lindex $args 2] 5] == "not" || [lindex [lindex $args 2] 4] == "not"} {return}
  164. if {![info exists bs(bot_delay)]} {
  165. set bs(bot_delay) on ; utimer 10 {if {[info exists bs(bot_delay)]} {unset bs(bot_delay)}}
  166. if {![lindex $args 0]} {putdcc [lindex $args 1] "[join [lindex $args 2]]"} {puthelp "[lindex $args 1] :[join [lindex $args 2]]"}
  167. }
  168. }
  169. bind dcc -|- seen bs_dccreq1
  170. bind dcc -|- seennick bs_dccreq2
  171. proc bs_dccreq1 {hand idx args} {bs_dccreq $hand $idx $args 0}
  172. proc bs_dccreq2 {hand idx args} {bs_dccreq $hand $idx $args 1}
  173. proc bs_dccreq {hand idx args no} {
  174. set args [bs_filt [join $args]] ; global bs
  175. if {[string match *\\\** [lindex $args 0]]} {
  176. set output [bs_seenmask dcc $hand $args]
  177. if {$output == "No matches were found."} {putallbots "bs_botsearch 0 $idx $hand $args"}
  178. if {[string match "I'm not on *" $output]} {putallbots "bs_botsearch 0 $idx $hand $args"}
  179. putdcc $idx $output ; return $bs(logqueries)
  180. }
  181. set search [bs_filt [lindex $args 0]]
  182. set output [bs_output dcc $hand $search $no]
  183. if {$output == 0} {return 0}
  184. if {[lrange [split $output] 1 4] == "I don't remember seeing"} {putallbots "bs_botsearch 0 $idx $hand $args"}
  185. putdcc $idx "$output" ; return $bs(logqueries)
  186. }
  187. bind msg -|- seen bs_msgreq1
  188. bind msg -|- seennick bs_msgreq2
  189. proc bs_msgreq1 {nick uhost hand args} {bs_msgreq $nick $uhost $hand $args 0}
  190. proc bs_msgreq2 {nick uhost hand args} {bs_msgreq $nick $uhost $hand $args 1}
  191. proc bs_msgreq {nick uhost hand args no} {
  192. if {[bs_flood $nick $uhost]} {return 0} ; global bs
  193. set args [bs_filt [join $args]]
  194. if {[string match *\\\** [lindex $args 0]]} {
  195. set output [bs_seenmask msg $nick $args]
  196. if {$output == "No matches were found."} {putallbots "bs_botsearch 1 \{notice $nick\} $nick $args"}
  197. if {[string match "I'm not on *" $output]} {putallbots "bs_botsearch 1 \{notice $nick\} $nick $args"}
  198. puthelp "notice $nick :$output" ; return $bs(logqueries)
  199. }
  200. set search [bs_filt [lindex $args 0]]
  201. set output [bs_output $search $nick $search $no]
  202. if {$output == 0} {return 0}
  203. if {[lrange [split $output] 1 4] == "I don't remember seeing"} {putallbots "bs_botsearch 1 \{notice $nick\} $nick $args"}
  204. puthelp "notice $nick :$output" ; return $bs(logqueries)
  205. }
  206. bind pub -|- [string trim $bs(cmdchar)]seen bs_pubreq1
  207. bind pub -|- [string trim $bs(cmdchar)]seennick bs_pubreq2
  208. proc bs_pubreq1 {nick uhost hand chan args} {bs_pubreq $nick $uhost $hand $chan $args 0}
  209. proc bs_pubreq2 {nick uhost hand chan args} {bs_pubreq $nick $uhost $hand $chan $args 1}
  210. proc bs_pubreq {nick uhost hand chan args no} {
  211. if {[bs_flood $nick $uhost] || ![channel get $chan seen]} {return 0}
  212. global botnick bs ; set i 0
  213. if {[lsearch -exact $bs(no_pub) [string tolower $chan]] >= 0} {return 0}
  214. if {$bs(log_only) != "" && [lsearch -exact $bs(log_only) [string tolower $chan]] == -1} {return 0}
  215. set args [bs_filt [join $args]]
  216. if {[lsearch -exact $bs(quiet_chan) [string tolower $chan]] >= 0} {set target "notice $nick"} {set target "privmsg $chan"}
  217. if {[string match *\\\** [lindex $args 0]]} {
  218. set output [bs_seenmask $chan $hand $args]
  219. if {$output == "No matches were found."} {putallbots "bs_botsearch 1 \{$target\} $nick $args"}
  220. if {[string match "I'm not on *" $output]} {putallbots "bs_botsearch 1 \{$target\} $nick $args"}
  221. puthelp "$target :$output" ; return $bs(logqueries)
  222. }
  223. set data [bs_filt [string trimright [lindex $args 0] ?!.,]]
  224. if {[string tolower $nick] == [string tolower $data] } {puthelp "$target :$nick, go look in a mirror." ; return $bs(logqueries)}
  225. if {[string tolower $data] == [string tolower $botnick] } {puthelp "$target :$nick, I'm right here. Quit wasting my time!" ; return $bs(logqueries)}
  226. if {[onchan $data $chan]} {puthelp "$target :$nick, $data is right here!" ; return $bs(logqueries)}
  227. set output [bs_output $chan $nick $data $no] ; if {$output == 0} {return 0}
  228. if {[lrange [split $output] 1 4] == "I don't remember seeing"} {putallbots "bs_botsearch 1 \{$target\} $nick $args"}
  229. puthelp "$target :$output" ; return $bs(logqueries)
  230. }
  231. proc bs_output {chan nick data no} {
  232. global botnick bs version bs_list
  233. set data [string tolower [string trimright [lindex $data 0] ?!.,]]
  234. if {$data == ""} {return 0}
  235. if {[string tolower $nick] == $data} {return [concat $nick, go look in a mirror.]}
  236. if {$data == [string tolower $botnick]} {return [concat $nick, I'm right here. Quit wasting my time!]}
  237. if {[string length $data] > $bs(nicksize)} {return 0}
  238. if {$bs(smartsearch) != 1} {set no 1}
  239. if {$no == 0} {
  240. set matches "" ; set hand "" ; set addy ""
  241. if {[lsearch -exact [array names bs_list] $data] != "-1"} {
  242. set addy [lindex $bs_list([string tolower $data]) 1] ; set hand [finduser $addy]
  243. foreach item [bs_seenmask dcc ? [maskhost $addy]] {if {[lsearch -exact $matches $item] == -1} {set matches "$matches $item"}}
  244. }
  245. if {[validuser $data]} {set hand $data}
  246. if {$hand != "*" && $hand != ""} {
  247. if {[string trimleft [lindex $version 1] 0]>1030000} {set hosts [getuser $hand hosts]} {set hosts [gethosts $hand]}
  248. foreach addr $hosts {
  249. foreach item [string tolower [bs_seenmask dcc ? $addr]] {
  250. if {[lsearch -exact [string tolower $matches] [string tolower $item]] == -1} {set matches [concat $matches $item]}
  251. }
  252. }
  253. }
  254. if {$matches != ""} {
  255. set matches [string trimleft $matches " "]
  256. set len [llength $matches]
  257. if {$len == 1} {return [bs_search $chan [lindex $matches 0]]}
  258. if {$len > 99} {return [concat I found $len matches to your query\; please refine it to see any output.]}
  259. set matches [bs_sort $matches]
  260. set key [lindex $matches 0]
  261. if {[string tolower $key] == [string tolower $data]} {return [bs_search $chan $key]}
  262. if {$len <= 5} {
  263. set output [concat I found $len matches to your query (sorted): [join $matches].]
  264. set output [concat $output [bs_search $chan $key]] ; return $output
  265. } {
  266. set output [concat I found $len matches to your query. Here are the 5 most recent (sorted): [join [lrange $matches 0 4]].]
  267. set output [concat $output [bs_search $chan $key]] ; return $output
  268. }
  269. }
  270. }
  271. set temp [bs_search $chan $data]
  272. if {$temp != 0} { return $temp } {
  273. #$data not found in $bs_list, so search userfile
  274. if {![validuser [bs_filt $data]] || [string trimleft [lindex $version 1] 0]<1030000} {
  275. return "$nick, I don't remember seeing $data."
  276. } {
  277. set seen [getuser $data laston]
  278. if {[getuser $data laston] == ""} {return "$nick, I don't remember seeing $data."}
  279. if {($chan != [lindex $seen 1] || $chan == "bot" || $chan == "msg" || $chan == "dcc") && [validchan [lindex $seen 1]] && [lindex [channel info [lindex $seen 1]] 23] == "+secret"} {
  280. set chan "-secret-"
  281. } {
  282. set chan [lindex $seen 1]
  283. }
  284. return [concat $nick, $data was last seen on $chan [bs_when [lindex $seen 0]] ago.]
  285. }
  286. }
  287. }
  288. proc bs_search {chan n} {
  289. global bs_list ; if {![info exists bs_list]} {return 0}
  290. if {[lsearch -exact [array names bs_list] [string tolower $n]] != "-1"} {
  291. #bugfix: let's see if the split added below fixes the eggdrop1.4.2 truncation bug
  292. set data [split $bs_list([string tolower $n])]
  293. #bugfix: added a join on the $n (c)
  294. set n [join [lindex $data 0]] ; set addy [lindex $data 1] ; set time [lindex $data 2] ; set marker 0
  295. if {([string tolower $chan] != [string tolower [lindex $data 4]] || $chan == "dcc" || $chan == "msg" || $chan == "bot") && [validchan [lindex $data 4]] && [lindex [channel info [lindex $data 4]] 23] == "+secret"} {
  296. set chan "-secret-"
  297. } {
  298. set chan [lindex $data 4]
  299. }
  300. switch -- [lindex $data 3] {
  301. part {
  302. set reason [lrange $data 5 e]
  303. if {$reason == ""} {set reason "."} {set reason " stating \"$reason\"."}
  304. set output [concat $n ($addy) was last seen parting $chan [bs_when $time] ago$reason]
  305. }
  306. quit { set output [concat $n ($addy) was last seen quitting from $chan [bs_when $time] ago stating ([join [lrange $data 5 e]]).] }
  307. kick { set output [concat $n ($addy) was last seen being kicked from $chan by [lindex $data 5] [bs_when $time] ago with the reason ([join [lrange $data 6 e]]).] }
  308. rnck {
  309. set output [concat $n ($addy) was last seen changing nicks from [lindex $data 5] on [lindex $data 4] [bs_when $time] ago.]
  310. if {[validchan [lindex $data 4]]} {
  311. if {[onchan $n [lindex $data 4]]} {
  312. set output [concat $output $n is still there.]
  313. } {
  314. set output [concat $output I don't see $n now, though.]
  315. }
  316. }
  317. }
  318. nick {
  319. set output [concat $n ($addy) was last seen changing nicks to [lindex $data 5] on [lindex $data 4] [bs_when $time] ago.]
  320. }
  321. splt { set output [concat $n ($addy) was last seen parting $chan due to a split [bs_when $time] ago.] }
  322. rejn {
  323. set output [concat $n ($addy) was last seen rejoining $chan from a split [bs_when $time] ago.]
  324. if {[validchan $chan]} {if {[onchan $n $chan]} {set output [concat $output $n is still on $chan.]} {set output [concat $output I don't see $n on $chan now, though.]}}
  325. }
  326. join {
  327. set output [concat $n ($addy) was last seen joining $chan [bs_when $time] ago.]
  328. if {[validchan $chan]} {if {[onchan $n $chan]} {set output [concat $output $n is still on $chan.]} {set output [concat $output I don't see $n on $chan now, though.]}}
  329. }
  330. away {
  331. set reason [lrange $data 5 e]
  332. if {$reason == ""} {
  333. set output [concat $n ($addy) was last seen returning to the partyline on $chan [bs_when $time] ago.]
  334. } {
  335. set output [concat $n ($addy) was last seen being marked as away ($reason) on $chan [bs_when $time] ago.]
  336. }
  337. }
  338. chon {
  339. set output [concat $n ($addy) was last seen joining the partyline [bs_when $time] ago.] ; set lnick [string tolower $n]
  340. foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output $n is on the partyline right now.] ; set marker 1 ; break}}
  341. if {$marker == 0} {set output [concat $output I don't see $n on the partyline now, though.]}
  342. }
  343. chof {
  344. set output [concat $n ($addy) was last seen leaving the partyline [bs_when $time] ago.] ; set lnick [string tolower $n]
  345. foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output $n is on the partyline in [lindex $item 1] still.] ; break}}
  346. }
  347. chjn {
  348. set output [concat $n ($addy) was last seen joining the partyline on $chan [bs_when $time] ago.] ; set lnick [string tolower $n]
  349. foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output $n is on the partyline right now.] ; set marker 1 ; break}}
  350. if {$marker == 0} {set output [concat $output I don't see $n on the partyline now, though.]}
  351. }
  352. chpt {
  353. set output [concat $n ($addy) was last seen leaving the partyline from $chan [bs_when $time] ago.] ; set lnick [string tolower $n]
  354. foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output $n is on the partyline in [lindex $item 1] still.] ; break}}
  355. }
  356. default {set output "error"}
  357. } ; return $output
  358. } {return 0}
  359. }
  360. proc bs_when {lasttime} {
  361. #This is equiv to mIRC's $duration() function
  362. set years 0 ; set days 0 ; set hours 0 ; set mins 0 ; set time [expr [unixtime] - $lasttime]
  363. if {$time < 60} {return "only $time seconds"}
  364. if {$time >= 31536000} {set years [expr int([expr $time/31536000])] ; set time [expr $time - [expr 31536000*$years]]}
  365. if {$time >= 86400} {set days [expr int([expr $time/86400])] ; set time [expr $time - [expr 86400*$days]]}
  366. if {$time >= 3600} {set hours [expr int([expr $time/3600])] ; set time [expr $time - [expr 3600*$hours]]}
  367. if {$time >= 60} {set mins [expr int([expr $time/60])]}
  368. if {$years == 0} {set output ""} elseif {$years == 1} {set output "1 year,"} {set output "$years years,"}
  369. if {$days == 1} {lappend output "1 day,"} elseif {$days > 1} {lappend output "$days days,"}
  370. if {$hours == 1} {lappend output "1 hour,"} elseif {$hours > 1} {lappend output "$hours hours,"}
  371. if {$mins == 1} {lappend output "1 minute"} elseif {$mins > 1} {lappend output "$mins minutes"}
  372. return [string trimright [join $output] ", "]
  373. }
  374. proc bs_add {nick data} {
  375. global bs_list bs
  376. if {[lsearch -exact $bs(no_log) [string tolower [lindex $data 3]]] >= 0 || ($bs(log_only) != "" && [lsearch -exact $bs(log_only) [string tolower [lindex $data 3]]] == -1)} {return}
  377. set bs_list([string tolower $nick]) "[bs_filt $nick] $data"
  378. }
  379. bind time - "*1 * * * *" bs_trim
  380. proc bs_lsortcmd {a b} {global bs_list ; set a [lindex $bs_list([string tolower $a]) 2] ; set b [lindex $bs_list([string tolower $b]) 2] ; if {$a > $b} {return 1} elseif {$a < $b} {return -1} {return 0}}
  381. proc bs_trim {min h d m y} {
  382. global bs bs_list ; if {![info exists bs_list] || ![array exists bs_list]} {return} ; set list [array names bs_list] ; set range [expr [llength $list] - $bs(limit) - 1] ; if {$range < 0} {return}
  383. set list [lsort -increasing -command bs_lsortcmd $list] ; foreach item [lrange $list 0 $range] {unset bs_list($item)}
  384. }
  385. proc bs_seenmask {ch nick args} {
  386. global bs_list bs ; set matches "" ; set temp "" ; set i 0 ; set args [join $args] ; set chan [lindex $args 1]
  387. if {$chan != "" && [string trimleft $chan #] != $chan} {
  388. if {![validchan $chan]} {return "I'm not on $chan."} {set chan [string tolower $chan]}
  389. } { set $chan "" }
  390. if {![info exists bs_list]} {return "No matches were found."} ; set data [bs_filt [string tolower [lindex $args 0]]]
  391.  
  392. #bugfix: unnecessarily complex masks essentially freeze the bot
  393. set maskfix 1
  394. while $maskfix {
  395. set mark 1
  396. if [regsub -all -- \\?\\? $data ? data] {set mark 0}
  397. if [regsub -all -- \\*\\* $data * data] {set mark 0}
  398. if [regsub -all -- \\*\\? $data * data] {set mark 0}
  399. if [regsub -all -- \\?\\* $data * data] {set mark 0}
  400. if $mark {break}
  401. }
  402.  
  403. set id [array startsearch bs_list]
  404. while {[array anymore bs_list $id]} {
  405. set item [array nextelement bs_list $id] ; if {$item == ""} {continue} ; set i 0 ; set temp "" ; set match [lindex $bs_list($item) 0] ; set addy [lindex $bs_list($item) 1]
  406. if {[string match $data $item![string tolower $addy]]} {
  407. set match [bs_filt $match] ; if {$chan != ""} {
  408. if {[string match $chan [string tolower [lindex $bs_list($item) 4]]]} {set matches [concat $matches $match]}
  409. } {set matches [concat $matches $match]}
  410. }
  411. }
  412. array donesearch bs_list $id
  413. set matches [string trim $matches " "]
  414. if {$nick == "?"} {return [bs_filt $matches]}
  415. set len [llength $matches]
  416. if {$len == 0} {return "No matches were found."}
  417. if {$len == 1} {return [bs_output $ch $nick $matches 1]}
  418. if {$len > 99} {return "I found $len matches to your query; please refine it to see any output."}
  419. set matches [bs_sort $matches]
  420. if {$len <= 5} {
  421. set output [concat I found $len matches to your query (sorted): [join $matches].]
  422. } {
  423. set output "I found $len matches to your query. Here are the 5 most recent (sorted): [join [lrange $matches 0 4]]."
  424. }
  425. return [concat $output [bs_output $ch $nick [lindex [split $matches] 0] 1]]
  426. }
  427. proc bs_sort {data} {global bs_list ; set data [bs_filt [join [lsort -decreasing -command bs_lsortcmd $data]]] ; return $data}
  428. bind dcc -|- seenstats bs_dccstats
  429. proc bs_dccstats {hand idx args} {putdcc $idx "[bs_stats]"; return 1}
  430. bind pub -|- [string trim $bs(cmdchar)]seenstats bs_pubstats
  431. proc bs_pubstats {nick uhost hand chan args} {
  432. global bs ; if {[bs_flood $nick $uhost] || [lsearch -exact $bs(no_pub) [string tolower $chan]] >= 0 || ($bs(log_only) != "" && [lsearch -exact $bs(log_only) [string tolower $chan]] == -1)} {return 0}
  433. if {[lsearch -exact $bs(quiet_chan) [string tolower $chan]] >= 0} {set target "notice $nick"} {set target "privmsg $chan"} ; puthelp "$target :[bs_stats]" ; return 1
  434. }
  435. bind msg -|- seenstats bs_msgstats
  436. proc bs_msgstats {nick uhost hand args} {global bs ; if {[bs_flood $nick $uhost]} {return 0} ; puthelp "notice $nick :[bs_stats]" ; return $bs(logqueries)}
  437. proc bs_stats {} {
  438. global bs_list bs ; set id [array startsearch bs_list] ; set bs_record [unixtime] ; set totalm 0 ; set temp ""
  439. while {[array anymore bs_list $id]} {
  440. set item [array nextelement bs_list $id]
  441. set tok [lindex $bs_list($item) 2] ; if {$tok == ""} {putlog "Damaged seen record: $item" ; continue}
  442. if {[lindex $bs_list($item) 2] < $bs_record} {set bs_record [lindex $bs_list($item) 2] ; set name $item}
  443. set addy [string tolower [maskhost [lindex $bs_list($item) 1]]] ; if {[lsearch -exact $temp $addy] == -1} {incr totalm ; lappend temp $addy}
  444. }
  445. array donesearch bs_list $id
  446. return "Currently I am tracking [array size bs_list]/$bs(limit) nicks, which comprise $totalm unique uhosts. The oldest record is [lindex $bs_list($name) 0]'s, which is from [bs_when $bs_record] ago."
  447. }
  448. bind dcc -|- chanstats bs_dccchanstats
  449. proc bs_dccchanstats {hand idx args} {
  450. if {$args == "{}"} {set args [console $idx]}
  451. if {[lindex $args 0] == "*"} {putdcc $idx "$hand, chanstats requires a channel arg, or a valid console channel." ; return 1}
  452. putdcc $idx "[bs_chanstats [lindex $args 0]]"
  453. return 1
  454. }
  455. bind pub -|- [string trim $bs(cmdchar)]chanstats bs_pubchanstats
  456. proc bs_pubchanstats {nick uhost hand chan args} {
  457. global bs ; set chan [string tolower $chan]
  458. if {[bs_flood $nick $uhost] || [lsearch -exact $bs(no_pub) $chan] >= 0 || ($bs(log_only) != "" && [lsearch -exact $bs(log_only) [string tolower $chan]] == -1)} {return 0}
  459. if {[lsearch -exact $bs(quiet_chan) $chan] >= 0} {set target "notice $nick"} {set target "privmsg $chan"}
  460. if {[lindex $args 0] != ""} {set chan [lindex $args 0]} ; puthelp "$target :[bs_chanstats $chan]" ; return $bs(logqueries)
  461. }
  462. bind msg -|- chanstats bs_msgchanstats
  463. proc bs_msgchanstats {nick uhost hand args} {global bs ; if {[bs_flood $nick $uhost]} {return 0} ; puthelp "notice $nick :[bs_chanstats [lindex $args 0]]" ; return $bs(logqueries)}
  464. proc bs_chanstats {chan} {
  465. global bs_list ; set chan [string tolower $chan] ; if {![validchan $chan]} {return "I'm not on $chan."}
  466. set id [array startsearch bs_list] ; set bs_record [unixtime] ; set totalc 0 ; set totalm 0 ; set temp ""
  467. while {[array anymore bs_list $id]} {
  468. set item [array nextelement bs_list $id] ; set time [lindex $bs_list($item) 2] ; if {$time == ""} {continue}
  469. if {$chan == [string tolower [lindex $bs_list($item) 4]]} {
  470. if {$time < $bs_record} {set bs_record $time} ; incr totalc
  471. set addy [string tolower [maskhost [lindex $bs_list($item) 1]]]
  472. if {[lsearch -exact $temp $addy] == -1} {incr totalm ; lappend temp $addy}
  473. }
  474. }
  475. array donesearch bs_list $id ; set total [array size bs_list]
  476. return "$chan is the source of [expr 100*$totalc/$total]% ($totalc/$total) of the seen database entries. In $chan, there were a total of $totalm unique uhosts seen in the last [bs_when $bs_record]."
  477. }
  478. foreach chan [string tolower [channels]] {if {![info exists bs_botidle($chan)]} {set bs_botidle($chan) [unixtime]}}
  479. bind join -|- * bs_join_botidle
  480. proc bs_join_botidle {nick uhost hand chan} {
  481. global bs_botidle botnick
  482. if {$nick == $botnick} {
  483. set bs_botidle([string tolower $chan]) [unixtime]
  484. }
  485. }
  486. bind pub -|- [string trim $bs(cmdchar)]lastspoke lastspoke
  487.  
  488. #bugfix: fixed lastspoke to handle [blah] nicks better (c)
  489. proc lastspoke {nick uhost hand chan args} {
  490. global bs botnick bs_botidle
  491. set chan [string tolower $chan] ; if {[bs_flood $nick $uhost] || [lsearch -exact $bs(no_pub) $chan] >= 0 || ($bs(log_only) != "" && [lsearch -exact $bs(log_only) $chan] == -1)} {return 0}
  492. if {[lsearch -exact $bs(quiet_chan) $chan] >= 0} {set target "notice $nick"} {set target "privmsg $chan"}
  493. set data [lindex [bs_filt [join $args]] 0]
  494. set ldata [string tolower $data]
  495. if {[string match *\** $data]} {
  496. set chanlist [string tolower [chanlist $chan]]
  497. if {[lsearch -glob $chanlist $ldata] > -1} {set data [lindex [chanlist $chan] [lsearch -glob $chanlist $ldata]]}
  498. }
  499. if {[onchan $data $chan]} {
  500. if {$ldata == [string tolower $botnick]} {puthelp "$target :$nick, must you waste my time?" ; return 1}
  501. set time [getchanidle $data $chan] ; set bottime [expr ([unixtime] - $bs_botidle($chan))/60]
  502. if {$time < $bottime} {
  503. if {$time > 0} {set diftime [bs_when [expr [unixtime] - $time*60 -15]]} {set diftime "less than a minute"}
  504. puthelp "$target :$data last uttered a word on $chan $diftime ago."
  505. } {
  506. set diftime [bs_when $bs_botidle($chan)]
  507. puthelp "$target :$data hasn't uttered a word since I joined $chan $diftime ago."
  508. }
  509. }
  510. return 1
  511. }
  512. bind msgm -|- "help seen" bs_help_msg_seen
  513. bind msgm -|- "help chanstats" bs_help_msg_chanstats
  514. bind msgm -|- "help seenstats" bs_help_msg_seenstats
  515. proc bs_help_msg_seen {nick uhost hand args} {
  516. global bs ; if {[bs_flood $nick $uhost]} {return 0}
  517. puthelp "notice $nick :### seen <query> \[chan\] $bs(version)"
  518. puthelp "notice $nick : Queries can be in the following formats:"
  519. puthelp "notice $nick : 'regular': seen lamer; seen lamest "
  520. puthelp "notice $nick : 'masked': seen *l?mer*; seen *.lame.com; seen *.edu #mychan" ; return 0
  521. }
  522. proc bs_help_msg_chanstats {nick uhost hand args} {
  523. global bs ; if {[bs_flood $nick $uhost]} {return 0}
  524. puthelp "notice $nick :### chanstats <chan> $bs(version)"
  525. puthelp "notice $nick : Returns the usage statistics of #chan in the seen database." ; return 0
  526. }
  527. proc bs_help_msg_seenstats {nick uhost hand args} {
  528. global bs ; if {[bs_flood $nick $uhost]} {return 0}
  529. puthelp "notice $nick :### seenstats $bs(version)"
  530. puthelp "notice $nick : Returns the status of the bseen database." ; return 0
  531. }
  532. bind dcc -|- seenversion bs_version
  533. proc bs_version {hand idx args} {global bs ; putidx $idx "### Bass's Seen script, $bs(version)."}
  534. bind dcc -|- help bs_help_dcc
  535. proc bs_help_dcc {hand idx args} {
  536. global bs
  537. switch -- $args {
  538. seen {
  539. putidx $idx "### seen <query> \[chan\] $bs(version)" ; putidx $idx "Queries can be in the following formats:"
  540. putidx $idx "'regular': seen lamer; seen lamest" ; putidx $idx "'masked': seen *l?mer*; seen *.lame.com; seen *.edu #mychan"
  541. }
  542. seennick {putidx $idx "### seen <nick> $bs(version)"}
  543. chanstats {putidx $idx "### chanstats <chan>" ; putidx $idx "Returns the usage statistics of #chan in the seen database."}
  544. seenstats {putidx $idx "### seenstats $bs(version)" ; putidx $idx "Returns the status of the bseen database."}
  545. unseen {if {[matchattr $hand n]} {putidx $idx "### unseen <chan> $bs(version)" ; putidx $idx "Deletes all <chan> entries from the bseen database."}}
  546. default {*dcc:help $hand $idx [join $args] ; return 0}
  547. } ; return 1
  548. }
  549.  
  550. return "seen module"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement