DoctorD90

TextSplitter.tcl 2.6.1

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