LoveAbleElf

aka.tcl

Dec 17th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.31 KB | None | 0 0
  1. ##############################################################################################
  2. ## ## aka.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ##
  3. ##############################################################################################
  4. ## .chanset #chan +aka for each channel you want to run the !aka trigger on. ##
  5. ## .chanset #chan +akashowlog to automatically see aka's in the partyline on join. ##
  6. ## .chanset #chan +akashowchan to automatically see aka's in #chan ##
  7. ##############################################################################################
  8. ## ____ __ ########################################### ##
  9. ## / __/___ _ ___ _ ___/ /____ ___ ___ ########################################### ##
  10. ## / _/ / _ `// _ `// _ // __// _ \ / _ \ ########################################### ##
  11. ## /___/ \_, / \_, / \_,_//_/ \___// .__/ ########################################### ##
  12. ## /___/ /___/ /_/ ########################################### ##
  13. ## ########################################### ##
  14. ##############################################################################################
  15. ## ## Start Setup. ## ##
  16. ##############################################################################################
  17. namespace eval aka {
  18. ## Edit cmdchar to change the !trigger used to for this script ## ##
  19. variable cmdchar "!"
  20. ## AKA Logo edit to change ## ##
  21. variable logo "\002\00304\[\00307A\00304K\00307A\00304\]\017"
  22. ## Edit nicktextf to change the colors of the nickname. ## ##
  23. variable nicktextf "\017\00309"
  24. ## Edit nickstextf to change the colors of the nicks in the aka list ## ##
  25. variable nickstextf "\017\00304"
  26. ## addresstype defines the type of search AKA uses to match users. Valid values are ## ##
  27. ## 0-9 0 *!user@host, 1 *!*user@host, 2 *!*@host, 3 *!*user@*.host, 4 *!*@*.host, 5 ## ##
  28. ## nick!user@host, 6 nick!*user@host, 7 nick!*@host, 8 nick!*user@*.host, 9 nick!*@*.host ##
  29. variable addresstype 2
  30. ## dupsdelay is the delay in seconds before the aka for a nick already displayed will ## ##
  31. ## be displayed again. This prevents redisplay on /hop and duplicates in partyline ## ##
  32. variable dupsdelay 5
  33. ## maxakas is the maximum number of nicks that will be recorded for a single hostmask ## ##
  34. variable maxakas 25
  35. ##############################################################################################
  36. ## ## End Setup. ## ##
  37. ##############################################################################################
  38. setudef flag akashowchan
  39. setudef flag akashowlog
  40. setudef flag aka
  41. bind dcc - aka aka::dccsearch
  42. bind pub -|- [string trimleft $aka::cmdchar]aka aka::search
  43. bind join -|- * aka::join
  44. bind nick -|- * aka::nick
  45. bind evnt -|- prerehash aka::savehash
  46. bind evnt -|- prerestart aka::savehash
  47. bind evnt -|- disconnect-server aka::savehash
  48. bind evnt -|- save aka::savehash
  49. bind evnt -|- init-server aka::loadhash
  50. proc dccsearch {hand idx text {matchno 1}} {
  51. if {[getchanhost $text] != ""} {
  52. set ltext [string tolower $text]
  53. set hostmask "akaindex[address "${text}![getchanhost $text]" $aka::addresstype]"
  54. if {[llength [hget "AKA" $hostmask]] <= 1} {
  55. putlog "${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  56. } else {
  57. putlog "${aka::logo} ${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  58. }
  59. } else {
  60. if {[hfind "AKA" "*${text}*" $matchno] != ""} {
  61. set hostmask "akaindex[address [hfind "AKA" "*${text}*" $matchno] $aka::addresstype]"
  62. }
  63. if {[hfind "AKA" "*${text}*" $matchno] == ""} {
  64. putlog "${aka::logo} ${aka::nickstextf}I have no data for ${aka::nicktextf}${text}."
  65. } elseif {[llength [hget "AKA" $hostmask]] <= 1} {
  66. putlog "${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  67. } else {
  68. putlog "${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  69. }
  70. }
  71. }
  72. proc search {nick host hand chan text {matchno 1}} {
  73. if {[lsearch -exact [channel info $chan] +aka] != -1} {
  74. if {[getchanhost $text] != ""} {
  75. set hostmask "akaindex[address "${text}![getchanhost $text]" $aka::addresstype]"
  76. if {[llength [hget "AKA" $hostmask]] <= 1} {
  77. putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  78. } else {
  79. putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  80. }
  81. } else {
  82. if {[hfind "AKA" "*${text}*" $matchno] != ""} {
  83. set hostmask "akaindex[address [hfind "AKA" "*${text}*" $matchno] $aka::addresstype]"
  84. }
  85. if {[hfind "AKA" "*${text}*" $matchno] == ""} {
  86. putserv "PRIVMSG $chan :${aka::logo} ${aka::nickstextf}I have no data for ${aka::nicktextf}${text}."
  87. } elseif {[llength [hget "AKA" $hostmask]] <= 1} {
  88. putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  89. } else {
  90. putserv "PRIVMSG $chan :${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  91. }
  92. }
  93. }
  94. }
  95. proc loadhash {type} {
  96. if {[file exists "${::network}aka.hsh"]} { aka::hload "AKA" "${::network}aka.hsh" }
  97. }
  98. proc savehash {type} {
  99. hsave "AKA" "${::network}aka.hsh"
  100. }
  101. proc nick {nick host hand chan newnick} {
  102. set hostmask "akaindex[address "${nick}!${host}" $aka::addresstype]"
  103. hadd "AKA" "${nick}!${host}" [unixtime]
  104. hadd "AKA" $hostmask [nodups [hget "AKA" $hostmask] $newnick]
  105. }
  106. proc ntimer {name seconds command} {
  107. set killtimer [hget NTIMER $name]
  108. if {[set idx [lsearch -glob [utimers] "*$killtimer*"]] != -1 && $killtimer != ""} {
  109. putlog "killed timer [lindex [lindex [utimers] $idx] 2]"
  110. killutimer [lindex [lindex [utimers] $idx] 2]
  111. }
  112. hadd NTIMER $name [utimer $seconds $command]
  113. utimer $seconds "aka::hdel {NTIMER} $name"
  114. }
  115. proc address {hostmask type} {
  116. set halfhost ""
  117. regexp -- {^(.*)\!(.*)@(.*?)(\..*\..*)?$} $hostmask wholematch nick user host halfhost
  118. switch $type {
  119. 0 { return "*!${user}@${host}${halfhost}" }
  120. 1 { return "*!*${user}@${host}${halfhost}" }
  121. 2 { return "*!*@${host}${halfhost}" }
  122. 3 {
  123. if {$halfhost != ""} {
  124. return "*!*${user}@*${halfhost}"
  125. } else {
  126. return "*!*${user}@${host}${halfhost}"
  127. }
  128. }
  129. 4 {
  130. if {$halfhost != ""} {
  131. return "*!*@*${halfhost}"
  132. } else {
  133. return "*!*@${host}${halfhost}"
  134. }
  135. }
  136. 5 { return $hostmask }
  137. 6 { return "${nick}!*${user}@${host}${halfhost}" }
  138. 7 { return "${nick}!*@${host}${halfhost}" }
  139. 8 {
  140. if {$halfhost != ""} {
  141. return "${nick}!*${user}@*${halfhost}"
  142. } else {
  143. return "${nick}!*${user}@${host}${halfhost}"
  144. }
  145. }
  146. 9 {
  147. if {$halfhost != ""} {
  148. return "${nick}!*@*${halfhost}"
  149. } else {
  150. return "${nick}!*@${host}${halfhost}"
  151. }
  152. }
  153. default { return $hostmask }
  154. }
  155. }
  156. proc joinadd {chan} {
  157. foreach user [chanlist $chan] {
  158. set host [getchanhost $user $chan]
  159. set hostmask "akaindex[address "${user}!${host}" $aka::addresstype]"
  160. hadd "AKA" "${user}!${host}" [unixtime]
  161. hadd "AKA" $hostmask [nodups [hget "AKA" $hostmask] $user]
  162. }
  163. }
  164. proc nodups {text add} {
  165. set return ""
  166. set addfix [string map {\[ \( \] \) \\ \\\\} $add]
  167. foreach name $text {
  168. set namefix [string map {\[ \( \] \) \\ \\\\} $name]
  169. if {![string match -nocase $namefix $addfix]} {
  170. set return [concat $return $name]
  171. }
  172. }
  173. if {[llength $return] >= [expr $aka::maxakas -1]} {
  174. set return [lrange $return 1 end]
  175. }
  176. return [concat $return $add]
  177. }
  178. proc noop {nick} {
  179. return 0
  180. }
  181. proc join {nick host hand chan} {
  182. if {$nick != $::botnick} {
  183. set hostmask "akaindex[address "${nick}!${host}" $aka::addresstype]"
  184. set safenick [string map {\[ \{ \] \}} $nick]
  185. hadd "AKA" "${nick}!${host}" [unixtime]
  186. hadd "AKA" $hostmask [nodups [hget "AKA" $hostmask] $nick]
  187. if {$nick != [hget "AKA" $hostmask]} {
  188. if {[lsearch -exact [channel info $chan] +akashowlog] != -1} {
  189. if {[set idx [lsearch -glob [utimers] "*aka::noop $safenick*"]] == -1} {
  190. putlog "$aka::logo ${aka::nicktextf}${nick} $aka::logo ${aka::nickstextf}[string map {" " "\,"} [hget "AKA" $hostmask]]"
  191. utimer $aka::dupsdelay "aka::noop $safenick"
  192. }
  193. }
  194. if {[lsearch -exact [channel info $chan] +akashowchan] != -1} {
  195. if {[set idx [lsearch -glob [utimers] "*aka::noop ${chan}${safenick}*"]] == -1} {
  196. putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${nick} $aka::logo ${aka::nickstextf}[string map {" " "\,"} [hget "AKA" $hostmask]]"
  197. utimer $aka::dupsdelay "aka::noop ${chan}${safenick}"
  198. }
  199. }
  200. }
  201. } else {
  202. timer 1 "aka::joinadd $chan"
  203. }
  204. }
  205. proc hadd {hashname hashitem hashdata } {
  206. global $hashname
  207. set ${hashname}($hashitem) $hashdata
  208. }
  209. proc hget {hashname hashitem} {
  210. upvar #0 $hashname hgethashname
  211. if {[info exists hgethashname($hashitem)]} {
  212. return $hgethashname($hashitem)
  213. } else {
  214. return ""
  215. }
  216. }
  217. proc hfind {hashname search matchno {type "w"}} {
  218. upvar #0 $hashname hfindhashname
  219. set search "(?i)[string map {* ""} ${search}]"
  220. if {$type == "w"} {
  221. if {[array exists hfindhashname]} {
  222. if {$matchno == 0} {
  223. return [llength [array names hfindhashname -regexp $search]]
  224. } else {
  225. set matchno [expr $matchno - 1]
  226. return [lindex [array names hfindhashname -regexp $search] $matchno]
  227. }
  228. }
  229. } elseif {$type == "W"} {
  230. set count 0
  231. foreach {item value} [array get hfindhashname] {
  232. if {[string match -nocase $search $value] && ![string match -nocase "*akaindex*" $item]} {
  233. incr count
  234. if {$count == $matchno} { return $item }
  235. }
  236. }
  237. if {$matchno == 0} {
  238. return $count
  239. } else {
  240. return ""
  241. }
  242. }
  243. }
  244. proc hsave {hashname filename} {
  245. upvar #0 $hashname hsavehashname
  246. if {[array exists hsavehashname]} {
  247. set hsavefile [open $filename w]
  248. foreach {key value} [array get hsavehashname] {
  249. puts $hsavefile "${key}=${value}"
  250. }
  251. close $hsavefile
  252. }
  253. }
  254. proc hload {hashname filename} {
  255. upvar #0 $hashname hloadhashname
  256. hfree $hashname
  257. set hloadfile [open $filename]
  258. set linenum 0
  259. while {[gets $hloadfile line] >= 0} {
  260. if {[regexp -- {([^\s]+)=(.*)$} $line wholematch item data]} {
  261. set hloadhashname($item) $data
  262. }
  263. }
  264. close $hloadfile
  265. }
  266. proc hfree {hashname} {
  267. upvar #0 $hashname hfreehashname
  268. if {[array exists hfreehashname]} {
  269. foreach key [array names hfreehashname] {
  270. unset hfreehashname($key)
  271. }
  272. }
  273. }
  274. proc hdel {hashname hashitem} {
  275. upvar #0 $hashname hdelhashname
  276. if {[info exists hdelhashname($hashitem)]} {
  277. unset hdelhashname($hashitem)
  278. }
  279. }
  280. proc hcopy {hashfrom hashto} {
  281. upvar #0 $hashfrom hashfromlocal $hashto hashtolocal
  282. array set hashtolocal [array get hashfromlocal]
  283. }
  284. }
  285. putlog "\002*Loaded* \002\00304\[\00307A\00304K\00307A\00304\]\017 \002by \
  286. Ford_Lawnmower irc.GeekShed.net #Script-Help .rss for help"
Add Comment
Please, Sign In to add comment