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.
Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
peec
Voice
Posts: 6 Joined: Fri Jan 06, 2006 12:18 pm
Post
by peec » Fri Jan 06, 2006 12:23 pm
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
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Fri Jan 06, 2006 12:49 pm
This belongs in the scripts requests forum.
Code: Select all
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:
<owner> !addcommand !beer brings %nick a nice cold beer
<owner> !beer MrX
* bot brings MrX a nice cold beer
peec
Voice
Posts: 6 Joined: Fri Jan 06, 2006 12:18 pm
Post
by peec » Fri Jan 06, 2006 1:27 pm
right now only the owner can successfully call !beer
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Fri Jan 06, 2006 1:37 pm
Yeah that's because I limited it to flag n. If you want anyone to use it then replace
Code: Select all
bind pub n $command added:$command
with
Code: Select all
bind pub - $command added:$command
peec
Voice
Posts: 6 Joined: Fri Jan 06, 2006 12:18 pm
Post
by peec » Fri Jan 06, 2006 1:59 pm
is there a way to have addcommands write to a file and then read it from it?
I have no clues about Tcl.
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Fri Jan 06, 2006 8:20 pm
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 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.
Last edited by
Sir_Fz on Sun Jan 08, 2006 10:14 am, edited 1 time in total.
R-WaT
Halfop
Posts: 79 Joined: Fri Jan 06, 2006 7:45 pm
Post
by R-WaT » Fri Jan 06, 2006 9:48 pm
What would I add to remove a command?
R-WaT
Halfop
Posts: 79 Joined: Fri Jan 06, 2006 7:45 pm
Post
by R-WaT » Fri Jan 06, 2006 9:55 pm
This seems to crash to bot alot..
After adding commands, then doing ".rehash" to the bot, it will crash.
Whys that?
Alchera
Revered One
Posts: 3344 Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:
Post
by Alchera » Fri Jan 06, 2006 10:08 pm
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
peec
Voice
Posts: 6 Joined: Fri Jan 06, 2006 12:18 pm
Post
by peec » Sat Jan 07, 2006 6:37 am
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
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sat Jan 07, 2006 10:48 am
What Tcl error do you get? I assume it occurs when trying to source the saved file?
peec
Voice
Posts: 6 Joined: Fri Jan 06, 2006 12:18 pm
Post
by peec » Sun Jan 08, 2006 6:31 am
[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.
De Kus
Revered One
Posts: 1361 Joined: Sun Dec 15, 2002 11:41 am
Location: Germany
Post
by De Kus » Sun Jan 08, 2006 9:55 am
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...
peec
Voice
Posts: 6 Joined: Fri Jan 06, 2006 12:18 pm
Post
by peec » Sun Jan 08, 2006 10:04 am
the quoting helped.
Thanks a lot everyone
spock
Master
Posts: 319 Joined: Thu Dec 12, 2002 8:40 pm
Post
by spock » Sun Jan 08, 2006 2:59 pm
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?