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.

!cmd pulled from txt file with timers

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

!cmd pulled from txt file with timers

Post by cache »

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...
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

See this and this (at the bottom).
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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).
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

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.
}
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

I gave this a try but I didn't get any errors :oops:

Code: Select all

#######
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
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

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
}
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Thanks that worked :D
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Sir_Fz wrote:

Code: Select all

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.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

The problem is probably with your text file.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

 set sexmsg [join [randomline $sex]]
joining the line should eliminate the escape sequences, but might introduce other errors along the way.
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

<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.

    Code: Select all

    puthelp "privmsg $chan :[join [subst -nocommands $sexmsg]]" 
    <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: Select all

    puthelp "privmsg $chan :[join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands $sexmsg]]]"
    <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.
    <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: Select all

    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.
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Thanks :)
Post Reply