# putils namespace eval ::putils { ## some internal variables for messaging and stuff :) not your business after all. # if putils-variable (thus, putils!) is already loaded, then .. well .. load again, but, this time, quietly. ;-) if {![info exists putils]} { putlog "::putils:: paul utils for eggdrop bots in tcl $putils(version) loading..." } # set again .. perhaps we changed version while in development ;) - even while putils was already loaded. set putils(version) "0.3" } ### this "library" supplies the following procedures: # gets botnick, truncates it and lowercases it. If input-value of a botnick was # already correct, then it won't change anything. ;) proc ::putils::proper_botnick {botnick} { set temp [string tolower $botnick] # abfrage ob zu lang, dann fixen # putlog "::putils:: $botnick lowercase: $temp" if {[string length $botnick] > 9} { set temp [string range $temp 0 8 ] # putlog "::putils:: botnickname $botnick too long: capping to: $temp" } return $temp } proc ::putils::proper_channelname {channelname} { # channel names ARE NOT and SHOULD NOT BE CASE SENSITIVE! set temp [string tolower $channelname] set temp [::putils::umlauts $temp] # putlog "::putils:: $channelname lowercase: $temp" return $temp } # puts out a normal channel message. proc ::putils::put_local_msg {chan text} { putserv "PRIVMSG $chan :$text" putlog "::putils:: + normal message: ${chan} => '$text'" } # puts a NOTICE to a specified nickname with a specified message. proc ::putils::put_nick {nick msg} { putserv "NOTICE $nick :$msg" } proc ::putils::kill_spaces {text} { regsub -all "\\s+" $text "" text return $text } # cleans the input text from all irc control codes... and even has # some spam-protection. proc ::putils::clean_txt {text} { #putlog "filter_A: ${text}" #regsub -all "\\" $text "\\\\" text # fixes many whitespace between words down to one space between words regsub -all "\\s+" $text " " text # filtering out all colorcodes (works well) regsub -all "\003\[0-9\]\{1,2\},\[0-9\]\{1,2\}" $text "" text regsub -all "\003\[0-9\]\{1,2\}" $text "" text regsub -all "\003" $text "" text # filtering out BOLD text regsub -all "\002" $text "" text # underline gets filtered too. (since +c on quakenet would suppress it ...) regsub -all "\037" $text "" text # replacing like !!!!!!!!!!!!! with !!!!! (5 letters) # s/(.?)\1{4,}/\1\1\1\1\1/g; # - max 5 same chars in a row regsub -all -nocase -expanded {(.)\1\1\1\1+} $text {\1\1\1\1\1} text #putlog "test: $text" set text [string trim $text] # putlog "filter_B: ${text}" return $text } # replace found umlauts with umlauts.. funny, eh? We have to do this to channel names with # umlauts, because of some encoding problem inside eggdrop. # Afterwards, you can check for channelnames - without errors. proc ::putils::umlauts {text} { # A REAL STRANGE BUG WORKAROUND WITH UMLAUTS regsub -all "Ä" ${text} "Ä" text regsub -all "Ü" ${text} "Ü" text regsub -all "Ö" ${text} "Ö" text regsub -all "ä" ${text} "ä" text regsub -all "ü" ${text} "ü" text regsub -all "ö" ${text} "ö" text return ${text} } # safe "bot-knows-the-channel-and-is-in-there"-function, returns boolean proc ::putils::botonchannel {chan} { if {[validchan $chan] == 1 && [botonchan $chan] == 1} { return 1 } else { return 0 } } return 1