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.

need help for my pub command script

Help for those learning Tcl or writing their own scripts.
Post Reply
l
lenooxx
Voice
Posts: 27
Joined: Tue Mar 24, 2009 10:56 am
Location: Hungarian
Contact:

need help for my pub command script

Post by lenooxx »

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


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"
}
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

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: Select all

# 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
l
lenooxx
Voice
Posts: 27
Joined: Tue Mar 24, 2009 10:56 am
Location: Hungarian
Contact:

thx

Post by lenooxx »

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 ?
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

!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
l
lenooxx
Voice
Posts: 27
Joined: Tue Mar 24, 2009 10:56 am
Location: Hungarian
Contact:

thx

Post by lenooxx »

Thank you mate ^^ :)
Post Reply