DoctorD90

TextSplitter.tcl 2.6.0

Apr 18th, 2013
3,587
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 6.17 KB | None | 0 0
  1. ### TextSplitter.tcl 2.6.0 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.   if {[info exists ::BotPatchedChk] && $::BotPatchedChk} {
  62.     set lines [bpatched_text $typ $who $what]
  63.   } else {
  64.     set lines [bunpatched_text $typ $who $what]
  65.   }
  66.   foreach line $lines {
  67.     if {[string length $flags]} {
  68.       _putserv "$typ $who :$line" $flags
  69.     } else {
  70.       _putserv "$typ $who :$line"
  71.     }
  72.   }
  73. }
  74.  
  75. proc puthelp {text {flags ""}} {
  76.   set cmd "[lindex [split $text :] 0]:"
  77.   set lcmd [string length $cmd]
  78.   set what [string range $text $lcmd end]
  79.   set typ [lindex [split $cmd] 0]
  80.   set who [lindex [split $cmd] 1]
  81.   if {[info exists ::BotPatchedChk] && $::BotPatchedChk} {
  82.     set lines [bpatched_text $typ $who $what]
  83.   } else {
  84.     set lines [bunpatched_text $typ $who $what]
  85.   }
  86.   foreach line $lines {
  87.     if {[string length $flags]} {
  88.       _puthelp "$typ $who :$line" $flags
  89.     } else {
  90.       _puthelp "$typ $who :$line"
  91.     }
  92.   }
  93. }
  94.  
  95. proc putquick {text {flags ""}} {
  96.   set cmd "[lindex [split $text :] 0]:"
  97.   set lcmd [string length $cmd]
  98.   set what [string range $text $lcmd end]
  99.   set typ [lindex [split $cmd] 0]
  100.   set who [lindex [split $cmd] 1]
  101.   if {[info exists ::BotPatchedChk] && $::BotPatchedChk} {
  102.     set lines [bpatched_text $typ $who $what]
  103.   } else {
  104.     set lines [bunpatched_text $typ $who $what]
  105.   }
  106.   foreach line $lines {
  107.     if {[string length $flags]} {
  108.       _putquick "$typ $who :$line" $flags
  109.     } else {
  110.       _putquick "$typ $who :$line"
  111.     }
  112.   }
  113. }
  114.  
  115. proc putnow {text {flags ""}} {
  116.   set cmd "[lindex [split $text :] 0]:"
  117.   set lcmd [string length $cmd]
  118.   set what [string range $text $lcmd end]
  119.   set typ [lindex [split $cmd] 0]
  120.   set who [lindex [split $cmd] 1]
  121.   if {[info exists ::BotPatchedChk] && $::BotPatchedChk} {
  122.     set lines [bpatched_text $typ $who $what]
  123.   } else {
  124.     set lines [bunpatched_text $typ $who $what]
  125.   }
  126.   foreach line $lines {
  127.     if {[string length $flags]} {
  128.       _putnow "$typ $who :$line" $flags
  129.     } else {
  130.       _putnow "$typ $who :$line"
  131.     }
  132.   }
  133. }
  134.  
  135. proc bpatched_text {typ who what} {
  136.   if {![string match "\001ACTION *\001" $what]} {
  137.     set what [string range $what 12 end-5]
  138.     set ac 1
  139.   } else {
  140.     set ac 16
  141.   }
  142.   set max [expr {$::textsplitter(netmaxchar) - [string bytelength $type] - [string bytelength $who] - 5 - $ac + 1}]
  143.   if {[string bytelength $what] <= $max} {
  144.     lappend msg $what
  145.   } else {
  146.     while {[string bytelength $what] != "0"} {
  147.       set a 0
  148.       set b 0
  149.       while {[string bytelength [string range $what 0 $a]] < $max && $a <= [string length $what]} {
  150.         if {![string length [string trim [string index $what $a]]]} {
  151.           set b $a
  152.         }
  153.         incr a
  154.       }
  155.       if {[string length [string trim [string index $what $a]]] && [string length [string trim [string index $what [expr {$a + 1}]]]] && [llength [split $what]] > "1"} {
  156.         set a $b
  157.       }
  158.       if {[string length [string trim [string range $what 0 $a]]]} {
  159.         if {$ac} {
  160.           lappend msg [string trim [string range $what 0 $a]]
  161.         } else {
  162.           lappend msg \001ACTION [string trim [string range $what 0 $a]]\001
  163.         }
  164.       }
  165.       set what [string range $what [expr {$a + 1}] end]
  166.     }
  167.   }
  168.   return $msg
  169. }
  170.  
  171. proc bunpatched_text {typ who what} {
  172.   if {![string match "\001ACTION *\001" $what]} {
  173.     set what [string range $what 12 end-5]
  174.     set ac 1
  175.   } else {
  176.     set ac 16
  177.   }
  178.   set max [expr {$::textsplitter(netmaxchar) - [string length $typ] - [string length $who] - 5 - $ac + 1}]
  179.   if {[string length $what] <= $max} {
  180.     lappend msg $what
  181.   } else {
  182.     while {[string length $what] != "0"} {
  183.       set a 0
  184.       set b 0
  185.       while {[string length [string range $what 0 $a]] < $max && $a <= [string length $what]} {
  186.         if {![string length [string trim [string index $what $a]]]} {
  187.           set b $a
  188.         }
  189.         incr a
  190.       }
  191.       if {[string length [string trim [string index $what $a]]] && [string length [string trim [string index $what [expr {$a + 1}]]]] && [llength [split $what]] > "1"} {
  192.         set a $b
  193.       }
  194.       if {[string length [string trim [string range $what 0 $a]]]} {
  195.         if {$ac} {
  196.           lappend msg [string trim [string range $what 0 $a]]
  197.         } else {
  198.           lappend msg \001ACTION [string trim [string range $what 0 $a]]\001
  199.         }
  200.       }
  201.       set what [string range $what [expr {$a + 1}] end]
  202.     }
  203.   }
  204.   return $msg
  205. }
  206.  
  207. ###
  208. putlog "TextSplitter.tcl LOADED"
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment