123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- # putils
- namespace eval ::putils {
- ## some internal variables for messaging and stuff :) not your business after all.
- set local_ver "0.3"
- # if putils-variable (thus, putils!) is already loaded, then .. well .. load again, but, this time, quietly. ;-)
- if {![info exists putils]} {
- set putils(version) $local_ver
- putlog "::putils:: paul's 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) $local_ver
-
- }
- ### 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
- }
- }
- proc ::putils::write_f_array {file thearraylist} {
- array set myinternalarray $thearraylist
-
- set array_string [array get myinternalarray]
-
- set fh [open "$file" "w"]
- puts $fh $array_string
- close $fh
- }
- proc ::putils::read_f_array {file} {
- set fh [open "$file" "r"]
- array set myinternalarray [gets $fh]
- close $fh
- return [array get myinternalarray]
- }
- return 1
|