egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Looking for a script or module to create custom commands
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
peec
Voice


Joined: 06 Jan 2006
Posts: 6

PostPosted: Fri Jan 06, 2006 12:23 pm    Post subject: Looking for a script or module to create custom commands Reply with quote

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
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Jan 06, 2006 12:49 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
peec
Voice


Joined: 06 Jan 2006
Posts: 6

PostPosted: Fri Jan 06, 2006 1:27 pm    Post subject: Cool - is ther a solution that everyone can do that? Reply with quote

right now only the owner can successfully call !beer
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Jan 06, 2006 1:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
peec
Voice


Joined: 06 Jan 2006
Posts: 6

PostPosted: Fri Jan 06, 2006 1:59 pm    Post subject: Works like a charm but ... Reply with quote

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
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Jan 06, 2006 8:20 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
R-WaT
Halfop


Joined: 06 Jan 2006
Posts: 79

PostPosted: Fri Jan 06, 2006 9:48 pm    Post subject: Reply with quote

What would I add to remove a command? Smile
Back to top
View user's profile Send private message AIM Address
R-WaT
Halfop


Joined: 06 Jan 2006
Posts: 79

PostPosted: Fri Jan 06, 2006 9:55 pm    Post subject: Reply with quote

This seems to crash to bot alot..

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

Whys that?
Back to top
View user's profile Send private message AIM Address
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Fri Jan 06, 2006 10:08 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
peec
Voice


Joined: 06 Jan 2006
Posts: 6

PostPosted: Sat Jan 07, 2006 6:37 am    Post subject: Debugging Reply with quote

thank you very much for the script. I even start to understand it Smile

It sometimes works and sometimes not. How can I debug eggdrop scripts?

Is ther any documentation?

Peter
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Jan 07, 2006 10:48 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
peec
Voice


Joined: 06 Jan 2006
Posts: 6

PostPosted: Sun Jan 08, 2006 6:31 am    Post subject: Errors when sourceing Reply with quote

[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
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sun Jan 08, 2006 9:55 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
peec
Voice


Joined: 06 Jan 2006
Posts: 6

PostPosted: Sun Jan 08, 2006 10:04 am    Post subject: Works .... Reply with quote

the quoting helped.

Thanks a lot everyone
Back to top
View user's profile Send private message
spock
Master


Joined: 12 Dec 2002
Posts: 319

PostPosted: Sun Jan 08, 2006 2:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber