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...
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.'
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
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.
}
#######
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
}
###########
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
}
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.
<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...
<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
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.
<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.
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.
<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.
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.