| View previous topic :: View next topic |
| Author |
Message |
tempest Voice
Joined: 23 Apr 2012 Posts: 6 Location: Australia
|
Posted: Mon Apr 23, 2012 8:11 am Post subject: !stop command when bot it outputting text file. |
|
|
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: |
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Mon Apr 23, 2012 2:34 pm Post subject: Re: !stop command when bot it outputting text file. |
|
|
| 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: |
bind pub - "!hypno_stop" hypno_stop
proc hypno_stop {nick uhost handle chan text} {
clearqueue mode
}
|
Reference:
http://www.eggheads.org/support/egghtml/1.6.21/tcl-commands.html
and find:
| Quote: |
clearqueue <queue>
Description: removes all messages from a queue. Valid arguments are: mode, server, help, or all.
|
I hope this helps. |
|
| Back to top |
|
 |
tempest Voice
Joined: 23 Apr 2012 Posts: 6 Location: Australia
|
Posted: Mon Apr 23, 2012 6:01 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Apr 24, 2012 1:13 am Post subject: |
|
|
First, it's better and wise to use puthelp instead of putquick.
| Code: |
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: |
global hypno_status
set hypno_status 1
|
and then alter your loop like this:
| Code: |
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. |
|
| Back to top |
|
 |
tempest Voice
Joined: 23 Apr 2012 Posts: 6 Location: Australia
|
Posted: Tue Apr 24, 2012 2:22 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Tue Apr 24, 2012 8:58 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
tempest Voice
Joined: 23 Apr 2012 Posts: 6 Location: Australia
|
Posted: Tue Apr 24, 2012 9:39 am Post subject: |
|
|
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: |
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Tue Apr 24, 2012 9:53 am Post subject: |
|
|
| 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: |
utimer 3 [list puthelp "PRIVMSG $chan :$trance_line" ]
|
Reference:
http://www.eggheads.org/support/egghtml/1.6.21/tcl-commands.html
and
http://www.peterre.info/characters.html |
|
| Back to top |
|
 |
tempest Voice
Joined: 23 Apr 2012 Posts: 6 Location: Australia
|
Posted: Wed Apr 25, 2012 4:03 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Wed Apr 25, 2012 10:37 am Post subject: |
|
|
| 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.
| Quote: |
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.
| Quote: |
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/1.6.20/tcl-commands.html
With those three, you can do a LOT.
| Quote: |
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.
| Quote: |
*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. |
|
| Back to top |
|
 |
tempest Voice
Joined: 23 Apr 2012 Posts: 6 Location: Australia
|
Posted: Sat Apr 28, 2012 8:22 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
|
| Back to top |
|
 |
|