| View previous topic :: View next topic |
| Author |
Message |
peec Voice
Joined: 06 Jan 2006 Posts: 6
|
Posted: Fri Jan 06, 2006 12:23 pm Post subject: Looking for a script or module to create custom commands |
|
|
Would need a script which allows to creat commands like
!beer nick
with a response
The_Bartender brings nick a nice cold beer
Have seen this often but am unable to find an example script
or a final solution for that problem.
Have a nice day
Peter |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Jan 06, 2006 12:49 pm Post subject: |
|
|
This belongs in the scripts requests forum.
| Code: | 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]]
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 n $command added:$command
} |
Example:
| Quote: | <owner> !addcommand !beer brings %nick a nice cold beer
<owner> !beer MrX
* bot brings MrX a nice cold beer |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
peec Voice
Joined: 06 Jan 2006 Posts: 6
|
Posted: Fri Jan 06, 2006 1:27 pm Post subject: Cool - is ther a solution that everyone can do that? |
|
|
| right now only the owner can successfully call !beer |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Jan 06, 2006 1:37 pm Post subject: |
|
|
Yeah that's because I limited it to flag n. If you want anyone to use it then replace
| Code: | | bind pub n $command added:$command |
with
| Code: | | bind pub - $command added:$command |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
peec Voice
Joined: 06 Jan 2006 Posts: 6
|
Posted: Fri Jan 06, 2006 1:59 pm Post subject: Works like a charm but ... |
|
|
is there a way to have addcommands write to a file and then read it from it?
I have no clues about Tcl. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Jan 06, 2006 8:20 pm Post subject: |
|
|
| Code: | 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 cmdlist [split [read [set f [open $cmdsfile]]] \n][close $f]
lappend cmdlist "bind pub - $c added:$c"
lappend cmdlist ""
lappend cmdlist "set addedcommands($c) \"$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]
} |
Edit: Fixed bug as pointed by De Kus. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts
Last edited by Sir_Fz on Sun Jan 08, 2006 10:14 am; edited 1 time in total |
|
| Back to top |
|
 |
R-WaT Halfop
Joined: 06 Jan 2006 Posts: 79
|
Posted: Fri Jan 06, 2006 9:48 pm Post subject: |
|
|
What would I add to remove a command?  |
|
| Back to top |
|
 |
R-WaT Halfop
Joined: 06 Jan 2006 Posts: 79
|
Posted: Fri Jan 06, 2006 9:55 pm Post subject: |
|
|
This seems to crash to bot alot..
After adding commands, then doing ".rehash" to the bot, it will crash.
Whys that? |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Fri Jan 06, 2006 10:08 pm Post subject: |
|
|
| R-WaT wrote: | This seems to crash to bot alot..
After adding commands, then doing ".rehash" to the bot, it will crash.
Whys that? |
If you you bother to read the logs or pay attention whilst in the Command Console you will see why; many errors are very descriptive. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
peec Voice
Joined: 06 Jan 2006 Posts: 6
|
Posted: Sat Jan 07, 2006 6:37 am Post subject: Debugging |
|
|
thank you very much for the script. I even start to understand it
It sometimes works and sometimes not. How can I debug eggdrop scripts?
Is ther any documentation?
Peter |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Jan 07, 2006 10:48 am Post subject: |
|
|
What Tcl error do you get? I assume it occurs when trying to source the saved file? _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
peec Voice
Joined: 06 Jan 2006 Posts: 6
|
Posted: Sun Jan 08, 2006 6:31 am Post subject: Errors when sourceing |
|
|
[11:21] wrong # args: should be "set varName ?newValue?"
while executing
"set addedcommands(ale) walks to %nick. Offers a cold ale."
(file "scripts/cmds.txt" line 3)
invoked from within
"source $cmdsfile"
invoked from within
"if {![file exists $cmdsfile]} {
set fileid [open $cmdsfile w]
close $fileid
} {
source $cmdsfile
}"
(file "scripts/addcommands.tcl" line 3)
invoked from within
"source scripts/addcommands.tcl"
(file "bot.conf" line 1345)
[11:21] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
----
I can add commands but they will not work. In my first test
at least the first command worked. |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sun Jan 08, 2006 9:55 am Post subject: |
|
|
try to replace
lappend cmdlist "set addedcommands($c) $act"
with
lappend cmdlist "set addedcommands($c) \"$act\"" _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
peec Voice
Joined: 06 Jan 2006 Posts: 6
|
Posted: Sun Jan 08, 2006 10:04 am Post subject: Works .... |
|
|
the quoting helped.
Thanks a lot everyone |
|
| Back to top |
|
 |
spock Master
Joined: 12 Dec 2002 Posts: 319
|
Posted: Sun Jan 08, 2006 2:59 pm Post subject: |
|
|
just be careful not to let anyone other than owners have access to !addcommand, unless you want them to execute tcl commands at will.
making commands such as ![whatever], which will execute the command "whatever", worst case scenario, they ![die] and no real harm done.
with dekus' fix, unrestricted access is granted.
i.e !addcommand !foo [adduser bar *!foo@bar; chattr bar +n ; setuser bar PASS bla]
or even worse !addcommand !foo [exec ...]
they will be executed upon rehash or restart.
i suggest
lappend cmdlist "set addedcommands($c) {$act}"
to remedy this issue (if it is one, that is)
owners can in most cases execute whatever regardless of the script being loaded, so if you leave it bound to n, i suppose its all good. _________________ photon? |
|
| Back to top |
|
 |
|