[eggheads-patches] PATCH: action_fix_tcl-2.diff alltools_tcl-4.diff botchk-2.diff compat_tcl-2.diff

Tothwolf tothwolf at concentric.net
Thu Oct 21 17:41:58 CST 1999


action_fix_tcl-2.diff:
  renamed procs to standardize more

alltools_tcl-4.diff:
  optimizations and bugfixes

botchk-2.diff:
  userfile checking to avoid 1000s of emails from crontab

compat_tcl-2.diff:
  optimizations

-Toth
-------------- next part --------------
--- ../eggdrop1.3.cvs/scripts/action.fix.tcl	Sun Jun 27 15:37:25 1999
+++ ./scripts/action.fix.tcl	Thu Oct 21 16:53:15 1999
@@ -1,13 +1,14 @@
-# cleanup by Tothwolf 25May1999
+# Tothwolf  25May1999: cleanup
+# Tothwolf  04Oct1999: changed proc names slightly
 
 # fix for mirc dcc chat /me's
-bind filt - "\001ACTION *\001" filt_act
-proc filt_act {idx text} {
+bind filt - "\001ACTION *\001" filt:dcc_action
+proc filt:dcc_action {idx text} {
   return ".me [string trim [join [lrange [split $text] 1 end]] \001]"
 }
 
 # fix for telnet session /me's
-bind filt - "/me *" filt_telnet_act
-proc filt_telnet_act {idx text} {
+bind filt - "/me *" filt:telnet_action
+proc filt:telnet_action {idx text} {
   return ".me [join [lrange [split $text] 1 end]]"
 }
-------------- next part --------------
--- ../eggdrop1.3.cvs/scripts/alltools.tcl	Thu Oct  7 08:45:33 1999
+++ ./scripts/alltools.tcl	Thu Oct 21 17:08:09 1999
@@ -1,27 +1,33 @@
 # All-Tools TCL, includes toolbox.tcl, toolkit.tcl and moretools.tcl
-# toolbox is Authored by cmwagner at sodre.net
-# toolkit is Authored by (Someone claim this)[unknown]
-# moretools is Authored by David Sesno(walker at shell.pcrealm.net)
-# modified for 1.3.0 bots by TG
-# rewritten and updated by Tothwolf 02May1999
-# updated even more by guppy 02May1999
-# fixed what guppy broke and updated again by Tothwolf 02May1999
-# more changes from Tothwolf 24/25May1999
-
+# toolbox was authored by cmwagner at sodre.net
+# toolkit was authored by (Someone claim this)[unknown]
+# moretools was authored by David Sesno(walker at shell.pcrealm.net)
+#
+# TG        ?????????: modified for 1.3.0 bots
+# Tothwolf  02May1999: rewritten and updated
+# guppy     02May1999: updated even more
+# Tothwolf  02May1999: fixed what guppy broke and updated again
+# Tothwolf  24/25May1999: more changes
+# rtc       20Sep1999: added isnumber, changes
+# dw        20Sep1999: use regexp for isnumber checking
+# Tothwolf  06Oct1999: optimized
+# Tothwolf  08Oct1999: fixed more bugs
+#
 ########################################
 # Descriptions of avaliable commands:
 ## (toolkit):
 # putmsg <nick/chan> <text>
-#   send a message to a nick/chan
+#   send a privmsg to the given nick or channel
 #
 # putchan <nick/chan> <text>
-#   identical to putmsg
+#   send a privmsg to the given nick or channel
+#   (for compat only, this is the same as 'putmsg' above)
 #
 # putnotc <nick/chan> <text>
-#   send a notice to a nick/chan
+#   send a notice to the given nick or channel
 #
 # putact <nick/chan> <text>
-#   send an action to a nick/chan
+#   send an action to the given nick or channel
 #
 ## (toolbox):
 # strlwr <string>
@@ -48,34 +54,31 @@
 #
 # timerexists <command>
 #   if the given command is scheduled by a timer, return its timer id
-#   else return ""
+#   else return empty string
 #
 # utimerexists <command>
 #   if the given command is scheduled by a utimer, return its utimer id
-#   else return ""
+#   else return empty string
 #
 # inchain <bot>
 #   if the given bot is connected to the botnet, return 1
 #   else return 0
+#   (for compat only, same as 'islinked')
 #
 # randstring <length>
 #   returns a random string of the given length
 #
 # putdccall <text>
 #   send the given text to all dcc users
-#   returns nothing
 #
 # putdccbut <idx> <text>
 #   send the given text to all dcc users except for the given idx
-#   returns nothing
 #
 # killdccall
 #   kill all dcc user connections
-#   returns nothing
 #
 # killdccbut <idx>
 #   kill all dcc user connections except for the given idx
-#   returns nothing
 #
 ## (moretools):
 # iso <nick> <channel>
@@ -85,8 +88,8 @@
 # realtime [format]
 #   'time' returns the current time in 24 hour format '14:15'
 #   'date' returns the current date in the format '21 Dec 1994'
-#   not specifying any format will return the current time with
-#   in 12 hour format '1:15 am'
+#   not specifying any format will return the current time in
+#   12 hour format '1:15 am'
 #
 # testip <ip>
 #   if the given ip is valid, return 1
@@ -94,60 +97,74 @@
 #
 # number_to_number <number>
 #   if the given number is between 1 and 15, return its analog representation
+#   else return the number given
+#
+## (other commands):
+# isnumber <string>
+#   if the given string is a valid number, return 1
+#   else return 0
 #
 ########################################
 
 # So scripts can see if allt is loaded.
 set alltools_loaded 1
-set allt_version 203
+set allt_version 204
 
 # For backward comptibility.
 set toolbox_revision 1007
 set toolbox_loaded 1
 set toolkit_loaded 1
 
-proc putmsg {who text} {
-  puthelp "PRIVMSG $who :$text"
+#
+# toolbox:
+#
+
+proc putmsg {dest text} {
+  puthelp "PRIVMSG $dest :$text"
 }
 
-proc putchan {who text} {
-  puthelp "PRIVMSG $who :$text"
+proc putchan {dest text} {
+  puthelp "PRIVMSG $dest :$text"
 }
 
-proc putnotc {who text} {
-  puthelp "NOTICE $who :$text"
+proc putnotc {dest text} {
+  puthelp "NOTICE $dest :$text"
 }
 
-proc putact {who text} {
-  puthelp "PRIVMSG $who :\001ACTION $text\001"
+proc putact {dest text} {
+  puthelp "PRIVMSG $dest :\001ACTION $text\001"
 }
 
+#
+# toolkit:
+#
+
 proc strlwr {string} {
-  return [string tolower $string]
+  string tolower $string
 }
 
 proc strupr {string} {
-  return [string toupper $string]
+  string toupper $string
 }
 
 proc strcmp {string1 string2} {
-  return [string compare $string1 $string2]
+  string compare $string1 $string2
 }
 
 proc stricmp {string1 string2} {
-  return [string compare [string tolower $string1] [string tolower $string2]]
+  string compare [string tolower $string1] [string tolower $string2]
 }
 
 proc strlen {string} {
-  return [string length $string]
+  string length $string
 }
 
 proc stridx {string index} {
-  return [string index $string $index]
+  string index $string $index
 }
 
 proc iscommand {command} {
-  if {![string match "" [info commands $command]]} then {
+  if {![string compare $command [info commands $command]]} then {
     return 1
   }
   return 0
@@ -155,7 +172,7 @@
 
 proc timerexists {command} {
   foreach i [timers] {
-    if {[string match [lindex $i 1] $command]} then {
+    if {![string compare $command [lindex $i 1]]} then {
       return [lindex $i 2]
     }
   }
@@ -164,7 +181,7 @@
 
 proc utimerexists {command} {
   foreach i [utimers] {
-    if {[string match [lindex $i 1] $command]} then {
+    if {![string compare $command [lindex $i 1]]} then {
       return [lindex $i 2]
     }
   }
@@ -172,101 +189,87 @@
 }
 
 proc inchain {bot} {
-  return [islinked $bot]
+  islinked $bot
 }
 
-proc randstring {length} {
-  set string ""
-  set chars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
+proc randstring {length {chars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789}} {
   set count [string length $chars]
-  for {set i 0} {[expr $i < $length]} {incr i} {
-    append string [string index $chars [rand $count]]
+  for {set i 0} {$i < $length} {incr i} {
+    append result [string index $chars [rand $count]]
   }
-  return $string
 }
 
 proc putdccall {text} {
-  foreach i [dcclist] {
-    set j [lindex $i 0]
-    if {[valididx $j]} then {
-      putdcc $j $text
-    }
+  foreach i [dcclist CHAT] {
+    putdcc [lindex $i 0] $text
   }
-  return
 }
 
 proc putdccbut {idx text} {
-  foreach i [dcclist] {
+  foreach i [dcclist CHAT] {
     set j [lindex $i 0]
-    if {([valididx $j]) && (![string match $j $idx])} then {
+    if {$j != $idx} then {
       putdcc $j $text
     }
   }
-  return
 }
 
 proc killdccall {} {
-  foreach i [dcclist] {
-    set j [lindex $i 0]
-    if {[valididx $j]} then {
-      killdcc $j
-    }
+  foreach i [dcclist CHAT] {
+    killdcc [lindex $i 0]
   }
-  return
 }
 
 proc killdccbut {idx} {
-  foreach i [dcclist] {
+  foreach i [dcclist CHAT] {
     set j [lindex $i 0]
-    if {([valididx $j]) && (![string match $j $idx])} then {
+    if {$j != $idx} then {
       killdcc $j
     }
   }
-  return
 }
 
+#
+# moretools:
+#
+
 proc iso {nick chan} {
-  return [matchattr [nick2hand $nick $chan] o|o $chan]
+  matchattr [nick2hand $nick $chan] o|o $chan
 }
 
 proc realtime {args} {
-  switch -exact [lindex $args 0] {
+  switch -exact -- $args {
     time {
-      return [strftime "%H:%M"]
+      strftime "%H:%M"
     }
     date {
-      return [strftime "%d %b %Y"]
+      strftime "%d %b %Y"
     }
     default {
-      return [strftime "%l:%M %P"]
+      strftime "%I:%M %P"
     }
   }
 }
 
 proc testip {ip} {
   set tmp [split $ip .]
-  if {[expr [llength $tmp] != 4]} then {
+  if {[llength $tmp] != 4} then {
     return 0
   }
-  foreach i [split [join $tmp ""] ""] {
-    if {![string match \[0-9\] $i]} then {
-      return 0
-    }
-  }
   set index 0
   foreach i $tmp {
-    if {(([expr [string length $i] > 3]) || \
-        (([expr $index == 3]) && (([expr $i > 254]) || ([expr $i < 1]))) || \
-        (([expr $index <= 2]) && (([expr $i > 255]) || ([expr $i < 0]))))} then {
+    if {((![regexp \[^0-9\] $i]) || ([string length $i] > 3) ||
+         (($index == 3) && (($i > 254) || ($i < 1))) ||
+         (($index <= 2) && (($i > 255) || ($i < 0))))} then {
       return 0
     }
-    incr index 1
+    incr index
   }
   return 1
 }
 
 proc number_to_number {number} {
-  switch -exact $number {
+  switch -exact -- $number {
     0 {
       return Zero
     }
@@ -315,6 +318,19 @@
     15 {
       return Fifteen
     }
+    default {
+      return $number
+    }
   }
-  return
+}
+
+#
+# other commands:
+#
+
+proc isnumber {string} {
+  if {([string compare "" $string]) && (![regexp \[^0-9\] $string])} then {
+    return 1
+  }
+  return 0
 }
-------------- next part --------------
--- ../eggdrop1.3.cvs/scripts/botchk	Sat Oct  9 12:26:19 1999
+++ ./scripts/botchk	Thu Oct 21 16:55:36 1999
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# new botchk  (for eggdrop 1.1)
+# new botchk  (for eggdrop 1.1+)
 #
 # This is a script suitable for use in a crontab.  It checks to make sure
 # your bot is running.  YOU NEED A SEPARATE CRON JOB FOR EACH BOT.  If your
@@ -31,41 +31,68 @@
 ########## you probably don't need to change anything below here ##########
 
 cd $botdir
-if test -r pid.$botname; then
+
+# is there a pid file?
+if test -r pid.$botname
+then
   # there is a pid file -- is it current?
   botpid=`cat pid.$botname`
-  if `kill -CHLD $botpid >/dev/null 2>&1`; then
-    # it's still going
-    # back out quietly
+  if `kill -CHLD $botpid >/dev/null 2>&1`
+  then
+    # it's still going -- back out quietly
     exit 0
   fi
   echo ""
-  echo "Stale pid.$botname file (erasing it)"
+  echo "Stale pid.$botname file, erasing..."
   rm -f pid.$botname
 fi
-echo ""
-echo "Couldn't find the bot running.  Reloading it..."
-echo ""
-# Check for userfile first
-if test -r $userfile; then
-   # It's there, load the bot
-  ./$botscript
-  exit 0
-fi
-if test -r $userfile~new; then
-   # Bot f*@!ed up while saving the userfile last time.  Move it over.
-   echo "Userfile missing.  Using last saved userfile..."
-   mv $userfile~new $userfile
-  ./$botscript
-  exit 0
+
+if test -r CANTSTART.$botname
+then
+  if test -r $userfile || test -r $userfile~new || test -r $userfile~bak
+  then
+    echo ""
+    echo "Userfile found, removing check file 'CANTSTART.$botname'..."
+    rm -f CANTSTART.$botname
+  fi
 fi
-if test -r $userfile~bak; then
-   # Userfile is missing, use backup userfile.
-   echo "Userfile missing.  Using backup userfile..."
-   cp $userfile~bak $userfile
-  ./$botscript
-  exit 0
+
+# test if we have run botchk previously and didn't find a userfile
+if test ! -f CANTSTART.$botname
+then
+  echo ""
+  echo "Couldn't find bot '$botname' running, reloading..."
+  echo ""
+  # check for userfile and reload bot if found
+  if test -r $userfile
+  then
+    # It's there, load the bot
+    ./$botscript
+    exit 0
+  else
+    if test -r $userfile~new
+    then
+      # Bot f*@!ed up while saving the userfile last time.  Move it over.
+      echo "Userfile missing.  Using last saved userfile..."
+      mv -f $userfile~new $userfile
+      ./$botscript
+      exit 0
+    else
+      if test -r $userfile~bak
+      then
+        # Userfile is missing, use backup userfile.
+        echo "Userfile missing.  Using backup userfile..."
+        cp -f $userfile~bak $userfile
+        ./$botscript
+        exit 0
+      else
+        # Well, nothing to work with...
+        echo "No userfile.  Could not reload the bot..."
+        echo "no userfile" > CANTSTART.$botname
+        exit 1
+      fi
+    fi
+  fi
 fi
-# Well, nothing to work with...
-echo "No userfile.  Could not reload the bot.."
+
 exit 0
-------------- next part --------------
--- ../eggdrop1.3.cvs/scripts/compat.tcl	Tue Oct 12 16:25:15 1999
+++ ./scripts/compat.tcl	Thu Oct 21 17:00:40 1999
@@ -2,93 +2,94 @@
 # This script just quickly maps old tcl functions to the new ones,
 # use this is you are to lazy to get of your butt and update your scripts :D
 #
-# cleanup by Tothwolf 25May1999
-# added g/setdn/uploads functions by rtc 10Oct1999
+# Tothwolf  25May1999: cleanup
+# Tothwolf  06Oct1999: optimized
+# rtc       10Oct1999: added [set|get][dn|up]loads functions
 
 proc gethosts {hand} {
-  return [getuser $hand HOSTS]
+  getuser $hand HOSTS
 }
 
 proc addhost {hand host} {
-  return [setuser $hand HOSTS $host]
+  setuser $hand HOSTS $host
 }
 
 proc chpass {hand pass} {
-  return [setuser $hand PASS $pass]
+  setuser $hand PASS $pass
 }
 
 # setxtra is no longer relevant 
 
 proc getxtra {hand} {
-  return [getuser $hand XTRA]
+  getuser $hand XTRA
 }
 
 proc setinfo {hand info} {
-  return [setuser $hand INFO $info]
+  setuser $hand INFO $info
 }
 
 proc getinfo {hand} {
-  return [getuser $hand INFO]
+  getuser $hand INFO
 }
 
 proc getaddr {hand} {
-  return [getuser $hand BOTADDR]
+  getuser $hand BOTADDR
 }
 
 proc setaddr {hand addr} {
-  return [setuser $hand BOTADDR $addr]
+  setuser $hand BOTADDR $addr
 }
 
 proc getdccdir {hand} {
-  return [getuser $hand DCCDIR]
+  getuser $hand DCCDIR
 }
 
 proc setdccdir {hand dccdir} {
-  return [setuser $hand DCCDIR $dccdir]
+  setuser $hand DCCDIR $dccdir
 }
 
 proc getcomment {hand} {
-  return [getuser $hand COMMENT]
+  getuser $hand COMMENT
 }
 
 proc setcomment {hand comment} {
-  return [setuser $hand COMMENT $comment]
+  setuser $hand COMMENT $comment
 }
 
 proc getemail {hand} {
-  return [getuser $hand XTRA email]
+  getuser $hand XTRA email
 }
 
 proc setemail {hand email} {
-  return [setuser $hand XTRA EMAIL $email]
+  setuser $hand XTRA EMAIL $email
 }
 
 proc getchanlaston {hand} {
-  return [lindex [getuser $hand LASTON] 1]
+  lindex [getuser $hand LASTON] 1
 }
 
 proc time {} {
-  return [strftime "%H:%M"]
+  strftime "%H:%M"
 }
 
 proc date {} {
-  return [strftime "%d %b %Y"]
+  strftime "%d %b %Y"
 }
 
 proc setdnloads {hand {c 0} {k 0}} {
-  return [setuser $hand FSTAT d $c $k]
+  setuser $hand FSTAT d $c $k
 }
 
 proc getdnloads {hand} {
-  return [getuser $hand FSTAT d]
+  getuser $hand FSTAT d
 }
 
 proc setuploads {hand {c 0} {k 0}} {
-  return [setuser $hand FSTAT u $c $k]
+  setuser $hand FSTAT u $c $k
 }
 
 proc getuploads {hand} {
-  return [getuser $hand FSTAT u]
+  getuser $hand FSTAT u
 }
 
 # as you can see it takes a lot of effort to simulate all the old commands


More information about the Patches mailing list