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 

need help for my pub command script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
lenooxx
Voice


Joined: 24 Mar 2009
Posts: 27
Location: Hungarian

PostPosted: Sun Oct 11, 2009 10:43 am    Post subject: need help for my pub command script Reply with quote

How can i creat addaccomand , list , remove commands? please help me Thank you Smile


bind pub - !command pub:command
bind pub w !addcommand pub:addcommand

proc pub:addcommand { nick uhost handle channel arg } {
if { $arg == "" } {
putserv "NOTICE $nick :USAGE: !addcommand <command>"
return 0
}
set command [open "command.txt" a]
puts $command "$arg"
close $command
putserv "NOTICE $nick :Command Added"
}

proc pub:command { nick uhost handle channel arg } {
set commandfile [open "command.txt" r]
set i 0
while { [eof $commandfile] != 1 } {
incr i 1
set command($i) [gets $commandfile]
}
set w [rand $i]
set outcommand $command($w)
putserv "PRIVMSG $channel :$outcommand"
}
Back to top
View user's profile Send private message Visit poster's website
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Oct 11, 2009 12:20 pm    Post subject: Reply with quote

As long as the saved data isn't overly large, I find it better to keep it in memory and only write it after changes. I have done a limited amount of testing on the following script. It could be used to save/display any text.

Code:

# command.tcl

# set here the single character command trigger
set vCommandTrigger !

# set here the bot user flag(s) required to add/delete commands
set vCommandFlag n

proc pCommandTrigger {} {
    global vCommandTrigger
    return $vCommandTrigger
}

bind EVNT - init-server pCommandInit
bind EVNT - rehash pCommandInit

proc pCommandInit {type} {
    pCommandRead
    return 0
}

bind PUB $vCommandFlag [pCommandTrigger]addcommand pCommandAdd
bind PUB $vCommandFlag [pCommandTrigger]delcommand pCommandDel

bind PUB - [pCommandTrigger]command pCommandRand
bind PUB - [pCommandTrigger]listcommand pCommandList

proc pCommandAdd {nick uhost hand chan text} {
    global vCommandData
    set command [string trim $text]
    if {[string length $command] != 0} {
        if {[lsearch -exact [string tolower $vCommandData] [string tolower $command]] == -1} {
            lappend vCommandData $command
            putserv "NOTICE $nick :command $command added"
            pCommandWrite
        } else {putserv "NOTICE $nick :The command $command already exists"}
    }  else {putserv "NOTICE $nick :Usage [pCommandTrigger]addcommand <command>"}
    return 0
}

proc pCommandDel {nick uhost hand chan text} {
    global vCommandData
    set command [string trim $text]
    if {[string length $command] != 0} {
        if {[llength $vCommandData] != 0} {
            if {[set position [lsearch -exact [string tolower $vCommandData] [string tolower $command]]] != -1} {
                set vCommandData [lreplace $vCommandData $position $position]
                putserv "NOTICE $nick :command $command deleted"
                pCommandWrite
            } else {putserv "NOTICE $nick :The command $command is not currently on file"}
        } else {putserv "NOTICE $nick :There are no commands currently on file"}
    }  else {putserv "NOTICE $nick :Usage [pCommandTrigger]delcommand <command>"}
    return 0
}

proc pCommandRand {nick uhost hand chan text} {
    global vCommandData
    set command [string trim $text]
    if {[string length $command] == 0} {
        if {[llength $vCommandData] != 0} {
            putserv "PRIVMSG $chan :[lindex $vCommandData [rand [llength $vCommandData]]]"
        } else {putserv "NOTICE $nick :There are no commands currently on file"}
    }  else {putserv "NOTICE $nick :Usage [pCommandTrigger]command without additional arguments"}
    return 0
}

proc pCommandList {nick uhost hand chan text} {
    global vCommandData
    set command [string trim $text]
    if {[string length $command] == 0} {
        if {[llength $vCommandData] != 0} {
            foreach element $vCommandData {
                putserv "NOTICE $nick :$element"
            }
        } else {putserv "NOTICE $nick :There are no commands currently on file"}
    } else {putserv "NOTICE $nick :Usage [pCommandTrigger]listcommand without additional arguments"}
    return 0
}

proc pCommandRead {} {
    global vCommandData
    if {[file exists command.txt]} {
        set id [open command.txt r]
        set vCommandData [split [read -nonewline $id] \n]
        close $id
    } else {
        set vCommandData {}
        pCommandWrite
    }
    return 0
}

proc pCommandWrite {} {
    global vCommandData
    set id [open command.txt w]
    if {[llength $vCommandData] != 0} {
        puts -nonewline $id [join $vCommandData \n]
    }
    close $id
    return 0
}

putlog "command.tcl loaded"

# eof

_________________
I must have had nothing to do
Back to top
View user's profile Send private message
lenooxx
Voice


Joined: 24 Mar 2009
Posts: 27
Location: Hungarian

PostPosted: Sun Oct 11, 2009 12:51 pm    Post subject: thx Reply with quote

Thank you mate !

i added some command , but
strange when i typed !command

i get only one command :s how I can receive the list what I added ?
Back to top
View user's profile Send private message Visit poster's website
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Oct 11, 2009 1:04 pm    Post subject: Reply with quote

!addcommand == add a command
!delcommand == delete a command
!listcommand == list all commands
!command == output a random command

make sure you deleted any command.txt from your earlier scripting efforts
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
lenooxx
Voice


Joined: 24 Mar 2009
Posts: 27
Location: Hungarian

PostPosted: Sun Oct 11, 2009 5:50 pm    Post subject: thx Reply with quote

Thank you mate ^^ Smile
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 -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
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