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.
}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
}
###########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.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 }
Code: Select all
set sexmsg [join [randomline $sex]]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 $a
<sp33chy> Tcl: "hello"
basically, tclsh on the partyline.. enabling .tcl and .set allows combined usage and is nice.<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
Code: Select all
puthelp "privmsg $chan :[join [subst -nocommands $sexmsg]]" 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.<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{
Code: Select all
puthelp "privmsg $chan :[join [string map { " \{" " \\\{" " \{" " \\\}" } [subst -nocommands $sexmsg]]]"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...<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
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.<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 { "
Code: Select all
puthelp "privmsg $chan :[join [string map { " \{" " \\\{" " \{" " \\\}" " \"" " \\\"" } [subst -nocommands $sexmsg]]]"