egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with timer to display Database info after XX minutes

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
rileyil77
Voice


Joined: 10 Sep 2005
Posts: 21
Location: Hamilton, AL

PostPosted: Mon Jan 28, 2019 3:46 pm    Post subject: Help with timer to display Database info after XX minutes Reply with quote

To whom it may concern,

I've edit the following calc.tcl to store Computerized Bulletin Board System information set by channel users and no longer display calculation results. Bulletin Board System is shortened by a lot of SysOp (System Operators) to BBS.

Code:
#calc.tcl v0.3g by RufusDE <rufus@o-town.de>
#
#  Copyright (c) 1996 Jason P Schanuel (calcbot@gobills.com)
#   permission is granted to do anything you want with this
#   as the above copyright stays intact (or whatever :-)



That being said I see a part of the script where it has information for picking random calc stored in the calcdata.tcl file. What I'm wanting to is in every so many minutes let the bot select a random calc from the calcdata.tcl and display it in the IRC chatroom. Since, I run the only IRC server for the network, and I run the bot I don't see this as a flooding problem. Especially since I sit on the server alone unless someone needs help with setting up an Old DOS based BBS.

Also I'm not a TCL programmer, I'm an old DOS QBasic programmer. However I'm great at copying and pasting into TCL. I will give display the entire randomizing part of the script here, and maybe you can tell me what to add to make it display a random calc from the calcdata.tcl after a set amount of minutes. Like for example:

Set Timer : 120 minutes (Which is 2 hours, incase your didn't know.)
Display randcalc from the database.

Code:
#
# forward pub randcalcs to main routine
#

proc pub_randcalc {nick uhost hand chan arg} {

    global debug_calc calc_dict



    if {[limit $nick $chan 1]} {return 0}

    set arg "calc [lindex [array names calc_dict] [rand [array size calc_dict]]]"

    if {$debug_calc} {

   putlog "pub_randcalc - nick=$nick, uhost=$uhost, hand=$hand, chan=$chan arg=$arg"

    }

    return [main_calc $nick $uhost $hand $chan pub $arg]

}

_________________
John Riley
SLASHER BBS ProBoard V2.17 telnet://slasherbbs.com
or look me on Internet Radio!

http://slasherbbs.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
rileyil77
Voice


Joined: 10 Sep 2005
Posts: 21
Location: Hamilton, AL

PostPosted: Tue Jan 29, 2019 12:26 am    Post subject: Help with timer to display Database info after XX minutes Reply with quote

I asked a friend on FaceBook and told him I seen several views, but no replies... He said, "POST the ENTIRE calc.tcl... That way everyone can see what it actually does." So I'm posting the entire script below!

Code:
# calc.tcl v0.3g by RufusDE <rufus@o-town.de>
#
#  Copyright (c) 1996 Jason P Schanuel (calcbot@gobills.com)
#   permission is granted to do anything you want with this
#   as the above copyright stays intact (or whatever :-)
#
#
# Changes:
#   v0.3g by Thomas Koester <rufus@o-town.de>
#   - added compatibility for 1.4/1.5 bots (which are much like 1.3.x)
#   - allow '!' and '=' in terms
#   0.3f by Thomas.Koester@rz.uni-osnabrueck.de
#   - create $calc_filename if it doesn't exist
#   0.3e by Thomas.Koester@rz.uni-osnabrueck.de
#   - added compatibility for 1.3.x bots
#   0.3d by Thomas.Koester@rz.uni-osnabrueck.de
#   - check if toolbox.tcl/toolkit.tcl are loaded
#   - support for traffic shaper (limit.tcl)
#   - set calc_loaded 1  (for interfacing with other scripts)
#   0.3c by Thomas.Koester@rz.uni-osnabrueck.de
#   - added the command:  match <key pattern>
#     Looking up keys with glob match
#   - commands may be prefixed by '!'
#   - fixed bug which caused "too many open files" after many .restarts
#   - hand2level now supports multi channel user levels
#   0.3b by Thomas.Koester@rz.uni-osnabrueck.de
#   - added the syntax:  calcto <nick> <key>
#     (not available in DCC chat)
#   - dcc chat calcs are not bound by default (cleans up the botnet)
#   - removed 'randcalc', use 'calc' w/o args instead
#   - much code cleanup
#   - option to rename calc command
#   - bots are not allowed to set/change calcs

#   0.3a by Thomas.Koester@rz.uni-osnabrueck.de

#   - fixed save of calcs from nicks with [..] in it

#   - fixed deleting of calcs (was not permanent w/o '.calc save')

#   - calc now can calculate. e.g. 'calc 4+7' or 'calc 4*atan(1)'

#   - calc without args is bound to randcalc

#   - calc definitions can only be overwritten or deleted by users of equal

#     or higher userlevel (order: -,f,o,m,n)

#   0.3 by Thomas.Koester@rz.uni-osnabrueck.de

#   - tested with 1.1.5

#   - removed the syntax: calc <key> is <definition>

#     due to bugs when there is a 'is' in the definition

#   - added '[added by: Foobar]' in replies

#   - added randcalc command

#   0.2d

#   - tested with turtle

#   - removed nick2hand nonsence

#   - little cleanup of code

#   - add the 0.2d to Changes: section :-)

#   0.2c

#   - added the syntax:

#     calc <key> is <definition>

#   - fixed up the if statements

#   - added an optional regexp search for the master .calc command

#       which doesn't work yet

#   0.2b

#   - bug fixes

#     - corrected bot response from

#       <GoBot> * calc whatever = what whatever is

#       to:

#       <GoBot> * whatever = what whatever is

#     - turned tracing off by default

#   0.2

#   - bug fixes

#     - changed incorrect use of $args to $arg (thanks Robey)

#       (so that's why I needed all those join's)

#     - msg calc definitions weren't written to file (fixed)

#   - enhancements

#     - .calc save now keeps handle of definition creator

#

# Install:

#   - change calc_channel and calc_filename and trace_filename

#       to suit your configuration

#   - just add 'source scripts/calc.tcl' to your bot command file

#

# Commands:

#   Public:

#     calc <key> =  <definition>

#       - sets a calc definition

#       - bot updates calc definitions file

#       - bot says thanks in public

#     calc <key>

#       - bot responds with definition in public

#     calc

#       - bot responds with randomly selected definition in public

#   Msg:

#     msg <bot> calc <key> = <definition>

#       - sets a calc definition

#       - bot updates calc definitions file

#       - bot say thanks via notice

#     msg <bot> calc <key>

#       - bot responds with definition via notice

#     msg <bot> calc

#       - bot responds with randomly selected definition via notice

#   Chat:

#     msg =<bot> calc <key> = <definition>

#       - sets a calc definition

#       - bot updates calc definitions file

#       - bot say thanks on your botnet channel

#     msg =<bot> calc <key>

#       - bot responds with definition on your botnet channel

#     msg =<bot> calc

#       - bot responds with randomly selected definition on your botnet channel

#   Command: requires +n

#     msg =<bot> .calc show

#       - bot displays *all* current calc definition

#     msg =<bot> .calc save

#       - bot overwites calc definition file with all current calc definitions

#

# Futures:

#   - Should limit public calc's via another user flag

#   - Multiple calc bots should negotiate who answers chat line calcs

#       - perhaps only local bot should answer chat line calcs

#       - if local bot is not a calc bot then one should be the master

#           and answer foreign chat line calcs

#   - Multiple calc bots should negotiate trading calc definitions



#

# Bugs:

#   - All calc bots in the net will answer chat line calcs

#       not a problem if we only have one calc bot

#   - Calc definitions file has multiple definitions for the

#       same key if it was defined more than once

#       it still works ok because the last one is used

#       the file is then too large but can be refreshed by '.calc save'

#   - No file locking - Do we need this?????

#   - It has it's own trace file for debugging

#       should probably use the global log file

#   - Probably need a bot check to prevent 'calc calc = whatever'

#       and the bot triggers  itself responding to 'calc calc'

#       - added a preceeding '* ' to prevent this

#

#



#debugging stuff

#

set debug_calc 0



# fake limit.tcl if not loaded

if {[info commands limit] == ""} { proc limit {nick chan lines} {return 0} }



# toolbox.tcl must be loaded

if {![info exists toolbox_loaded]} {

   putlog "[info script] needs toolbox.tcl - not installed!"

   return 0

}



# toolkit.tcl must be loaded

if {![info exists toolkit_loaded]} {

   putlog "[info script] needs toolkit.tcl - not installed!"

   return 0

}



# compatibility for 1.1 and 1.3 bots

switch -glob $version {

   "1.[12].*"   {

      proc calc_matchchanattr {hand flags chan} {

         return [matchchanattr $hand $flags $chan]

      }

   }

   "1.[3-9].*"      {

      proc calc_matchchanattr {hand flags chan} {

         return [matchattr $hand |$flags $chan]

      }

   }

   default      {

      putlog "eggdrop $version is not supported by [info script]."; exit 0

   }

}



# calc_channel is the channel for public calcs (use % for any channel)

#set calc_channel {#osnabrueck}

set calc_channel {%}



# calc_command is the command for pub, msg and chat calcs

set calc_command ".calc"

set match_command ".match"



#

# calc_filename is where we store all current calcs

set calc_filename "calcdata.tcl"



#

# handle to level

#

proc hand2level {hand chan} {

    global calc_channel

    if {[validchan $chan]} {

   set lchan $chan

    } else {

   set lchan $calc_channel

    }

    set handle_level 0

    if {[matchattr $hand b]} { return -1 }

    foreach level {f o m n} {

   if {[matchattr $hand $level] || ([validchan $lchan] && [calc_matchchanattr $hand $level $lchan])} {

       incr handle_level

   }

    }

    #putlog "hand2level - hand='$hand', handle_level='$handle_level', lchan='$lchan'"

    return $handle_level

}



#

# append calc definition to definitions file (no checking for success ;-)

#

proc file_add_calc {hand arg} {

    global debug_calc calc_filename

    set calc_fid [open $calc_filename a]

    if {$debug_calc} {

   putlog "file_add_calc - hand=$hand, arg='$arg'"

    }

    puts $calc_fid "file_calc [list $hand] [list $arg]"

    close $calc_fid

    return 1

}



#

# process all calc commands (except the dcc .calc)

#

proc main_calc {nick uhost hand chan calc_type arg} {

    global debug_calc

    global calc_dict

    global calc_hand_dict



    if {[strcmp $hand "*"]} { set handle $hand

    } else { set handle "~$nick" }



    if {$debug_calc} {

   putlog "main_calc - type=$calc_type, nick=$nick, uhost=$uhost, hand=$hand, chan=$chan arg='$arg'"

    }



    regexp {^calc(|to [^ ]+) ([0-9a-z,+*/.%~!<>()&^|?: !=-]*)$} $arg full towhom term

    if {[info exists term] && ![catch "expr $term" value]} {

       set reply "I have no idea!"

       if {[info exists towhom] && ([string first "to " $towhom]==0)} {

      putmsg [string range $towhom 3 end] $reply

      set calc_type msg

       }

    } else {



    regexp {^calc ([^=]+)\=(.*)$} $arg full lhs rhs

    if {[info exists lhs]} {

      

   set lhs [string trim [strupr $lhs]]

   set rhs [string trim $rhs]

   if {$debug_calc} {

       putlog "main_calc - full='$full', lhs='$lhs', rhs='$rhs'"

   }



   if {[hand2level $hand $chan] < 0 || ([info exists calc_dict($lhs)] &&

       [hand2level $hand $chan] < [hand2level $calc_hand_dict($lhs) $chan])} {

       set reply "Sorry, $handle, you are not allowed to change this calc."

   } elseif {[strcmp $rhs ""]} {

       set calc_dict($lhs) $rhs

       if {[strcmp $calc_type file]} {

      file_add_calc $handle $arg

       }

       set calc_hand_dict($lhs) $handle

       set reply "Thanks for the info, $handle"

   } else {

       if {[info exists calc_dict($lhs)]} {

      if {[strcmp $calc_type file]} {

         file_add_calc $handle $arg

      }

      unset calc_dict($lhs)

      set reply "Ok, I will delete this calc, $handle"

       } else {

      set reply "Sorry, $handle, I can't delete this."

       }

   }



    } else {

   regexp {^calc(|to [^ ]+) (.*)$} $arg full towhom mixedkey

   set mixedkey [string trim $mixedkey]

   set key [strupr $mixedkey]

   if {[info exists calc_dict($key)]} {

       set reply "* $mixedkey \= $calc_dict($key)  \[added by: $calc_hand_dict($key)\]"

       if {[info exists towhom] && ([string first "to " $towhom]==0)} {

      putmsg [string range $towhom 3 end] $reply

      set calc_type msg

       }

   } else {

       set reply "Sorry $nick, I don't know what '$mixedkey' is :-("

   }

    }



    }

    if {[info exists reply]} {

   switch $calc_type {

   chat   { dccputchan $chan $reply }

   file   { }

   msg   { putmsg $nick $reply }

   pub   { putchan $chan $reply }

   default   { putlog "main_calc - ERROR: unknown type=$calc_type" }

   }

    }

   

    return 1

}



#

# forward pub calcs to main routine

#

proc pub_calc {nick uhost hand chan arg} {

    global debug_calc calc_command



    if {[limit $nick $chan 1]} {return 0}

    if {$debug_calc} {

   putlog "pub_calc - nick=$nick, uhost=$uhost, hand=$hand, chan=$chan arg=$arg"

    }

    regsub -nocase "^!?$calc_command" $arg "calc" arg

    return [main_calc $nick $uhost $hand $chan pub $arg]

}



#

# forward msg calcs to main routine

#

proc msg_calc {nick uhost hand arg} {

    global debug_calc calc_command

    if {$debug_calc} {

   putlog "msg_calc - nick=$nick, uhost=$uhost, hand=$hand arg='$arg'"

    }

    regsub -nocase "^!?$calc_command" $arg "calc" arg

    return [main_calc $nick $uhost $hand chan msg $arg]

}



#

# forward chat calcs to main routine

#

proc chat_calc {nick chan arg} {

    global debug_calc calc_command

    if {$debug_calc} {

   putlog "chat_calc - nick=$nick, chan=$chan, arg='$arg'"

    }

    regsub -nocase "^!?$calc_command" $arg "calc" arg

    return [main_calc $nick uhost "*" $chan chat $arg]

}



#

# forward calcs read from definitions file to main routine

#

proc file_calc {hand arg} {

    global debug_calc

    if {$debug_calc} {

   putlog "file_calc - hand=$hand arg='$arg'"

    }

    return [main_calc nick uhost $hand chan file $arg]

}



#

# process the dcc .calc command

#

proc dcc_calc {hand idx arg} {

    global debug_calc

    global calc_filename

    global calc_dict

    global calc_hand_dict



    if {$debug_calc} {

   putlog "dcc_calc - hand=$hand, idx=$idx, arg=$arg"

    }



    if {[llength $arg] == 0} {

   putdcc $idx {syntax: .calc [show|save]}

    } else {

   set calc_type [lindex $arg 0]

   if {[llength $arg] == 2} {

       set mask [lindex $arg 1]

   }

   

   set count 0

   

   if {![strcmp $calc_type show]} {

       if {[info exists mask]} {

      putdcc $idx "calc: these are the currently available calc's matching '$mask'"

       } else {

      putdcc $idx {calc: these are the currently available calc's}

       }

       foreach key [array names calc_dict] {

      if {[info exists mask]} {

          if {[regexp [strupr $mask] [strupr $key]]} {

         putdcc $idx "$key = $calc_dict($key) \[added by: $calc_hand_dict($key)\]"

         incr count

          }

      } else {

          putdcc $idx "$key = $calc_dict($key) \[added by: $calc_hand_dict($key)\]"

          incr count

      }

       }

       if {[info exists mask]} {

      putdcc $idx "calc: $count records total matching '$mask'"

       } else {

      putdcc $idx "calc: $count records total"

       }

   } elseif {![strcmp $calc_type save]} {

       set calc_fid [open $calc_filename w]

       foreach key [array names calc_dict] {

      file_add_calc $calc_hand_dict($key) "calc $key\=$calc_dict($key)"

      incr count

       }

       close $calc_fid

       putdcc $idx "calc: $count records saved to $calc_filename"

   } else {

       putdcc $idx {syntax: .calc [show|save]}

   }

    }

    return 1

}

#
# forward pub randcalcs to main routine
#

proc pub_randcalc {nick uhost hand chan arg} {

    global debug_calc calc_dict



    if {[limit $nick $chan 1]} {return 0}

    set arg "calc [lindex [array names calc_dict] [rand [array size calc_dict]]]"

    if {$debug_calc} {

   putlog "pub_randcalc - nick=$nick, uhost=$uhost, hand=$hand, chan=$chan arg=$arg"

    }

    return [main_calc $nick $uhost $hand $chan pub $arg]

}



#

# forward msg randcalcs to main routine

#

proc msg_randcalc {nick uhost hand arg} {

    global debug_calc calc_dict

    set arg "calc [lindex [array names calc_dict] [rand [array size calc_dict]]]"

    if {$debug_calc} {

   putlog "msg_calc - nick=$nick, uhost=$uhost, hand=$hand arg='$arg'"

    }

    return [main_calc $nick $uhost $hand chan msg $arg]

}

#
# forward chat randcalcs to main routine
#

proc chat_randcalc {nick chan arg} {

    global debug_calc calc_dict

    set arg "calc [lindex [array names calc_dict] [rand [array size calc_dict]]]"

    if {$debug_calc} {

   putlog "chat_calc - nick=$nick, chan=$chan, arg='$arg'"

    }

    return [main_calc $nick uhost "*" $chan chat $arg]

}

#
# match
#

proc main_match {nick uhost hand chan match_type arg} {

    global debug_calc calc_dict



    regexp {^match (.*)$} $arg full search



    set count 0



    foreach key [lsort [array names calc_dict]] {

   if {[string match [strlwr "$search*"] [strlwr "$key"]]} {

       if {$count} {

      append matches [strlwr ", $key"]

       } else {

      set matches [strlwr "$key"]

       }

       incr count

   }

    }



    if {$count} {

   if {$count==1} {

       set reply "$nick: $count match ($matches)"

   } {

       set reply "$nick: $count matches ($matches)"

   }

    } else {

   set reply "$nick: Sorry, no matches."

    }



    if {[info exists reply] } {

   set reply_line 0

   while {[strlen $reply] > 0} {

       if {[strlen $reply] > 255} {

      set do_reply "[string range $reply 0 251]..."

      set reply [string range $reply 252 end]

       } else {

      set do_reply $reply

      set reply ""

       }

       incr reply_line

       switch $match_type {

       chat    { if {$reply_line<=20} {dccputchan $chan $do_reply}}

       msg     { if {$reply_line<=5} {putmsg $nick $do_reply}}

       pub     { if {$reply_line<=1} {putchan $chan $do_reply}}

       default { putlog "main_match - ERROR: unknown type=$match_type" }

       }

   }

    }



    return 1

}



proc pub_match {nick uhost hand chan arg} {

    global debug_calc match_command



    if {[limit $nick $chan 1]} {return 0}

    if {$debug_calc} {

   putlog "pub_match - nick=$nick, uhost=$uhost, hand=$hand, chan=$chan arg=$arg"

    }

    regsub -nocase "^!?$match_command" $arg "match" arg

    return [main_match $nick $uhost $hand $chan pub $arg]

}



proc msg_match {nick uhost hand arg} {

    global debug_calc match_command

    if {$debug_calc} {

   putlog "msg_match - nick=$nick, uhost=$uhost, hand=$hand, arg=$arg"

    }

    regsub -nocase "^!?$match_command" $arg "match" arg

    return [main_match $nick $uhost $hand chan msg $arg]

}



#

# bindings

#

#

bind pubm - "$calc_channel $calc_command *" pub_calc

bind pubm - "$calc_channel !$calc_command *" pub_calc

bind pubm - "$calc_channel $calc_command" pub_randcalc

bind pubm - "$calc_channel !$calc_command" pub_randcalc

bind pubm - "$calc_channel ${calc_command}to % *" pub_calc

bind pubm - "$calc_channel !${calc_command}to % *" pub_calc

bind pubm - "$calc_channel ${calc_command}to %" pub_randcalc

bind pubm - "$calc_channel !${calc_command}to %" pub_randcalc



bind msgm - "$calc_command *" msg_calc

bind msgm - "!$calc_command *" msg_calc

bind msgm - "$calc_command" msg_randcalc

bind msgm - "!$calc_command" msg_randcalc

bind msgm - "${calc_command}to % *" msg_calc

bind msgm - "!${calc_command}to % *" msg_calc

bind msgm - "${calc_command}to %" msg_randcalc

bind msgm - "!${calc_command}to %" msg_randcalc



#bind chat - "$calc_command *" chat_calc

#bind chat - "!$calc_command *" chat_calc

#bind chat - "$calc_command" chat_randcalc

#bind chat - "!$calc_command" chat_randcalc

bind dcc  m calc  dcc_calc



bind pubm - "$calc_channel $match_command *" pub_match

bind pubm - "$calc_channel !$match_command *" pub_match



bind msgm - "$match_command *" msg_match

bind msgm - "!$match_command *" msg_match


#
# read in the current calc definitions file
#

if {![file exists $calc_filename]} { close [open $calc_filename w] }

source $calc_filename

set calc_loaded 1
putlog "[info script] by RufusDE loaded."

_________________
John Riley
SLASHER BBS ProBoard V2.17 telnet://slasherbbs.com
or look me on Internet Radio!

http://slasherbbs.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3578
Location: Mint Factory

PostPosted: Tue Jan 29, 2019 2:18 am    Post subject: Reply with quote

You can have a look at Basic File Operations topic where you will find a detailed explanation on how to read the contents of a text file, pick a random line and do whatever you want with it. Should be an easy DIY. Smile

For a timed output you have two options (depending on eggdrop version): timers or crontab.

TIMER wrote:

timer <minutes> <tcl-command> [count]
Description: executes the given Tcl command after a certain number of minutes have passed. If count is specified, the command will be executed count times with the given interval in between. If you specify a count of 0, the timer will repeat until it's removed with killtimer or until the bot is restarted.
Returns: a timerID
Module: core

For example:
Code:

timer 120 [list calc_get_random_line] 0

proc calc_get_random_line args {
# code you make with instructions from 'Basic File Operations'
}

Keep in mind that args has a special meaning in TCL, so avoid using variables with this name. I added it here because I don't pass any arguments to the calc_get_random_line function. I can make it:
Code:

proc calc_get_random_line {} {

and will work just fine.
CRON wrote:

CRON (stackable)
bind cron <flags> <mask> <proc>
procname <minute 0-59> <hour 0-23> <day 1-31> <month 1-12> <weekday
0-6>
Description: similar to bind TIME, but the mask is evaluated as a cron expression, e.g. "16/2 */2 5-15 7,8,9 4". It can contain up to five fields: minute, hour, day, month, weekday; delimited by whitespace. Week days are represented as 0-6, where Sunday can be either 0 or 7. Symbolic names are not supported. The bind will be triggered if the mask matches all of the fields, except that if both day and weekday are not '*', only one of them is required to match. If any number of fields are omitted at the and, the match will proceed as if they were '*'. All cron operators are supported. Please refer to the crontab manual for their meanings. Flags are ignored.
Module: core

Now with cron is a lot easier because it's basic unix crontab.
Code:

bind cron - {* */2 * * *} calc_get_random_line

proc calc_get_random_line {min hour day month weekday} {
# code you make with instructions from 'Basic File Operations'
}

I prefer cron cos it's easier to maintain and I'm 100% sure runs when it should.
_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
rileyil77
Voice


Joined: 10 Sep 2005
Posts: 21
Location: Hamilton, AL

PostPosted: Tue Jan 29, 2019 9:07 am    Post subject: Reply with quote

Thanks, Caesar, for your reply. However since my primary bot is an eggdrop on Windows, or a WinDrop, I can't use crons. But timer sounds right. However going through the Basic File Operations, I don't see anywhere on the the commands to output to a channel(s). I see a ton of commands to read random lines from the text, add lines to the text file, remove lines to the text file, and so forth.

So, I did go ahead and try the timer command and got this error from my eggdrop:

wrong # args: should be "timer minutes command"
[07:36] <SlashBot> while executing
[07:36] <SlashBot> "timer 2 [list calc_get_random_line] 0 "

I put timer 2 so I could just see it worked...

The code I used was actually already in the script I just removed the references where it was talking to specific $nick in the chat room. I've also went ahead and corrected what I thought caused my error above.

Code:
#
# Random Calc Displayed in Channel
#
timer 2 [list pub_randcalc] 0
proc pub_randcalc {uhost hand chan arg} {

    global debug_calc calc_dict

    if {[limit $chan 1]} {return 0}
    set arg "calc [lindex [array names calc_dict] [rand [array size calc_dict]]]"
    if {$debug_calc} {
   putlog "pub_randcalc - uhost=$uhost, hand=$hand, chan=$chan arg=$arg"
    }
    return [main_calc $uhost $hand $chan pub $arg]
}

_________________
John Riley
SLASHER BBS ProBoard V2.17 telnet://slasherbbs.com
or look me on Internet Radio!

http://slasherbbs.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3578
Location: Mint Factory

PostPosted: Tue Jan 29, 2019 10:28 am    Post subject: Reply with quote

Hi,

I didn't have much to do with timers so I just did what the manual said would have the timer run forever. Guess I miss-understood it. Anyway..

The cron command, much like timer, is from the eggdrop/windrop version and (in theory at least) shouldn't be OS dependent. But better not take my word for it and load this code on a test bot:
Code:

bind cron - {* */2 * * *} get_random

proc get_random{min hour day month weekday} {

}

If doesn't crash then should be fine with using cron, else will stick with timer, no problem at all.

If you got the basics of how to get a random line from that text file then the part where you dump the output to the channels set in calc_channel variable (from the code you posted right now is set to % meaning all channels) then we use this code:
Code:

if {[string equal "%" $calc_channel]} {
   set source [channels]
} else {
   set source $calc_channel
}

foreach chan $source {
   if {![botonchan $chan]} continue
   puthelp "PRIVMSG $chan :<message>"
}

This first tests if the calc_channel variable is set to % (meaning all channels) then set the source as all channels the bot has a record on, else whatever is set in that variable.

Then we loop over what channels where either listed in calc_channel variable (if isn't set to %) or the channels the bot has a record on. We check if the bot is actually on the channel (continue with next record if isn't) and send that <message>.

Final timer code should be:
Code:

timer 120 calc_random

proc calc_random args {
   # code you make with instructions from 'Basic File Operations'

   if {[string equal "%" $calc_channel]} {
      set source [channels]
   } else {
      set source $calc_channel
   }

   foreach chan $source {
      if {![botonchan $chan]} continue
      puthelp "PRIVMSG $chan :<message>"
   }
   
   # we call this again to have it loop forever every 120 minutes
   timer 120 calc_random   
}

Replace <message> with the actual variable you got for that random line.
_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1008

PostPosted: Tue Jan 29, 2019 11:51 am    Post subject: Re: Help with timer to display Database info after XX minute Reply with quote

rileyil77 wrote:

... Especially since I sit on the server alone unless someone needs help with setting up an Old DOS based BBS. ...


Just remember ... OS/2 does DOS better than DOS does DOS. Wink Very Happy

Whew... that goes back a ways. heheeheh

Warp4
Maximus/2
BinkleyTerm

FidoNet and others.

(Before that, it was multi-tasking DOS using DESQview and QEMM, with a whopping whole 4!! meg of memory. )

Someday let me know what IRC network you are on, and your nick there. It might be fun to reminisce about how much fun computer communications was, before the internet came along.

Sorry to interrupt and digress.
Have fun with Eggdrop/Windrop and your BBS stuff. Smile
_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Back to top
View user's profile Send private message
rileyil77
Voice


Joined: 10 Sep 2005
Posts: 21
Location: Hamilton, AL

PostPosted: Tue Jan 29, 2019 11:52 am    Post subject: Reply with quote

So now I'm getting this error:

[09:46] <SlashBot> [09:47:01] Tcl error in script for 'timer8':
[09:46] <SlashBot> [09:47:01] can't read "calc_channel": no such variable

And here is the code I'm using in the script, so I KNOW the calc channel variable is set...

Code:
timer 2 calc_random
set calc_channel {%}

proc calc_random args {
set fname "calcdata.tcl"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"] 

   if {[string equal "%" $calc_channel]} {
      set source [channels]
   } else {
      set source $calc_channel
   }

   foreach chan $source {
      if {![botonchan $chan]} continue
      putlog "msg_calc - uhost=$uhost, hand=$hand arg='$arg'"
   }
   
   timer 2 calc_random   
}

_________________
John Riley
SLASHER BBS ProBoard V2.17 telnet://slasherbbs.com
or look me on Internet Radio!

http://slasherbbs.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3578
Location: Mint Factory

PostPosted: Wed Jan 30, 2019 1:47 am    Post subject: Reply with quote

Ah, my bad. Forgot to add a global calc_channel, so the function can have access to a variable outside of it's scope.

I see that you got the part where you get the contents of a file into the bot memory but skipped the part where you actually select a random line. Anyway, give this a try:
Code:

timer 2 calc_random
set calc_channel {%}

proc calc_random args {
   global calc_channel
   
   set fname "calcdata.tcl"
   set fp [open $fname "r"]
   set data [read -nonewline $fp]
   close $fp
   set lines [split $data "\n"]
   set numlines [llength $lines]
   set num [rand $numlines]
   set randline [lindex $lines $num]

   if {[string equal "%" $calc_channel]} {
      set source [channels]
   } else {
      set source $calc_channel
   }

   foreach chan $source {
      if {![botonchan $chan]} continue
      puthelp "PRIVMSG $chan :$randline"
   }

   timer 2 calc_random
}

_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
rileyil77
Voice


Joined: 10 Sep 2005
Posts: 21
Location: Hamilton, AL

PostPosted: Wed Jan 30, 2019 1:13 pm    Post subject: Reply with quote

Thank you, Caesar. That works perfectly!! Thank you so much!!
_________________
John Riley
SLASHER BBS ProBoard V2.17 telnet://slasherbbs.com
or look me on Internet Radio!

http://slasherbbs.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber