putils.tcl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # putils
  2. namespace eval ::putils {
  3. ## some internal variables for messaging and stuff :) not your business after all.
  4. set putils(version) "0.3"
  5. putlog "::putils:: paul utils for eggdrop bots in tcl $putils(version) loading..."
  6. }
  7. # gets botnick, truncates it and lowercases it.
  8. proc ::putils::proper_botnick {botnick} {
  9. set temp [string tolower $botnick]
  10. # abfrage ob zu lang, dann fixen
  11. # putlog "::putils:: $botnick lowercase: $temp"
  12. if {[string length $botnick] > 9} {
  13. set temp [string range $temp 0 8 ]
  14. # putlog "::putils:: botnickname $botnick too long: capping to: $temp"
  15. }
  16. return $temp
  17. }
  18. proc ::putils::proper_channelname {channelname} {
  19. # channel names ARE NOT and SHOULD NOT BE CASE SENSITIVE!
  20. set temp [string tolower $channelname]
  21. set temp [::putils::umlauts $temp]
  22. # putlog "::putils:: $channelname lowercase: $temp"
  23. return $temp
  24. }
  25. proc ::putils::put_local_msg {chan text} {
  26. variable mnet_colors
  27. variable mnet_freqs_onoff
  28. putserv "PRIVMSG $chan :$text"
  29. putlog "::putils:: + normal message: ${chan} => '$text'"
  30. }
  31. proc ::putils::kill_spaces {text} {
  32. regsub -all "\\s+" $text "" text
  33. return $text
  34. }
  35. proc ::putils::clean_txt {text} {
  36. #putlog "filter_A: ${text}"
  37. #regsub -all "\\" $text "\\\\" text
  38. # fixes many whitespace between words down to one space between words
  39. regsub -all "\\s+" $text " " text
  40. # filtering out all colorcodes (works well)
  41. regsub -all "\003\[0-9\]\{1,2\},\[0-9\]\{1,2\}" $text "" text
  42. regsub -all "\003\[0-9\]\{1,2\}" $text "" text
  43. regsub -all "\003" $text "" text
  44. # filtering out BOLD text
  45. regsub -all "\002" $text "" text
  46. # underline gets filtered too. (since +c on quakenet would suppress it ...)
  47. regsub -all "\037" $text "" text
  48. # replacing like !!!!!!!!!!!!! with !!!!! (5 letters)
  49. # s/(.?)\1{4,}/\1\1\1\1\1/g;
  50. # - max 5 same chars in a row
  51. regsub -all -nocase -expanded {(.)\1\1\1\1+} $text {\1\1\1\1\1} text
  52. #putlog "test: $text"
  53. set text [string trim $text]
  54. # putlog "filter_B: ${text}"
  55. return $text
  56. }
  57. proc ::putils::umlauts {text} {
  58. # A REAL STRANGE BUG WORKAROUND WITH UMLAUTS
  59. regsub -all "Ä" ${text} "Ä" text
  60. regsub -all "Ü" ${text} "Ü" text
  61. regsub -all "Ö" ${text} "Ö" text
  62. regsub -all "ä" ${text} "ä" text
  63. regsub -all "ü" ${text} "ü" text
  64. regsub -all "ö" ${text} "ö" text
  65. return ${text}
  66. }
  67. # safe "bot-knows-the-channel-and-is-in-there"-function
  68. proc ::putils::botonchannel {chan} {
  69. if {[validchan $chan] == 1 && [botonchan $chan] == 1} {
  70. return 1
  71. } else {
  72. return 0
  73. }
  74. }