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 Previous  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
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sun Jan 08, 2006 4:39 pm    Post subject: Reply with quote

{$act} should be [list $act] but anyway, the whole thing is better implemented with static code structure, i.e. no fancy reloading of generated code
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
spock
Master


Joined: 12 Dec 2002
Posts: 319

PostPosted: Sun Jan 08, 2006 6:49 pm    Post subject: Reply with quote

i dont think you need [list] in this case, but feel free to prove me wrong (be gentle Smile)
_________________
photon?
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Jan 08, 2006 9:05 pm    Post subject: Reply with quote

{$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, which will not cause security risks. Thanx for the notice there spock. More secure code:
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 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]
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
spock
Master


Joined: 12 Dec 2002
Posts: 319

PostPosted: Sun Jan 08, 2006 9:39 pm    Post subject: Reply with quote

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

Quote:

$ 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}}

_________________
photon?
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Mon Jan 09, 2006 3:40 am    Post subject: Reply with quote

that's right, the quotes provide you with necessary 1 level of variable evaluation, and nested quotes (double eval) is a no-no
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Jan 09, 2006 6:01 am    Post subject: Reply with quote

Ah yeah true, will be more aware next time Very Happy
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
CuteBangla
Halfop


Joined: 27 Feb 2006
Posts: 58
Location: Dhaka, Bangladesh

PostPosted: Wed Mar 29, 2006 12:03 am    Post subject: Re Reply with quote

sop whats ta final result?
_________________
SuMiT
iRC.CuteBangla.Com
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Mar 29, 2006 6:17 am    Post subject: Reply with quote

If you read through the post, you would've noticed that the last code I posted works as asked.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
CuteBangla
Halfop


Joined: 27 Feb 2006
Posts: 58
Location: Dhaka, Bangladesh

PostPosted: Wed Mar 29, 2006 8:06 am    Post subject: Re Add command module Reply with quote

is there any way to show all the command that added in bot by this module
_________________
SuMiT
iRC.CuteBangla.Com
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Mar 29, 2006 5:22 pm    Post subject: Reply with quote

Try:
Code:
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]
}

type !countcmds on chan.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
dq
Voice


Joined: 03 Apr 2006
Posts: 32

PostPosted: Sun Jun 11, 2006 8:00 pm    Post subject: Reply with quote

Sir_Fz wrote:
Try:
Code:
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]
}

type !countcmds on chan.


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 trick Sad
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Jun 12, 2006 9:06 am    Post subject: Reply with quote

Code:
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]
}

This will unbind the command if it exists (will make it unfunctional) but will not remove it from the .txt (you'll have to remove it manually).

Edit: Fixed missing " and bug in using [lsearch].
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts


Last edited by Sir_Fz on Fri Dec 29, 2006 4:40 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
dq
Voice


Joined: 03 Apr 2006
Posts: 32

PostPosted: Fri Jun 16, 2006 1:56 pm    Post subject: Reply with quote

Looking good Sir_Fz, you've done it again! haha

Anyway we can include flood protection so we don't get kids constantly typing .bindhere and the bot trying to respond?
Back to top
View user's profile Send private message
pavel_kbc
Voice


Joined: 28 Dec 2006
Posts: 23

PostPosted: Fri Dec 29, 2006 9:27 am    Post subject: Reply with quote

<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 Sad(

how do i fix it ?
Back to top
View user's profile Send private message
CuteBangla
Halfop


Joined: 27 Feb 2006
Posts: 58
Location: Dhaka, Bangladesh

PostPosted: Fri Dec 29, 2006 9:35 am    Post subject: Reply with quote

Use the Command like

Quote:
<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 Sad(

how do i fix it ?

_________________
SuMiT
iRC.CuteBangla.Com
Back to top
View user's profile Send private message Visit poster's website
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 Previous  1, 2, 3  Next
Page 2 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