Guest User

Untitled

a guest
Jun 21st, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 7.50 KB | None | 0 0
  1. #  $Id: blacklist.tcl,v 0.3 2004/07/26 20:06:03 perpleXa Exp $  #
  2. #                                                               #
  3. #  Commands:                                                    #
  4. #  $blackadd <mask> <reason>                                    #
  5. #  $blackdel <mask|#id>                                         #
  6. #  $blacklist                                                   #
  7. #################################################################
  8.  
  9.  
  10. set blacklist_file "scripts/dbase/blacklist"
  11.  
  12.  
  13. bind PUB  m|o !blacklist  blacklist:list
  14. bind PUB  m|o !bl         blacklist:add
  15. bind PUB  m|o !unbl       blacklist:del
  16. bind TIME -|- "0* * * * *" blacklist:sentry
  17. bind JOIN -   "*"            blacklist:join
  18.  
  19.  
  20. proc blacklist:list {nickname hostname handle channel arguments} {
  21.  global blacklist
  22.   set entrys 0
  23.   puthelp "NOTICE $nickname :liste de la blacklist"
  24.   puthelp "NOTICE $nickname :Nr. Owner           Hostmask"
  25.   foreach entry [array names blacklist] {
  26.     incr entrys
  27.     set owner [lindex $blacklist($entry) 0]
  28.     while {[string length $owner] < 15} {
  29.       set owner "$owner "
  30.     }
  31.     if {[string length $entrys] < 2} {
  32.       set target "$entrys "
  33.     } else {
  34.       set target $entrys
  35.     }
  36.     puthelp "NOTICE $nickname :#$target $owner $entry"
  37.   }
  38.   puthelp "NOTICE $nickname :End of list."
  39. }
  40.  
  41.  
  42. proc blacklist:add {nickname hostname handle channel arguments} {
  43.  global blacklist
  44.   set arguments [blacklist:clean $arguments]
  45.   set banmask [blacklist:validate:host [lindex $arguments 0]]
  46.   if {([regexp -all -- {!} $banmask] > 1) || ([regexp -all -- {@} $banmask] > 1)} {
  47.     puthelp "NOTICE $nickname :Sorry, couldn't add that hostmask."
  48.     return
  49.   }
  50.   set owner $handle
  51.   if {[regexp {^(\d{1,2}|[0-3][0-6][0-5])$} [lindex $arguments 1]]} {
  52.    set expire [expr ([lindex $arguments 1] * 86400) + [unixtime]]
  53.    set reason [join [lrange $arguments 2 end]]
  54.   } else {
  55.    set expire 0
  56.    set reason [join [lrange $arguments 1 end]]
  57.   }
  58.   if {[llength $reason] >= 1} {
  59.     if {![info exists blacklist($banmask)]} {
  60.       set blacklist($banmask) "$owner $expire $reason"
  61.       puthelp "NOTICE $nickname :Done. $banmask blacklisted successfully (reason: $reason)."
  62.       blacklist:sentry
  63.     } else {
  64.       puthelp "NOTICE $nickname :Sorry, couldn't add that hostmask."
  65.     }
  66.   } else {
  67.     puthelp "NOTICE $nickname :You forgot to type a blacklist reason."
  68.   }
  69. }
  70.  
  71.  
  72. proc blacklist:del {nickname hostname handle channel arguments} {
  73.  global blacklist
  74.   set arguments [blacklist:clean $arguments]
  75.   set banmask [lindex $arguments 0]
  76.   set success 0
  77.   if {[regexp {^#([0-9]+)$} $banmask tmp number]} {
  78.     set item 0
  79.     foreach entry [array names blacklist] {
  80.       incr item
  81.       if {$item == $number} {
  82.         unset blacklist($entry)
  83.         set success 1
  84.       }
  85.     }
  86.   } else {
  87.     if {[info exists blacklist($banmask)]} {
  88.       unset blacklist($banmask)
  89.       set success 1
  90.     }
  91.   }
  92.   if {$success == 0} {
  93.     puthelp "NOTICE $nickname :Couldn't delete the requested ban. Use \$blacklist to view them."
  94.   } else {
  95.     puthelp "NOTICE $nickname :Done."
  96.   }
  97. }
  98.  
  99.  
  100. proc blacklist:sentry {{minute "0"} {hour "0"} {day "0"} {week "0"} {year "0"}} {
  101.  global blacklist
  102.   foreach channel [channels] {
  103.     if {![botisop $channel]} {continue}
  104.     foreach target [chanlist $channel] {
  105.       set userhost [blacklist:weirdclean "$target![getchanhost $target]"]
  106.       foreach entry [array names blacklist] {
  107.         set expire [lindex $blacklist($entry) 1]
  108.         if {$expire >= [unixtime] || ($expire == 0)} {
  109.           set reason [lrange [blacklist:clean $blacklist($entry)] 2 end]
  110.           set blackhost [blacklist:weirdclean $entry]
  111.           if {[string match -nocase $blackhost $userhost]} {
  112.             putquick "MODE $channel -o+b $target $entry"
  113.             putquick "KICK $channel $target :[join $reason]"
  114.           }
  115.         } else {
  116.           unset blacklist($entry)
  117.         }
  118.       }
  119.     }
  120.   }
  121.   blacklist:save
  122. }
  123.  
  124. setudef flag blacklist
  125.  
  126. proc blacklist:join {nickname hostname handle channel} {
  127. global blacklist
  128.   if {![botisop $channel] || ![channel get $channel blacklist] } {return}
  129.   set userhost [blacklist:weirdclean "$nickname![getchanhost $nickname]"]
  130.   foreach entry [array names blacklist] {
  131.     set reason [lrange [blacklist:clean $blacklist($entry)] 2 end]
  132.     set blackhost [blacklist:weirdclean $entry]
  133.     if {[string match -nocase $blackhost $userhost]} {
  134.       putquick "MODE $channel -o+b $nickname $entry"
  135.       putquick "KICK $channel $nickname :[join $reason]"
  136.     }
  137.   }
  138. }
  139.  
  140.  
  141. proc blacklist:validate:host {i} {
  142.   regsub -all {\*+} $i {*} i
  143.   array set ban {
  144.     ident *
  145.     host *
  146.   }
  147.   set ban(nick) $i
  148.   if {[regexp -- {!} $i]} {
  149.     regexp -- {^(.+?)!(.*?)(@(.*))?$} $i tmp ban(nick) ban(ident) tmp ban(host)
  150.   } elseif {[regexp -- {@} $i]} {
  151.     regexp -- {^(.+!)?(.*?)(@(.*))?$} $i tmp ban(nick) ban(ident) tmp ban(host)
  152.   }
  153.   foreach item [array names ban] {
  154.     if {[string length $ban($item)] < 1} {
  155.       set ban($item) *
  156.     }
  157.   }
  158.   return $ban(nick)!$ban(ident)@$ban(host)
  159. }
  160.  
  161.  
  162. proc blacklist:load {} {
  163.  global blacklist blacklist_file
  164.   regexp {(\S+/)?} $blacklist_file tmp blacklist_dir
  165.   if {$blacklist_dir != ""} {
  166.     if {![file isdirectory $blacklist_dir]} {
  167.       file mkdir $blacklist_dir
  168.       putlog "Created directory: $blacklist_dir"
  169.     }
  170.   }
  171.   if {![file exists $blacklist_file]} {
  172.     array set blacklist {}
  173.     return
  174.   }
  175.   if {[array exists blacklist]} {
  176.     array unset blacklist
  177.   }
  178.   set file [open $blacklist_file r]
  179.   while {![eof $file]} {
  180.     gets $file line
  181.     if {[regexp -- {(\S+)\s(\S+)\s(\S+)\s(.+)} $line tmp banmask owner expire reason]} {
  182.       if {$expire >= [unixtime] || ($expire == 0)} {
  183.         set blacklist($banmask) "$owner $expire $reason"
  184.       }
  185.     }
  186.   }
  187.   close $file
  188. }
  189.  
  190.  
  191. proc blacklist:save {} {
  192.  global blacklist blacklist_file
  193.   set file "[open $blacklist_file w]"
  194.   foreach entry [array names blacklist] {
  195.     puts $file "$entry $blacklist($entry)"
  196.   }
  197.   close $file
  198. }
  199.  
  200.  
  201. proc blacklist:weirdclean {i} {
  202.   regsub -all -- \\\\ $i \001 i
  203.   regsub -all -- \\\[ $i \002 i
  204.   regsub -all -- \\\] $i \003 i
  205.   regsub -all -- \\\} $i \004 i
  206.   regsub -all -- \\\{ $i \005 i
  207.   return $i
  208. }
  209.  
  210.  
  211. proc blacklist:clean {i} {
  212.   regsub -all -- \\\\ $i \\\\\\\\ i
  213.   regsub -all -- \\\[ $i \\\\\[ i
  214.   regsub -all -- \\\] $i \\\\\] i
  215.   regsub -all -- \\\} $i \\\\\} i
  216.   regsub -all -- \\\{ $i \\\\\{ i
  217.   regsub -all -- \\\" $i \\\\\" i
  218.  return $i
  219. }
  220.  
  221. bind pub o "!blon" blon
  222. proc blon { nick host hand chan arg } {
  223.         set arg [blfilter $arg]
  224.    if {[channel get $chan blacklist] == 0} {
  225.         channel set $chan +blacklist
  226.         putquick "PRIVMSG $chan :Blacklist Activé !"
  227.    } else {
  228.         putquick "PRIVMSG $chan :Blackliste déjà Activé !"
  229.    }
  230. }
  231.  
  232. bind pub o "!bloff" bloff
  233. proc bloff { nick host hand chan arg } {
  234.         set arg [blfilter $arg]
  235.    if {[channel get $chan blacklist] != 0} {
  236.         channel set $chan -blacklist
  237.         putquick "PRIVMSG $chan :Blackliste Désactivé !"
  238.    } else {
  239.         putquick "PRIVMSG $chan :Blackliste déjà Désactivé !"
  240.    }
  241. }
  242.  
  243. proc blfilter {arg} {
  244.    regsub -all -- \\\\ $arg \\\\\\\\ arg
  245.    regsub -all -- \\\[ $arg \\\\\[ arg
  246.    regsub -all -- \\\] $arg \\\\\] arg
  247.    regsub -all -- \\\} $arg \\\\\} arg
  248.    regsub -all -- \\\{ $arg \\\\\{ arg
  249.    regsub -all -- \\\" $arg \\\\\" arg
  250.    return $arg
  251. }
  252.  
  253. blacklist:load
  254.  
  255. putlog "Script loaded: Blacklist :O by perpleXa"
Add Comment
Please, Sign In to add comment