User:Mike5904/botsrc

bind pubm - *#meta.wikimedia* grabrcmeta proc grabrcmeta { nick host hand chan torc } { set msgts "$torc" set msgts [mirc_strip -color -- $msgts] if {[regexp {Special\:Log} $msgts]} { return 0 }	regexp {\* (.+) \*} $msgts - username regexp {\[\[(.+?)\]\]} $msgts - artname if {[regexp {(.*)\]\]} $artname]} { regexp {(.*)\]\]} $artname - artname }	if {[regexp {(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})} $username]} { set utype "IP" } else { set utype "User" }	regexp {(http:\/\/[\w\.\/\?\=\&\:\-]+)} $msgts - diff regexp {\((..{0,9})\)} $msgts - cbytes regexp {\(..{0,9}\) (.*)} $msgts - esummary if {$cbytes > 0} { set vtype "Gibberish" if {[regexp {.*]] N http.*} $msgts ]} { set ptype "NEW"} else { set ptype "OLD" } } 	if {$cbytes < 0} { set vtype "Blanking" if {[regexp {.*]] N http.*} $msgts ]} { set ptype "NEW"} else { set ptype "OLD" } }	regexp {([0-9]{1,6})} $cbytes - cbytes set artname "\[\[m:$artname\]\]" regsub -all -- " " $artname "_" artname regsub -all -- " " $esummary "_" esummary set msgts2 "$artname $cbytes $diff $vtype $username $utype $ptype $esummary" if {$cbytes > 700} { dccbroadcast $msgts2 set msgts3 "Vandal $msgts2" putbot "MetaRC-Wa" $msgts3 }	if {$ptype == "NEW"} { if {$utype == "IP"} { if {$cbytes < 300} { set msgts4 "TinyIP $msgts2" putbot "MetaRC-Wa" $msgts4 }		}	}	if {$ptype == "NEW"} { if {$utype == "IP"} { if {$cbytes > 3000} { set msgts4 "LargeIP $msgts2" putbot "MetaRC-Wa" $msgts4 }		}	} }

proc unlist { badargs $args 1 end "argsList ?varName varName ...?" set argList [lindex $args 0] set argList [expr {([catch {llength $argList}])?[split $argList]:$argList}] set argNames [lrange $args 1 end] if {![llength $argNames]} { return [expr {(![catch {llength $argList}])? [join $argList]:$argList}] } for {set index 0} {$index < [llength $argNames]} {incr index 1} { set argName    [lindex $argNames $index] set argListItem [lindex $argList $index]

set argName_ [expr {([catch {llength $argName}])?[split $argName]:$argName}] set setTo  [lindex $argName_ 1] set argName [lindex $argName_ 0]

if {$argName == ""} {continue}

upvar 1 $argName var

if {[expr $index+1] > [llength $argList]} { if {[llength $argName_] == "2"} {set var $setTo} } else { if {$argName == "args"} { set var [lrange $argList $index end] incr index [expr [llength $var]-1] } else {set var $argListItem} } }; return $index }

proc 2list { badargs $args 1 1 "text" unlist $args text

return [expr {([catch {llength $text}])?[split $text]:$text}] }

proc replace { badargs $args 2 4 "?switches? text substitutions" set switches "" for {set i 0} {[string match -* [set arg [lindex $args $i]]]} {incr i} { if {![regexp -- {^-(nocase|-)$} $arg -> switch]} { error "bad switch \"$arg\": must be -nocase, or --" }   if {$switch == "-"} { incr i     break }; lappend switches $switch } set nocase [expr {([lsearch -exact $switches "nocase"] >= "0") ? 1 : 0}] set text [lindex $args $i] set substitutions [lindex $args [expr $i+1]] badargs [lrange $args $i end] 2 2 "?switches? text substitutions"

set substitutions [2list $substitutions]

if {[info tclversion] >= "8.1"} { return [expr {($nocase)? [string map -nocase $substitutions $text]: [string map $substitutions $text]}] }

set re_syntax {([][\\\*\+\?\{\}\,\(\)\:\.\^\$\=\!\|])} foreach {a b} $substitutions { regsub -all -- $re_syntax $a {\\\1} a   if {$nocase} {regsub -all -nocase -- $a $text $b text} \ else {regsub -all -- $a $text $b text} }; return $text }

proc badargs { if {[llength $args] < 4} { error { wrong # args: should be "badargs args min_llength max_llength argNames" } }

set index 0 foreach varName [list args min max names] { set check_$varName [lindex $args $index] incr index }

if {[regexp -- {([^0-9])} $check_min -> bad]} { error "bad number \"$bad\" in: $check_min" } if {[regexp -- {([^0-9])} $check_max -> bad] && ($check_max != "end")} { error "bad number \"$bad\" in: $check_max" }

if {[catch {llength $check_args} llength]} { set check_args [split $check_args] set llength $check_args }

if {($llength < $check_min) || (($llength != "end") &&     ($llength > $check_max))} { if {[info level] == "1"} {return 1} error "wrong # args: should be \"[lindex [info level -1] 0] $check_names\"" }; return 0 }

proc mirc_strip { badargs $args 1 7 "?switches? text" set switches "" for {set i 0} {[string match -* [set arg [lindex $args $i]]]} {incr i} { if {![regexp -- {^-(all|bold|color|reverse|underline|-)$} $arg -> switch]} { set valid "-all -bold -color -reverse -underline {or --}" error "bad switch \"$arg\": must be [join $valid ", "]" }   if {$switch == "-"} { incr i     break }; lappend switches $switch } if {$switches == ""} {set switches all} set arg [lindex $args $i] badargs [lrange $args $i end] 1 1 "?switches? text"

set all [expr {([lsearch -exact $switches all] >= 0) ? 1 : 0}] set list "" if {$all} { set list [list \002 "" \017 "" \026 "" \037 ""] } else { if {[lsearch -exact $switches bold] >= 0} {lappend list [list \002 ""]} if {[lsearch -exact $switches plain] >= 0} {lappend list [list \017 ""]} if {[lsearch -exact $switches reverse] >= 0} {lappend list [list \026 ""]} if {[lsearch -exact $switches underline] >= 0} {lappend list [list \037 ""]} } if {$all || ([lsearch -exact $switches color] >= 0)} { regsub -all -- "\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?" $arg "" arg } set arg [replace -- $arg [join $list]]

return $arg }