DoctorD90

TextSplitter.tcl 2.5.1

Apr 17th, 2013
335
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### TextSplitter.tcl 2.5.1 fpx1Gx1Z
  2.  
  3. #REQUIREMENTS
  4. # PatchChk.tcl Y5aZfqpT
  5.  
  6. #LICENSE
  7. # Copyright © 2013 Alberto Dietze "DoctorD90"
  8. #
  9. #    This program is free software: you can redistribute it and/or modify
  10. #    it under the terms of the GNU General Public License as published by
  11. #    the Free Software Foundation, either version 3 of the License, or
  12. #    (at your option) any later version.
  13. #
  14. #    This program is distributed in the hope that it will be useful,
  15. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #    GNU General Public License for more details.
  18. #
  19. #    You should have received a copy of the GNU General Public License
  20. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Full GPLv3 Text: http://www.gnu.org/licenses/gpl.txt
  23.  
  24. #PATERNITY
  25. #Coder or Developer?: DoctorD90
  26. #Network: irc.OnlineGamesNet.net
  27. #Chan: #eHito
  28. #
  29. #Thanks to guys on #egghelp on irc.freenode.net
  30. #Special thanks to Speechles
  31.  
  32. #PURPOSE
  33. #This script splits messages sended to irc server
  34. #in lines if it is over max chars network length
  35.  
  36. #USAGE
  37. #To send message to server, use command
  38. #notice Target stringMessage speedqueque
  39. #or
  40. #privmsg Target stringMessage speedqueque
  41. #or
  42. #actmsg Target stringMessage speedqueque
  43. # 'speedqueque' is optional. If it isn't setted,
  44. #it will use default value setted in SETTINGS section.
  45.  
  46. #SETTINGS
  47. #Set your own Max Char Network Length
  48. set textsplitter(netmaxchar) 512
  49.  
  50. #Set your default queque speed messages.
  51. #1 putserv
  52. #2 puthelp
  53. #3 putquick
  54. #4 putnow
  55. set textsplitter(speedqueque) 1
  56.  
  57.  
  58. ### DON'T EDIT ANYTHING BELOW ###
  59.  
  60. proc notice {who what {speed{$::textsplitter(speedqueque)}}} {
  61.   if {[info exists ::BotPatchedChk] && $::BotPatchedChk} {
  62.     set lines [bpatched_text $who 0 $what]
  63.   } else {
  64.     set lines [bunpatched_text $who 0 $what]
  65.   }
  66.   foreach line $lines {
  67.     set text "NOTICE $who :$line"
  68.     switch -glob -- $speed {
  69.       "2" {
  70.         puthelp $text
  71.       }
  72.       "3" {
  73.         putquick $text
  74.       }
  75.       "4" {
  76.         putnow $text
  77.       }
  78.       "default" {
  79.         putserv $text
  80.       }
  81.     }
  82.   }
  83. }
  84.  
  85. proc privmsg {who what {speed{$::textsplitter(speedqueque)}}} {
  86.   if {[info exists ::BotPatchedChk] && $::BotPatchedChk} {
  87.     set lines [bpatched_text $who 1 $what]
  88.   } else {
  89.     set lines [bunpatched_text $who 1 $what]
  90.   }
  91.   foreach line $lines {
  92.     set text "PRIVMSG $who :$line"
  93.     switch -glob -- $speed {
  94.       "2" {
  95.         puthelp $text
  96.       }
  97.       "3" {
  98.         putquick $text
  99.       }
  100.       "4" {
  101.         putnow $text
  102.       }
  103.       "default" {
  104.         putserv $text
  105.       }
  106.     }
  107.   }
  108. }
  109.  
  110. proc actmsg {who what {speed{$::textsplitter(speedqueque)}}} {
  111.   if {[info exists ::BotPatchedChk] && $::BotPatchedChk} {
  112.     set lines [bpatched_text $who 16 $what]
  113.   } else {
  114.     set lines [bunpatched_text $who 16 $what]
  115.   }
  116.   foreach line $lines {
  117.     set text "PRIVMSG $who :\001ACTION $line\001"
  118.     switch -glob -- $speed {
  119.       "2" {
  120.         puthelp $text
  121.       }
  122.       "3" {
  123.         putquick $text
  124.       }
  125.       "4" {
  126.         putnow $text
  127.       }
  128.       "default" {
  129.         putserv $text
  130.       }
  131.     }
  132.   }
  133. }
  134.  
  135. proc bpatched_text {who typ what} {
  136.   set max [expr {$::textsplitter(netmaxchar) - 7 - $typ - [string bytelength $who] - 2 - 2}]
  137.   if {[string bytelength $what] <= $max} {
  138.     lappend msg $what
  139.   } else {
  140.     while {[string bytelength $what] != "0"} {
  141.       set a 0
  142.       set b 0
  143.       while {[string bytelength [string range $what 0 $a]] < $max && $a <= [string length $what]} {
  144.         if {![string length [string trim [string index $what $a]]]} {
  145.           set b $a
  146.         }
  147.         incr a
  148.       }
  149.       if {[string length [string trim [string index $what $a]]] && [string length [string trim [string index $what [expr {$a + 1}]]]] && [llength [split $what]] > "1"} {
  150.         set a $b
  151.       }
  152.       if {[string length [string trim [string range $what 0 $a]]]} {
  153.         lappend msg [string trim [string range $what 0 $a]]
  154.        }
  155.        set what [string range $what [expr {$a + 1}] end]
  156.     }
  157.   }
  158.   return $msg
  159. }
  160.  
  161. proc bunpatched_text {who typ what} {
  162.   set ::textsplitter(netmaxchar) 512
  163.   set max [expr {$::textsplitter(netmaxchar) - 7 - $typ - [string length $who] - 2 - 2}]
  164.   if {[string length $what] <= $max} {
  165.     lappend msg $what
  166.   } else {
  167.     while {[string length $what] != "0"} {
  168.       set a 0
  169.       set b 0
  170.       while {[string length [string range $what 0 $a]] < $max && $a <= [string length $what]} {
  171.         if {![string length [string trim [string index $what $a]]]} {
  172.           set b $a
  173.         }
  174.         incr a
  175.       }
  176.       if {[string length [string trim [string index $what $a]]] && [string length [string trim [string index $what [expr {$a + 1}]]]] && [llength [split $what]] > "1"} {
  177.         set a $b
  178.       }
  179.      if {[string length [string trim [string range $what 0 $a]]]} {
  180.         lappend msg [string trim [string range $what 0 $a]]
  181.      }
  182.       set what [string range $what [expr {$a + 1}] end]
  183.     }
  184.   }
  185.   return $msg
  186. }
  187.  
  188. ###
  189. putlog "TextSplitter.tcl LOADED"
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment