Advertisement
Ford

AKA for Eggdrop

Feb 21st, 2013
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 11.36 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 hostmask "akaindex[address "${text}![getchanhost $text]" $aka::addresstype]"
  53.       if {[llength [hget "AKA" $hostmask]] <= 1} {
  54.         putlog "${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  55.       } else {
  56.         putlog "${aka::logo} ${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  57.       }
  58.     } else {
  59.       if {[hfind "AKA" "*${text}*" $matchno] != ""} {
  60.         set hostmask "akaindex[address [hfind "AKA" "*${text}*" $matchno] $aka::addresstype]"
  61.       }
  62.       if {[hfind "AKA" "*${text}*" $matchno] == ""} {
  63.         putlog "${aka::logo} ${aka::nickstextf}I have no data for ${aka::nicktextf}${text}."
  64.       } elseif {[llength [hget "AKA" $hostmask]] <= 1} {
  65.         putlog "${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  66.       } else {
  67.         putlog "${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  68.       }
  69.     }
  70.   }
  71.   proc search {nick host hand chan text {matchno 1}} {
  72.     if {[lsearch -exact [channel info $chan] +aka] != -1} {
  73.       if {[getchanhost $text] != ""} {
  74.         set hostmask "akaindex[address "${text}![getchanhost $text]" $aka::addresstype]"
  75.         if {[llength [hget "AKA" $hostmask]] <= 1} {
  76.           putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  77.         } else {
  78.           putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  79.         }
  80.       } else {
  81.         if {[hfind "AKA" "*${text}*" $matchno] != ""} {
  82.           set hostmask "akaindex[address [hfind "AKA" "*${text}*" $matchno] $aka::addresstype]"
  83.         }
  84.         if {[hfind "AKA" "*${text}*" $matchno] == ""} {
  85.           putserv "PRIVMSG $chan :${aka::logo} ${aka::nickstextf}I have no data for ${aka::nicktextf}${text}."
  86.         } elseif {[llength [hget "AKA" $hostmask]] <= 1} {
  87.           putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${text} ${aka::nickstextf} has not been know by any other names."
  88.         } else {
  89.           putserv "PRIVMSG $chan :${aka::nicktextf}${text} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  90.         }
  91.       }
  92.     }
  93.   }
  94.   proc loadhash {type} {
  95.     if {[file exists "${::network}aka.hsh"]} { aka::hload "AKA" "${::network}aka.hsh" }
  96.   }
  97.   proc savehash {type} {
  98.     hsave "AKA" "${::network}aka.hsh"
  99.   }
  100.   proc nick {nick host hand chan newnick} {
  101.     set hostmask "akaindex[address "${nick}!${host}" $aka::addresstype]"
  102.     hadd "AKA" "${nick}!${host}" [unixtime]
  103.     hadd "AKA" $hostmask [nodups [hget "AKA" $hostmask] $newnick]
  104.   }
  105.   proc ntimer {name seconds command} {
  106.     set killtimer [hget NTIMER $name]
  107.     if {[set idx [lsearch -glob [utimers] "*$killtimer*"]] != -1 && $killtimer != ""} {
  108.       putlog "killed timer [lindex [lindex [utimers] $idx] 2]"
  109.       killutimer [lindex [lindex [utimers] $idx] 2]
  110.     }
  111.     hadd NTIMER $name [utimer $seconds $command]
  112.     utimer $seconds "aka::hdel {NTIMER} $name"
  113.   }
  114.   proc address {hostmask type} {
  115.     set halfhost ""
  116.     regexp -- {^(.*)\!(.*)@(.*?)(\..*\..*)?$} $hostmask wholematch nick user host halfhost
  117.     switch $type {
  118.       0 { return "*!${user}@${host}" }
  119.       1 { return "*!*${user}@${host}" }
  120.       2 { return "*!*@${host}" }
  121.       3 {
  122.           if {$halfhost != ""} {
  123.             return "*!*${user}@*${host}"
  124.           } else {
  125.             return "*!*${user}@Ford-IRC.Land "
  126.           }
  127.         }
  128.       4 {      
  129.           if {$halfhost != ""} {
  130.             return "*!*@*${halfhost}"
  131.           } else {
  132.             return "*!*@${host}"
  133.           }
  134.         }
  135.       5 { return $hostmask }
  136.       6 { return "${nick}!*${user}@${host}" }
  137.       7 { return "${nick}!*@${host}" }
  138.       8 {
  139.           if {$halfhost != ""} {
  140.             return "${nick}!*${user}@*${halfhost}"
  141.           } else {
  142.             return "${nick}!*${user}@${host}"
  143.           }
  144.         }
  145.       9 {
  146.           if {$halfhost != ""} {
  147.             return "${nick}!*@*${halfhost}"
  148.           } else {
  149.             return "${nick}!*@${host}"
  150.           }
  151.         }
  152.       default { return $hostmask }
  153.     }
  154.   }
  155.   proc joinadd {chan} {
  156.     foreach user [chanlist $chan] {
  157.       set host [getchanhost $user $chan]
  158.       set hostmask "akaindex[address "${user}!${host}" $aka::addresstype]"
  159.       hadd "AKA" "${user}!${host}" [unixtime]
  160.       hadd "AKA" $hostmask [nodups [hget "AKA" $hostmask] $user]
  161.     }  
  162.   }
  163.   proc nodups {text add} {
  164.     set return ""
  165.     foreach name $text {
  166.       if {![string match -nocase $name $add]} {
  167.         set return [concat $return $name]
  168.       }
  169.     }
  170.     if {[llength $return] >= [expr $aka::maxakas -1]} {
  171.       set return [lrange $return 1 end]
  172.     }
  173.     return [concat $return $add]
  174.   }
  175.   proc noop {nick} {
  176.     return 0
  177.   }  
  178.   proc join {nick host hand chan} {
  179.     if {$nick != $::botnick} {
  180.       set hostmask "akaindex[address "${nick}!${host}" $aka::addresstype]"
  181.       hadd "AKA" "${nick}!${host}" [unixtime]
  182.       hadd "AKA" $hostmask [nodups [hget "AKA" $hostmask] $nick]
  183.       if {$nick != [hget "AKA" $hostmask]} {
  184.         if {[lsearch -exact [channel info $chan] +akashowlog] != -1} {
  185.           if {[set idx [lsearch -glob [utimers] "*aka::noop $nick*"]] == -1} {
  186.             putlog "$aka::logo ${aka::nicktextf}${nick} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  187.             utimer $aka::dupsdelay "aka::noop $nick"
  188.           }
  189.         }
  190.         if {[lsearch -exact [channel info $chan] +akashowchan] != -1} {
  191.           if {[set idx [lsearch -glob [utimers] "*aka::noop ${chan}${nick}*"]] == -1} {
  192.             putserv "PRIVMSG $chan :${aka::logo} ${aka::nicktextf}${nick} $aka::logo ${aka::nickstextf}[string map {" " \,} [hget "AKA" $hostmask]]"
  193.             utimer $aka::dupsdelay "aka::noop ${chan}${nick}"
  194.           }
  195.         }
  196.       }
  197.     } else {
  198.       timer 1 "aka::joinadd $chan"
  199.     }
  200.   }
  201.   proc hadd {hashname hashitem hashdata } {
  202.     global $hashname
  203.     set ${hashname}($hashitem) $hashdata
  204.   }
  205.   proc hget {hashname hashitem} {
  206.     upvar #0 $hashname hgethashname
  207.     if {[info exists hgethashname($hashitem)]} {
  208.       return $hgethashname($hashitem)
  209.     } else {
  210.       return ""
  211.     }
  212.   }
  213.   proc hfind {hashname search matchno {type "w"}} {
  214.     upvar #0 $hashname hfindhashname
  215.     if {$type == "w"} {
  216.       if {[array exists hfindhashname]} {
  217.         if {$matchno == 0} {
  218.           return [llength [array names hfindhashname $search]]
  219.         } else {
  220.           set matchno [expr $matchno - 1]
  221.           return [lindex [array names hfindhashname $search] $matchno]
  222.         }
  223.       }
  224.     } elseif {$type == "W"} {
  225.       set count 0
  226.       foreach {item value} [array get hfindhashname] {
  227.         if {[string match $search $value] && ![string match "*akaindex*" $item]} {
  228.           incr count
  229.           if {$count == $matchno} { return $item }
  230.         }
  231.       }
  232.       if {$matchno == 0} {
  233.         return $count
  234.       } else {
  235.         return ""
  236.       }
  237.     }
  238.   }
  239.   proc hsave {hashname filename} {
  240.     upvar #0 $hashname hsavehashname
  241.     if {[array exists hsavehashname]} {
  242.       set hsavefile [open $filename w]
  243.       foreach {key value} [array get hsavehashname] {
  244.         puts $hsavefile "${key}=${value}"
  245.       }
  246.       close $hsavefile
  247.     }
  248.   }
  249.   proc hload {hashname filename} {
  250.     upvar #0 $hashname hloadhashname
  251.     hfree $hashname
  252.     set hloadfile [open $filename]
  253.     set linenum 0
  254.     while {[gets $hloadfile line] >= 0} {
  255.       if {[regexp -- {([^\s]+)=(.*)$} $line wholematch item data]} {
  256.         set hloadhashname($item) $data
  257.       }
  258.     }
  259.     close $hloadfile
  260.   }
  261.   proc hfree {hashname} {
  262.     upvar #0 $hashname hfreehashname
  263.     if {[array exists hfreehashname]} {
  264.       foreach key [array names hfreehashname] {
  265.         unset hfreehashname($key)
  266.       }
  267.     }
  268.   }
  269.   proc hdel {hashname hashitem} {
  270.     upvar #0 $hashname hdelhashname
  271.     if {[info exists hdelhashname($hashitem)]} {
  272.       unset hdelhashname($hashitem)
  273.     }
  274.   }
  275.   proc hcopy {hashfrom hashto} {
  276.     upvar #0 $hashfrom hashfromlocal $hashto hashtolocal
  277.     array set hashtolocal [array get hashfromlocal]
  278.   }  
  279. }
  280. #aka::ntimer "test" 10 "putlog {test some other stuff}"
  281. #aka::ntimer "test" 1 "putlog {test this stuff}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement