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