| View previous topic :: View next topic |
| Author |
Message |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Apr 23, 2006 2:33 am Post subject: !cmd pulled from txt file with timers |
|
|
I am trying to make something that does this....
Chatter: !cmd
Then bot grabs something from random out of the cmd.txt file
BUT the !cmd cannot be used again untill 60 seconds is up... it'll respond 'HEY wait 1 minute.'
caesar's scramble game script would do the trick if it didn't mix all the letters up lol... but since im still learning tcl I don't know what part to disable on that script... |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Apr 23, 2006 3:41 pm Post subject: |
|
|
Hi Sir,
I read those before posting but im trying to see if I can make it where you can only type !cmd once every 60secs instead of every 5 secs etc. Like if 60 secs wasn't up it would PM chatter and say 'Wait 60secs before reusing this cmd.'
thanks |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun Apr 23, 2006 6:16 pm Post subject: |
|
|
Yeah, that's why I linked to the 2nd topic. I've implemented the cmd in 20 seconds there (you can change it to 60). _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Mon Apr 24, 2006 4:14 pm Post subject: |
|
|
The way im looking at the script. it just stops that one person from re-using it right? Cause im trying to disable it for everyone at the same time till 60 secs is up...
Still trying to figure out how to combine the two scripts lol
thanks |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Mon Apr 24, 2006 4:33 pm Post subject: |
|
|
| Code: | set usedcmd [unixtime]
bind pub - !cmd cmd
proc cmd {nick uhost hand chan arg} {
global usedcmd
if {[unixtime]-$usedcmd < 60} {return 0}
set usedcmd [unixtime]
# do your stuff here.
} |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Mon Apr 24, 2006 5:33 pm Post subject: |
|
|
I gave this a try but I didn't get any errors
| Code: | #######
set sex "../data/whatever.txt"
set usedcmd [unixtime]
bind pub - !whatever cmd
proc cmd {nick uhost hand chan arg} {
global usedcmd
global sex
if {[unixtime]-$usedcmd < 60} {return 0}
set usedcmd [unixtime]
set sexmsg [string range [randomline $sex] 0 end]
puthelp "privmsg $chan :[subst -nocommands $sexmsg]"
}
proc randomline f {
set data [split [read [set file [open $f]]][close $file] \n]
set position [rand [llength $data]]
lindex $data $position
}
########### |
Any idea what im doing wrong?
thanks |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Mon Apr 24, 2006 6:25 pm Post subject: |
|
|
| Code: | set sex "../data/whatever.txt"
set usedcmd [expr {[unixtime]-60}]
bind pub - !whatever cmd
proc cmd {nick uhost hand chan arg} {
global usedcmd sex
if {[set t [expr {[unixtime]-$usedcmd}]] < 60} {
puthelp "privmsg $chan :You have to wait [expr {60-$t}] sec(s) before you can use this command."
return 0
}
set usedcmd [unixtime]
set sexmsg [randomline $sex]
puthelp "privmsg $chan :[subst -nocommands $sexmsg]"
}
proc randomline f {
set data [split [read [set file [open $f]]][close $file] \n]
set position [rand [llength $data]]
lindex $data $position
} |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Mon Apr 24, 2006 7:28 pm Post subject: |
|
|
Thanks that worked  |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Tue Jun 17, 2008 11:56 am Post subject: |
|
|
| Sir_Fz wrote: | | Code: | set sex "../data/whatever.txt"
set usedcmd [expr {[unixtime]-60}]
bind pub - !whatever cmd
proc cmd {nick uhost hand chan arg} {
global usedcmd sex
if {[set t [expr {[unixtime]-$usedcmd}]] < 60} {
puthelp "privmsg $chan :You have to wait [expr {60-$t}] sec(s) before you can use this command."
return 0
}
set usedcmd [unixtime]
set sexmsg [randomline $sex]
puthelp "privmsg $chan :[subst -nocommands $sexmsg]"
}
proc randomline f {
set data [split [read [set file [open $f]]][close $file] \n]
set position [rand [llength $data]]
lindex $data $position
} |
|
I like this script, anyway it can be changed to work with !whatever "text"? The " character displays as <Bot> does whatever to \"text\" adding those \ thingys. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Thu Jun 19, 2008 3:21 pm Post subject: |
|
|
| Code: | | set sexmsg [join [randomline $sex]] |
joining the line should eliminate the escape sequences, but might introduce other errors along the way. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Thu Jun 19, 2008 7:40 pm Post subject: |
|
|
| Sir_Fz wrote: | | The problem is probably with your text file. |
me: !whatever "Test"
bot: says whatever to Test
me: !whatever Test"
bot: says whatever to Test\"
I see it works if you use " " two rather than one, was hoping to strip on the accidental typo of one " that always gets me by the enter key lol |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Fri Jun 20, 2008 12:05 am Post subject: |
|
|
| Quote: | <speechles> .tcl set a "\"hello\""
<sp33chy> Tcl: "hello"
<speechles> .tcl set b [join $a]
<sp33chy> Tcl: hello
<speechles> .tcl set c $a
<sp33chy> Tcl: "hello" |
As I said above, [join] can help eradicate visibility of escapes, but the consequence is that it also removes other things (if they aren't over-escaped), such as double-quotes as evidenced above... | Quote: | <speechles> .tcl set a "\\\"hello\\\""
<sp33chy> Tcl: \"hello\"
<speechles> .tcl set b [join $a]
<sp33chy> Tcl: "hello"
<speechles> .tcl set c [join [join $a]]
<sp33chy> Tcl: hello | basically, tclsh on the partyline.. enabling .tcl and .set allows combined usage and is nice.
If it's simply over-escaped text, as you can see above, [join] removes the visible escape and keeps intact the double-quotes. It is usually better to find the source of the over-escaping (which most times is simply the result of using [split] or "tcl special character" filters (which simulate [split] escape behavior) when it isn't required) and correcting it before attempting to repair the damage done after the fact. But for a quick fix, it's fine, and this is exactly why you should be using [join] to solve it.
Note: Your subject line '!cmd pulled from txt file with timers' indicates use of timers. Timers usually involve setting parameters to [list] elements and this has the same escape behavior as using [split] does. If you mean timer as in throttling a users use of commands (by checking elapsed time) then this has nothing really to do with timers, ignore this note. In both cases, [join] is the answer. | Code: | | puthelp "privmsg $chan :[join [subst -nocommands $sexmsg]]" |
| Quote: | <speechles> .tcl set a [join [subst -nocommands "hello $::botnick {"]]
<sp33chy> Tcl error: unmatched open brace in list
<speechles> .tcl set a [join [subst -nocommands "hello $::botnick{"]]
<sp33chy> Tcl: hello sp33chy{ |
Unmatched open braces with spaces before them will crash this instantly. Afterall, we just want [join]s escape removing powers activated. [join] will see any unescaped curly bracings with leading spaces as list element fields and attempt to match and join them too, we don't want that. | Code: | | puthelp "privmsg $chan :[join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands $sexmsg]]]" |
| Quote: | <speechles> .tcl set a [join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands "hello $::botnick {"]]]
<sp33chy> Tcl: hello sp33chy {
<speechles> .tcl set a [join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands "hello $::botnick{"]]]
<sp33chy> Tcl: hello sp33chy{
<speechles> .tcl set a [join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands "hello $::botnick"]]]
<sp33chy> Tcl: hello sp33chy | This should work all combined, the string map will over-escape curly bracings if found (to stop [join] from trying to match list elements), then the [join] will remove all those over-escaped escapes, including the escapes on the curly bracings. The above is the code you should use...
...But to further everyone's knowledge, let's test those double-quotes.
| Quote: | <speechles> .tcl set b "\""
<sp33chy> Tcl: "
<speechles> .tcl set a [join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands "hello $::botnick $::b"]]]
<sp33chy> Tcl error: unmatched open quote in list
<speechles> .tcl set a [join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands "hello $::botnick$::b"]]]
<sp33chy> Tcl: hello sp33chy"
<speechles> .tcl set a [join [string map { " \{" " \\\{" " \{" " \\\}" " \"" " \\\"" } [subst -nocommands "hello $::botnick { $::b"]]]
<sp33chy> Tcl: hello sp33chy { " |
Now we've got it, over-escaping any double-quotes with leading spaces as well should do it. In your case this should already be happening as witnessed by yourself and is the entire reason for this excercise. The below code is only to be useful to those reading this for some learning experience. | Code: | | puthelp "privmsg $chan :[join [string map { " \{" " \\\{" " \{" " \\\}" " \"" " \\\"" } [subst -nocommands $sexmsg]]]" |
And even still, this code is not perfect (certain combinations of special characters will cause tcl errors and will need placement into the string map escape sequences, this will happen often and unpredictably). It can never be entirely safe. It can only temporarily fix a bad situation and make it a little better. The best solution is finding where the escapes are being generated and put a stop to it there rather than attempt to fix it with additional code. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Fri Jun 20, 2008 9:04 am Post subject: |
|
|
Thanks  |
|
| Back to top |
|
 |
|