DoctorD90

TCLLoader.tcl 2.0.0

Apr 23rd, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### TCLLoader.tcl 2.0.0 smApj15u
  2.  
  3. #SUGGESTED
  4. # PBinSrc.tcl fMrtKqyq
  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: DoctorD90
  26. #Network: irc.OnlineGamesNet.net
  27. #Chan: #eHito
  28.  
  29. #PURPOSE
  30. #Do not make crash bot if has been founded an error in a script and automatize adding scripts without editing anything more, but using 3 easy commands.
  31.  
  32. #USAGE
  33. #Paste this script in your own eggdrop's scripts folder;
  34. #write at the end of eggdrop's config 'source path/to/scripts/folder/TCLLoader.tcl'
  35. #Then to manage scripts, paste scripts in your own eggdrop's scripts folder and
  36. #use commands setted in SETTINGS section.
  37. #Do not need more to append scripts at the end of your eggdrop's config file.
  38.  
  39. #SETTINGS
  40. #Set path where scripts will be stored.
  41. set tclldr(dir) "scripts/"
  42. #Set query command to add scripts.
  43. set tclldr(add) ".Scr+"
  44. #Set query command to list scripts.
  45. set tclldr(see) ".Scr"
  46. #Set query command to del scripts.
  47. set tclldr(del) ".Scr-"
  48. #Set query command to un/comment scripts.
  49. set tclldr(com) ".Scr#"
  50.  
  51.  
  52. ### DON'T EDIT ANYTHING BELOW ###
  53.  
  54. bind msg n $tclldr(add) msg_scradd
  55. proc msg_scradd {nick uhost hand text} {
  56.   set text [split $text]
  57.   if {![llength $text]} {
  58.     putserv "PRIVMSG $nick :\002AddScript:\002 Script's Name Required."
  59.     return
  60.   }
  61.   set tclscr [lindex $text 0]
  62.   if {![file exists "${::tclldr(dir)}$tclscr"]} {
  63.     putserv "PRIVMSG $nick :\002AddScript:\002 $tclscr Not Found In $::tclldr(dir) Folder."
  64.     return
  65.   }
  66.   if {![file exists "${::tclldr(dir)}SCRIPTS.DAT"]} {
  67.     set fs [open "${::tclldr(dir)}SCRIPTS.DAT" w]
  68.   } else {
  69.     set fs [open "${::tclldr(dir)}SCRIPTS.DAT" a]
  70.   }
  71.   puts $fs "$tclscr"
  72.   close $fs
  73.   privmsg $nick "\002$tclscr\002 Successfully Added."
  74.   putserv "PRIVMSG $nick :Rehashing..."
  75.   rehash
  76. }
  77.  
  78. bind msg n $tclldr(see) msg_scrsee
  79. proc msg_scrsee {nick uhost hand text} {
  80.   if {[file exists "${::tclldr(dir)}SCRIPTS.DAT"]} {
  81.     set lines [tclldr_get "${::tclldr(dir)}SCRIPTS.DAT"]
  82.   }
  83.   if {![info exists lines] || ![string length [string trim [join $lines]]]} {
  84.     set lines [list "\002Scripts:\002 No Script Listed."]
  85.   }
  86.   set n 0
  87.   foreach line $lines {
  88.     if {[string length [string trim $line]]} {
  89.       set line "-Empty-"
  90.     }
  91.     putserv "PRIVMSG $nick :$n) $line"
  92.     incr n
  93.   }
  94.   putserv "PRIVMSG $nick :*End*"
  95. }
  96.  
  97. bind msg n $tclldr(del) msg_scrdel
  98. proc msg_scrdel {nick uhost hand text} {
  99.   set text [split $text]
  100.   if {![llength $text]} {
  101.     putserv "PRIVMSG $nick :\002DelScript:\002 Script's Name or Line's Number Required."
  102.     return
  103.   }
  104.   set tclscr [lindex $text 0]
  105.   if {[file exists "${::tclldr(dir)}SCRIPTS.DAT"]} {
  106.     set lines [tclldr_get "${::tclldr(dir)}SCRIPTS.DAT"]
  107.   }
  108.   if {![info exists lines] || ![string length [string trim [join $lines]]]} {
  109.     putserv "PRIVMSG $nick :\002DelScripts:\002 No Script Listed."
  110.     return
  111.   }
  112.   set d [tclldr_search $tclscr $lines]
  113.   if {$d == "-1"} {
  114.     putserv "PRIVMSG $nick :\002DelScript:\002 No Script Founds In List."
  115.     return
  116.   }
  117.   tclldr_del [split $d] $lines
  118.   if {[string is integer -strict $tclscr]} {
  119.     set tclscr "Line \002$tclscr\002"
  120.   } else {
  121.     set tclscr "\002$tclscr\002"
  122.   }
  123.   privmsg $nick "$tclscr Erased."
  124.   privmsg $nick "Restarting..."
  125.   restart
  126. }
  127.  
  128. bind msg n $tclldr(com) msg_scrcom
  129. proc msg_scrcom {nick uhost hand text} {
  130.   set text [split $text]
  131.   if {![llength $text]} {
  132.     putserv "PRIVMSG $nick :\002DelScript:\002 Script's Name or Line's Number Required."
  133.     return
  134.   }
  135.   set tclscr [lindex $text 0]
  136.   if {[file exists "${::tclldr(dir)}SCRIPTS.DAT"]} {
  137.     set lines [tclldr_get "${::tclldr(dir)}SCRIPTS.DAT"]
  138.   }
  139.   if {![info exists lines] || ![string length [string trim [join $lines]]]} {
  140.     putserv "PRIVMSG $nick :\002DelScripts:\002 No Script Listed."
  141.     return
  142.   }
  143.   set c [tclldr_search $tclscr $lines]
  144.   if {$c == "-1"} {
  145.     putserv "PRIVMSG $nick :\002DelScript:\002 No Script Founds In List."
  146.     return
  147.   }
  148.   set c [split $c]
  149.   set scr [lindex $lines [lindex $c 0]]
  150.   tclldr_del $c $lines
  151.   if {[string index $scr 0] != "#"} {
  152.     set c 0
  153.     set scr "#$scr"
  154.   } else {
  155.     set c 1
  156.     set scr [string range $scr 1 end]
  157.   }
  158.   set fs [open "${::tclldr(dir)}SCRIPTS.DAT" a]
  159.   puts $fs $scr
  160.   close $fs
  161.   if {$c} {
  162.     putserv "PRIVMSG $nick :\002$scr\002 UnComment."
  163.     putserv "PRIVMSG $nick :Rehashing..."
  164.     rehash
  165.   } else {
  166.     putserv "PRIVMSG $nick :\002$scr\002 Comment."
  167.     putserv "PRIVMSG $nick :Restarting..."
  168.     restart
  169.   }
  170. }
  171.  
  172. proc tclldr_get {file} {
  173.   set fs [open "$file"]
  174.   set lines [split [read -nonewline $fs] "\n"]
  175.   close $fs
  176.   return $lines
  177. }
  178.  
  179. proc tclldr_search {text lines} {
  180.   if {![string is integer -strict $text]} {
  181.     set s [lsearch -all $lines "*$text"]
  182.   } else {
  183.     if {$text >= "0"} {
  184.       set s $text
  185.     } else {
  186.       set s "-1"
  187.     }
  188.     if {$text >= [llength $lines]} {
  189.       set s end
  190.     }
  191.   }
  192.   return $s
  193. }
  194.  
  195. proc tclldr_del {d lines} {
  196.   set a 0
  197.   foreach l $d {
  198.     set n [expr {$l - $a}]
  199.     set lines [lreplace $lines $n $n]
  200.     incr a
  201.   }
  202.   set fs [open "${::tclldr(dir)}SCRIPTS.DAT" w]
  203.   puts $fs [join $lines "\n"]
  204.   close $fs
  205. }
  206.  
  207. proc nown { } {
  208.   if {[handonchan $::owner]} {
  209.     set o [hand2nick $::owner]
  210.   } else {
  211.     set o $::owner
  212.   }
  213.   return $o
  214. }
  215.  
  216.   if {![file exists "${::tclldr(dir)}SCRIPTS.DAT"]} {
  217.     set tclfs [open "${::tclldr(dir)}SCRIPTS.DAT" w]
  218.     close $tclfs
  219.     unset tclfs
  220.     putlog "SCRIPTS.DAT  Created."
  221.     putserv "NOTICE [nown] :SCRIPTS.DAT  Created."
  222.   } else {
  223.     set tcllines [tclldr_get "${::tclldr(dir)}SCRIPTS.DAT"]
  224.     set l 0
  225.     if {[llength $lines]} {
  226.       foreach tclscr $tcllines {
  227.         if {[string length $tclscr] && [string index $tclscr 0] != "#"} {
  228.           if {[catch {source ${::tclldr(dir)}$tclscr} tclerr]} {
  229.             putlog "TCLError in ($l) $tclscr"
  230.             putserv "PRIVMSG [own] :TCLError in ($l) \002$tclscr\002"
  231.             foreach err [split $tclerr "\n"] {
  232.               putlog "$err"
  233.               putserv "PRIVMSG [own] :$err"
  234.             }
  235.             unset tclerr
  236.           } else {
  237.             putlog "$tclscr Successfully LOADED"
  238.           }
  239.         }
  240.         incr l
  241.       }
  242.     }
  243.     unset tcllines
  244.     putlog "***ALL SCRIPTS LOADED***"
  245.     putserv "NOTICE [own] :***ALL SCRIPTS LOADED***"
  246.   }
  247.  
  248. ###
  249. putlog "TCLLoader.tcl LOADED"
Advertisement
Add Comment
Please, Sign In to add comment