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.

Looking for a script or module to create custom commands

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
p
peec
Voice
Posts: 6
Joined: Fri Jan 06, 2006 12:18 pm

Looking for a script or module to create custom commands

Post by peec »

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

Post by Sir_Fz »

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
p
peec
Voice
Posts: 6
Joined: Fri Jan 06, 2006 12:18 pm

Cool - is ther a solution that everyone can do that?

Post by peec »

right now only the owner can successfully call !beer
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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
p
peec
Voice
Posts: 6
Joined: Fri Jan 06, 2006 12:18 pm

Works like a charm but ...

Post by peec »

is there a way to have addcommands write to a file and then read it from it?

I have no clues about Tcl.
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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
R-WaT
Halfop
Posts: 79
Joined: Fri Jan 06, 2006 7:45 pm

Post by R-WaT »

What would I add to remove a command? :)
R
R-WaT
Halfop
Posts: 79
Joined: Fri Jan 06, 2006 7:45 pm

Post by R-WaT »

This seems to crash to bot alot..

After adding commands, then doing ".rehash" to the bot, it will crash.

Whys that?
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

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
p
peec
Voice
Posts: 6
Joined: Fri Jan 06, 2006 12:18 pm

Debugging

Post by peec »

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

Post by Sir_Fz »

What Tcl error do you get? I assume it occurs when trying to source the saved file?
p
peec
Voice
Posts: 6
Joined: Fri Jan 06, 2006 12:18 pm

Errors when sourceing

Post by peec »

[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.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

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...
p
peec
Voice
Posts: 6
Joined: Fri Jan 06, 2006 12:18 pm

Works ....

Post by peec »

the quoting helped.

Thanks a lot everyone
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

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?
Post Reply