putils.tcl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. # putils
  2. namespace eval ::putils {
  3. ## some internal variables for messaging and stuff :) not your business after all.
  4. set local_ver "0.3"
  5. # if putils-variable (thus, putils!) is already loaded, then .. well .. load again, but, this time, quietly. ;-)
  6. if {![info exists putils]} {
  7. set putils(version) $local_ver
  8. putlog "::putils:: paul's utils for eggdrop bots in tcl - $putils(version) - loading..."
  9. }
  10. # set again .. perhaps we changed version while in development ;) - even while putils was already loaded.
  11. set putils(version) $local_ver
  12. }
  13. ### this "library" supplies the following procedures:
  14. # gets botnick, truncates it and lowercases it. If input-value of a botnick was
  15. # already correct, then it won't change anything. ;)
  16. proc ::putils::proper_botnick {botnick} {
  17. set temp [string tolower $botnick]
  18. # abfrage ob zu lang, dann fixen
  19. # putlog "::putils:: $botnick lowercase: $temp"
  20. if {[string length $botnick] > 9} {
  21. set temp [string range $temp 0 8 ]
  22. # putlog "::putils:: botnickname $botnick too long: capping to: $temp"
  23. }
  24. return $temp
  25. }
  26. proc ::putils::proper_channelname {channelname} {
  27. # channel names ARE NOT and SHOULD NOT BE CASE SENSITIVE!
  28. set temp [string tolower $channelname]
  29. set temp [::putils::umlauts $temp]
  30. # putlog "::putils:: $channelname lowercase: $temp"
  31. return $temp
  32. }
  33. # puts out a normal channel message.
  34. proc ::putils::put_local_msg {chan text} {
  35. putserv "PRIVMSG $chan :$text"
  36. putlog "::putils:: + normal message: ${chan} => '$text'"
  37. }
  38. # puts a NOTICE to a specified nickname with a specified message.
  39. proc ::putils::put_nick {nick msg} {
  40. putserv "NOTICE $nick :$msg"
  41. }
  42. proc ::putils::kill_spaces {text} {
  43. regsub -all "\\s+" $text "" text
  44. return $text
  45. }
  46. # cleans the input text from all irc control codes... and even has
  47. # some spam-protection.
  48. proc ::putils::clean_txt {text} {
  49. #putlog "filter_A: ${text}"
  50. #regsub -all "\\" $text "\\\\" text
  51. # fixes many whitespace between words down to one space between words
  52. regsub -all "\\s+" $text " " text
  53. # filtering out all colorcodes (works well)
  54. regsub -all "\003\[0-9\]\{1,2\},\[0-9\]\{1,2\}" $text "" text
  55. regsub -all "\003\[0-9\]\{1,2\}" $text "" text
  56. regsub -all "\003" $text "" text
  57. # filtering out BOLD text
  58. regsub -all "\002" $text "" text
  59. # underline gets filtered too. (since +c on quakenet would suppress it ...)
  60. regsub -all "\037" $text "" text
  61. # replacing like !!!!!!!!!!!!! with !!!!! (5 letters)
  62. # s/(.?)\1{4,}/\1\1\1\1\1/g;
  63. # - max 5 same chars in a row
  64. regsub -all -nocase -expanded {(.)\1\1\1\1+} $text {\1\1\1\1\1} text
  65. #putlog "test: $text"
  66. set text [string trim $text]
  67. # putlog "filter_B: ${text}"
  68. return $text
  69. }
  70. # replace found umlauts with umlauts.. funny, eh? We have to do this to channel names with
  71. # umlauts, because of some encoding problem inside eggdrop.
  72. # Afterwards, you can check for channelnames - without errors.
  73. proc ::putils::umlauts {text} {
  74. # A REAL STRANGE BUG WORKAROUND WITH UMLAUTS
  75. regsub -all "Ä" ${text} "Ä" text
  76. regsub -all "Ü" ${text} "Ü" text
  77. regsub -all "Ö" ${text} "Ö" text
  78. regsub -all "ä" ${text} "ä" text
  79. regsub -all "ü" ${text} "ü" text
  80. regsub -all "ö" ${text} "ö" text
  81. return ${text}
  82. }
  83. # safe "bot-knows-the-channel-and-is-in-there"-function, returns boolean
  84. proc ::putils::botonchannel {chan} {
  85. if {[validchan $chan] == 1 && [botonchan $chan] == 1} {
  86. return 1
  87. } else {
  88. return 0
  89. }
  90. }
  91. proc ::putils::write_f_array {file thearraylist} {
  92. array set myinternalarray $thearraylist
  93. set array_string [array get myinternalarray]
  94. set fh [open "$file" "w"]
  95. puts $fh $array_string
  96. close $fh
  97. }
  98. proc ::putils::read_f_array {file} {
  99. set fh [open "$file" "r"]
  100. array set myinternalarray [gets $fh]
  101. close $fh
  102. return [array get myinternalarray]
  103. }
  104. return 1