Code: Select all
tag when posting logs, code
Code: Select all
set cmdsfile "scripts/cmds.txt"
if {![file exists $cmdsfile]} {
set fileid [open $cmdsfile w]
close $fileid
} {
source $cmdsfile
}
bind pub n !addcommand add:command
proc add:command {n u h c a} {
global addedcommands
set command [lindex [split $a] 0]
set action [join [lrange [split $a] 1 end]]
if {[info command added:$command] == ""} {
set addedcommands($command) $action
proc added:$command {n u h c a} {
global addedcommands
puthelp "privmsg $c :\001ACTION [string map [list %nick [lindex [split $a] 0]] $addedcommands($::lastbind)]\001"
}
bind pub - $command added:$command
save:command $command $action
puthelp "notice $n :Added add:$command command."
} {
puthelp "notice $n :Command added:$command already exists."
}
}
proc save:command {c act} {
global cmdsfile
set c [string map {\[ \\\[ \] \\\] \\ \\\\} $c]
set cmdlist [split [read [set f [open $cmdsfile]]] \n][close $f]
lappend cmdlist "bind pub - $c added:$c"
lappend cmdlist ""
lappend cmdlist "set addedcommands($c) [list $act]"
lappend cmdlist ""
set f [open $cmdsfile w]
foreach cmd $cmdlist {
puts $f $cmd
}
puts $f [printproc added:$c]
close $f
}
# user's proc from the Tcl faq forum
proc printproc proc {
set args {}
foreach arg [info args $proc] {
if {[info default $proc $arg val]} {
lappend args [list $arg $val]
} {
lappend args [list $arg]
}
}
list proc $proc $args [info body $proc]
}
Sir_Fz wrote:{$act} will save {$act} into the file which will cause all commands to reply with the word {$act} on command (literally {$act}) while [list $act] will save {the whole action here} in the file
$ cat bla.tcl
set act "hand %nick a beer"
set f [open "out" w]
set cmdlist {"command number 1" "command number 2"}
lappend cmdlist "set bla {$act}"
puts $f $cmdlist
close $f
$ tclsh bla.tcl
$ cat out
{command number 1} {command number 2} {set bla {hand %nick a beer}}
Code: Select all
tag when posting logs, code
Code: Select all
set cmdsfile "scripts/cmds.txt"
if {![file exists $cmdsfile]} {
set fileid [open $cmdsfile w]
close $fileid
} {
source $cmdsfile
}
set allcommands [list]
foreach donecmd [split [read [set fileid [open $cmdsfile]]][close $fileid] \n][unset fileid] {
if {[string match -nocase "bind pub - *" $donecmd]} {
lappend allcommands [lindex [split $donecmd] 3]
}
}
bind pub n !addcommand add:command
bind pub n !countcmds count:command
proc add:command {n u h c a} {
global addedcommands
set command [lindex [split $a] 0]
set action [join [lrange [split $a] 1 end]]
if {[info command added:$command] == ""} {
set addedcommands($command) $action
proc added:$command {n u h c a} {
global addedcommands
puthelp "privmsg $c :\001ACTION [string map [list %nick [lindex [split $a] 0]] $addedcommands($::lastbind)]\001"
}
bind pub - $command added:$command
save:command $command $action
puthelp "notice $n :Added add:$command command."
} {
puthelp "notice $n :Command added:$command already exists."
}
}
proc count:command {n u h c a} {
global allcommands
if {[llength $allcommands]} {
puthelp "privmsg $c :Available commands: [join $allcommands]"
} {
puthelp "privmsg $c :No commands available."
}
}
proc save:command {c act} {
global cmdsfile
set c [string map {\[ \\\[ \] \\\] \\ \\\\} $c]
set cmdlist [split [read [set f [open $cmdsfile]]] \n][close $f]
lappend cmdlist "bind pub - $c added:$c"
lappend cmdlist ""
lappend cmdlist "set addedcommands($c) [list $act]"
lappend cmdlist ""
set f [open $cmdsfile w]
foreach cmd $cmdlist {
puts $f $cmd
}
puts $f [printproc added:$c]
close $f
}
# user's proc from the Tcl faq forum
proc printproc proc {
set args {}
foreach arg [info args $proc] {
if {[info default $proc $arg val]} {
lappend args [list $arg $val]
} {
lappend args [list $arg]
}
}
list proc $proc $args [info body $proc]
}
Very nice script Sir_Fz, but is it possible to unbind them.. because removing the cmds.txt or clearing it doesn't seem to do the trickSir_Fz wrote:Try:type !countcmds on chan.Code: Select all
set cmdsfile "scripts/cmds.txt" if {![file exists $cmdsfile]} { set fileid [open $cmdsfile w] close $fileid } { source $cmdsfile } set allcommands [list] foreach donecmd [split [read [set fileid [open $cmdsfile]]][close $fileid] \n][unset fileid] { if {[string match -nocase "bind pub - *" $donecmd]} { lappend allcommands [lindex [split $donecmd] 3] } } bind pub n !addcommand add:command bind pub n !countcmds count:command proc add:command {n u h c a} { global addedcommands set command [lindex [split $a] 0] set action [join [lrange [split $a] 1 end]] if {[info command added:$command] == ""} { set addedcommands($command) $action proc added:$command {n u h c a} { global addedcommands puthelp "privmsg $c :\001ACTION [string map [list %nick [lindex [split $a] 0]] $addedcommands($::lastbind)]\001" } bind pub - $command added:$command save:command $command $action puthelp "notice $n :Added add:$command command." } { puthelp "notice $n :Command added:$command already exists." } } proc count:command {n u h c a} { global allcommands if {[llength $allcommands]} { puthelp "privmsg $c :Available commands: [join $allcommands]" } { puthelp "privmsg $c :No commands available." } } proc save:command {c act} { global cmdsfile set c [string map {\[ \\\[ \] \\\] \\ \\\\} $c] set cmdlist [split [read [set f [open $cmdsfile]]] \n][close $f] lappend cmdlist "bind pub - $c added:$c" lappend cmdlist "" lappend cmdlist "set addedcommands($c) [list $act]" lappend cmdlist "" set f [open $cmdsfile w] foreach cmd $cmdlist { puts $f $cmd } puts $f [printproc added:$c] close $f } # user's proc from the Tcl faq forum proc printproc proc { set args {} foreach arg [info args $proc] { if {[info default $proc $arg val]} { lappend args [list $arg $val] } { lappend args [list $arg] } } list proc $proc $args [info body $proc] }
Code: Select all
set cmdsfile "scripts/cmds.txt"
if {![file exists $cmdsfile]} {
set fileid [open $cmdsfile w]
close $fileid
} {
source $cmdsfile
}
set allcommands [list]
foreach donecmd [split [read [set fileid [open $cmdsfile]]][close $fileid] \n][unset fileid] {
if {[string match -nocase "bind pub - *" $donecmd]} {
lappend allcommands [lindex [split $donecmd] 3]
}
}
bind pub n !addcommand add:command
bind pub n !countcmds count:command
bind pub n !delcommand del:command
proc add:command {n u h c a} {
global addedcommands
set command [string tolower [lindex [split $a] 0]]
set action [join [lrange [split $a] 1 end]]
if {[info command added:$command] == ""} {
set addedcommands($command) $action
proc added:$command {n u h c a} {
global addedcommands
puthelp "privmsg $c :\001ACTION [string map [list %nick [lindex [split $a] 0]] $addedcommands($::lastbind)]\001"
}
bind pub - $command added:$command
save:command $command $action
puthelp "notice $n :Added add:$command command."
} {
puthelp "notice $n :Command added:$command already exists."
}
}
proc count:command {n u h c a} {
global allcommands
if {[llength $allcommands]} {
puthelp "privmsg $c :Available commands: [join $allcommands]"
} {
puthelp "privmsg $c :No commands available."
}
}
proc del:command {n u h c a} {
global allcommands
set cmd [string tolower [lindex [split $a] 0]]
if {![catch {unbind pub - $cmd added:$cmd}]} {
if {[set i [lsearch -exact $allcommands $cmd]] != -1} {
set allcommands [lreplace $allcommands $i $i]
}
puthelp "notice $n :Successfully remove \002$cmd\002 PUB command."
} {
puthelp "notice $n :Command \002$cmd\002 does not exist."
}
}
proc save:command {c act} {
global cmdsfile
set c [string map {\[ \\\[ \] \\\] \\ \\\\} $c]
set cmdlist [split [read [set f [open $cmdsfile]]] \n][close $f]
lappend cmdlist "bind pub - $c added:$c"
lappend cmdlist ""
lappend cmdlist "set addedcommands($c) [list $act]"
lappend cmdlist ""
set f [open $cmdsfile w]
foreach cmd $cmdlist {
puts $f $cmd
}
puts $f [printproc added:$c]
close $f
}
# user's proc from the Tcl faq forum
proc printproc proc {
set args {}
foreach arg [info args $proc] {
if {[info default $proc $arg val]} {
lappend args [list $arg $val]
} {
lappend args [list $arg]
}
}
list proc $proc $args [info body $proc]
}
<SuMiT>!addcommand !testing %nick is testing
<SuMiT>!testing
-CuteBangla- Added add:!testing command.
*CuteBangla SuMiT is testing
pavel_kbc wrote:<x-r00t-x> !addcommand testing PRIVMSG x-r00t-x testing
-lord- Added add:testing command.
<x-r00t-x> testing
* lord PRIVMSG x-r00t-x testing
Please help meee (
how do i fix it ?