This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

!stop command when bot it outputting text file.

Help for those learning Tcl or writing their own scripts.
Post Reply
t
tempest
Voice
Posts: 6
Joined: Mon Apr 23, 2012 8:01 am
Location: Australia

!stop command when bot it outputting text file.

Post by tempest »

i have a small script that reads a text file to a channel. some times the files are long and would like to have a !stop command... however just adding a proc and binding !stop does not work as the loop that is reading the file is queuing up the output command... i don't know if its a hard thing or not, but im not that good with tcl... any pointers would be good.

here is the code.

Code: Select all

proc Hypno_Reader {nick uhost hand chan text} { 
    set number [lindex [split $text] 0] 
    set filename ${::trance_file}/${number}.txt 
    if {![file exists $filename]} { 
        putquick "NOTICE $chan :Trance file not found." 
        return 
    } 

    set tracks [open $filename] 
    set data [split [read -nonewline $tracks] \n] 
    close $tracks 
    putquick "PRIVMSG #TheGridTestingArea : Loading your file ..."
    putquick "PRIVMSG ##TheGridTestingArea : We hope you enjoy..."
    foreach trance_line $data { 
        putquick "PRIVMSG #TheGridTestingArea :$trance_line" 
    } 
 } 
thanks in advance!

Tempest.
i come for the conversation and leave with the fishes.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Re: !stop command when bot it outputting text file.

Post by willyw »

tempest wrote:i have a small script that reads a text file to a channel. some times the files are long and would like to have a !stop command... however just adding a proc and binding !stop does not work as the loop that is reading the file is queuing up the output command... i don't know if its a hard thing or not, but im not that good with tcl... any pointers would be good.

...
Try this:

Code: Select all


bind pub - "!hypno_stop" hypno_stop

proc hypno_stop {nick uhost handle chan text} {

	clearqueue mode
}


Reference:
http://www.eggheads.org/support/egghtml ... mands.html
and find:
clearqueue <queue>

Description: removes all messages from a queue. Valid arguments are: mode, server, help, or all.
I hope this helps.
t
tempest
Voice
Posts: 6
Joined: Mon Apr 23, 2012 8:01 am
Location: Australia

Post by tempest »

thank you for the quick reply!

Well i put the proc in and it still does the same.. if you run the stop command while the bot is outputting the text file to the chan, it will not pick up the fact that you have done it untill it finishes outputting the file.

One the files has finished being output it then runs the stop proc. hmmm im still trying..

tempest.

Edit:
I'm sorry i must of put it in wrong. it n ow seems to be working! thank you so so much for your help!!!

You just made my day!!!!!!!!
i come for the conversation and leave with the fishes.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

First, it's better and wise to use puthelp instead of putquick.

Code: Select all

bind pub - "!hypno_stop" hypno_stop

proc hypno_stop {nick uhost handle chan text} {
global hypno_status
set hypno_status 0
}
add before "set tracks [open $filename]":

Code: Select all

global hypno_status
set hypno_status 1
and then alter your loop like this:

Code: Select all

    foreach trance_line $data {
        if {!$hypno_status} break
        puthelp "PRIVMSG #TheGridTestingArea :$trance_line"
    }
Once the game is over, the king and the pawn go back in the same box.
t
tempest
Voice
Posts: 6
Joined: Mon Apr 23, 2012 8:01 am
Location: Australia

Post by tempest »

thank you so much caesar!

im not able to apply your suggestions just yet, as im out and about! but i will let you know how i go with it when i get back in!

You guys are so helpfull!!

thank you!
i come for the conversation and leave with the fishes.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Something almost exactly like this was my first thought too.
When it didn't work, I did a quick experiment.

Try this:
Trigger the reader proc, then -
In the partyline, do: .tcl queuesize
to get the current number of entries in the queue.
Keep repeating the command, and see it count down.
(Be sure the file had something like 20 lines or more, so you have time)

I came to the conclusion that the foreach loop quickly does its job, and everything is in the queue, waiting. Thus, when the user comes along with the break, it doesn't matter... the loop is long done.

If you have time, experiment with it, and see what you come up with.
t
tempest
Voice
Posts: 6
Joined: Mon Apr 23, 2012 8:01 am
Location: Australia

Post by tempest »

yes well found that it cues up rather quickly! so the "clearqueue" is working wonders! don't want to pest too much just one more bit of advice. i want to slow down the output a little to the chan so in the loop i tried this...

Code: Select all

    foreach trance_line $data {
       puthelp "PRIVMSG $chan :$trance_line" 
       update
       after 3000
    } 
so trying to get it to wait for 3 seconds as the normal cue is a bit fast for what im after i have found.. however it seems to pause the whole script rather than just the text output. I have done a little searching around and i have only found examples of this in non loops... this last part and it will be perfect! LOL
i come for the conversation and leave with the fishes.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

tempest wrote: ...
so trying to get it to wait for 3 seconds as the normal cue is a bit fast for what im after i have found.. however it seems to pause the whole script rather than just the text output. I have done a little searching around and i have only found examples of this in non loops... this last part and it will be perfect! LOL

Off the top of my head (meaning - - untested) :

Experiment with this -

Code: Select all


utimer 3 [list puthelp "PRIVMSG $chan :$trance_line" ]


Reference:
http://www.eggheads.org/support/egghtml ... mands.html
and
http://www.peterre.info/characters.html
t
tempest
Voice
Posts: 6
Joined: Mon Apr 23, 2012 8:01 am
Location: Australia

Post by tempest »

well read up on utimer. It's a little confusing, just adding the utime line with the output still lets the bot output but still no actual pause in time for each line. hmmmm

I am now actually reading of a tcl manual LOL so i might get there in the end. Still more pointers welcome!

I have also read the utimer post that is here

http://forum.egghelp.org/viewtopic.php?p=88230

but still a little unclear how it fits in... having a bit of a play..

apparently a lot of people have a similar issue with utimer? It's just not clear cut! LOL
*gets her thinking cap on*
i come for the conversation and leave with the fishes.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

tempest wrote:well read up on utimer. It's a little confusing, just adding the utime line with the output still lets the bot output but still no actual pause in time for each line. hmmmm
I wasn't sure about it.
I suspect that all the timers are set and run down and the whole mess is in the queue, waiting, same as before.
I am now actually reading of a tcl manual LOL so i might get there in the end.
Excellent!
I have no doubt that you will. :)

Still more pointers welcome!
Do this little course:
http://suninet.the-demon.de/
I think it is a good place to begin. And you can use it for reference too, later.

Keep this open for reading, whenever scripting:
http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

Keep this open too, whenever scripting:
http://www.eggheads.org/support/egghtml ... mands.html

With those three, you can do a LOT.

I have also read the utimer post that is here

http://forum.egghelp.org/viewtopic.php?p=88230

but still a little unclear how it fits in... having a bit of a play..

apparently a lot of people have a similar issue with utimer? It's just not clear cut! LOL
Not really.
In that thread, arfer and nml375 are commenting. What they are talking about is the same thing that is covered by that link I gave you earlier:
http://www.peterre.info/characters.html
On that page, it tells how to use list with the timer (and utimer) command.
Perhaps their explanation was easier to follow.

Tip: In my experience reading here, anything to do with TCL that either arfer or nml375 responds with, is solid.
Actually, that's what we need here now... for one of them to jump in here.
*gets her thinking cap on*
Me too, and normally I would not have replied yet. But a solution is not coming to me, ( I have tried something else, and got similar results again) and I don't want you to have to wait. Others that may know how to do this in the proper manner, may be reading along and being polite and not jumping in. I'm inviting them, now.
t
tempest
Voice
Posts: 6
Joined: Mon Apr 23, 2012 8:01 am
Location: Australia

Post by tempest »

Sorry I have not been able to reply sooner. Life threw me a few curly ones this week, so have not had much of a chance to do more on this. But I'm back to it now!

Just wanted to say thank you for all the help that you guys have posted! it's been really great! I will let you all know how I go!

tempest.
i come for the conversation and leave with the fishes.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Post Reply