| View previous topic :: View next topic |
| Author |
Message |
lenooxx Voice
Joined: 24 Mar 2009 Posts: 27 Location: Hungarian
|
Posted: Sun Oct 11, 2009 10:43 am Post subject: need help for my pub command script |
|
|
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"
} |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Oct 11, 2009 12:20 pm Post subject: |
|
|
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 |
|
 |
lenooxx Voice
Joined: 24 Mar 2009 Posts: 27 Location: Hungarian
|
Posted: Sun Oct 11, 2009 12:51 pm Post subject: thx |
|
|
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 |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Oct 11, 2009 1:04 pm Post subject: |
|
|
!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 |
|
 |
lenooxx Voice
Joined: 24 Mar 2009 Posts: 27 Location: Hungarian
|
Posted: Sun Oct 11, 2009 5:50 pm Post subject: thx |
|
|
Thank you mate ^^  |
|
| Back to top |
|
 |
|