The loop problem is indeed fixed in this new version.
I have some suggestions for you, to reduce the number of duplicate functions.
Instead of this for each filename:
Code: Select all
set mphtfile "/tmp/mphtcodes.txt"
if {![file exists $mphtfile]} {
catch {close [open $mphtfile w]}
}
Try something like:
Code: Select all
set filepath "/home/mybot/datafiles/"
set codefiles [list mpht mkds lsmg stfx]
foreach name $codefiles {
if {![file exists $filepath$name]} {
catch {close [open $filepath$name\codes.txt w]}
}
}
If you made $filepath a global variable, then people can change that one line and set the path to whatever they want more simply.
Actually, it's probably not even necessary to initialize the files in such a way, you can create them when needed in the procs that go to write them. But anyway..
You could also use lsearch to reduce the redundant sections in other proc's, for example:
Code: Select all
set command [lindex [split $arg] 0]
global filepath codefiles
# This assumes that $command is the same as the name of the codefile
# so, if you had a command called !add mpht, it'll match the filenames
if {[set myarg [lsearch $codefiles $command]] != -1} {
set gamer [string tolower $nick]
set code [lindex [split $arg] 1]
# $nick would never be "" if this is run from a public command
if {$code != ""} {
set fd [open $path$myarg\codes.txt r]
set list [split [read $fd] \n]
catch {close $fd}
# you should do an lsearch here for the nick, to prevent duplicates
set linecount -1
foreach line $list {
incr linecount
set nickf [lindex [split $line :] 0]
set codef [lindex [split $line :] 1]
if {$nickf == $gamer} {
# this is a matching line.. lreplace the data
set list [lreplace $list $linecount $linecount "$gamer:$code"]
} else {
set list [linsert $list end "$gamer:code"]
}
}
set fd [open $path$myarg\codes.txt w]
foreach line $list {
if {$line != ""}
puts $fd $line
}
}
catch {close $fd}
putquick "NOTICE $nick :^C$noticecolor Your code for ^B$acwwini^B has been added."
} else {
putquick "NOTICE $nick :^C$noticecolor Type '^B!add $acwwini <code>^B'"
}
}
That will also format your lines in such a way as to make it easier to parse them in other procs. The find:code proc would be very similar to the above, except it's only reading and comparing the lines, not writing to the file.
As far as the info: proc's, they could all be combined into 1 generic help proc, then just parse the arg for the option:
Code: Select all
bind pub - !gamehelp gamehelp
proc gamehelp {$nick uhost hand chan text} {
if {$text == "about"} {
puthelp "PRIVMSG $nick :About the script.."
} elseif {$text == "fcmenu"} {
puthelp "PRIVMSG $nick :so forth and so on"
} else {
puthelp "PRIVMSG $nick :I didn't understand that command, here's a summary of options:"
puthelp "PRIVMSG $nick :so forth and so on..."
}
}