# script rank.tcl
# version 0.1
# settings
set rank(top) 5
set rank(time) 10
# binds
bind pub - !rank pub:rank
# rank proc
proc pub:rank {nick uhost hand chan arg} {
global rank
# set
set topic [lindex $arg 0]
set points [lindex $arg 1]
# help
if {![llength $arg] == 1} {
putserv "PRIVMSG $chan :Usage: !rank <topic> <1 to 5>"
return }
# topics list
if {$points > $rank(top) || $points == 0} {
putserv "PRIVMSG $chan :Ranks available betwen \0020\002 and \002$rank(top)\002."
return }
# count
if {![info exists rank($uhost:$chan)]} {
set rank($uhost:$chan) 0 }
# retopice array
utimer $rank(time) "array unset rank $uhost:$chan"
# already topicd
if {$rank($uhost:$chan) > 0} {
putserv "PRIVMSG $chan :Only one \002!rank\002 per hour. Please try again later."
return }
# for & fix
for {set no 1} {$no<$rank(top)} {incr no} {
#fix
if {![info exists rank($topic:$points)]} {
set rank([lindex $arg 0]:$points) 0 }
}
incr rank($topic:$points)
incr rank($uhost:$chan)
# tell
if {$points > 1} {
putserv "PRIVMSG $chan :You have ranked topic number \002$topic\002 with \002$points\002 points. Thank you!"
} else {
putserv "PRIVMSG $chan :You have ranked topic number \002$topic\002 with \002$points\002 point. Thank you!" }
return }
putlog "rank.tcl loaded.."
eg. '!rank 1 1' results in a array like this: 1:1 1 (topic-number:rank number of times he was ranked with 1). How can I write this result in a file like this: 'topic 1:1 1' and on another '!rank 1 1' should read and write in the file '1:1 2', I mean read and increase it's value. Also on a '!rank 1 2' to write another line in the file: 'topic 1:2 1' and so on.. Any sugestions to do so?
Once the game is over, the king and the pawn go back in the same box.
emm...
are you sure you want it to read and write every time someone does that command? I have the feeling the bot will be lagged if it is used heavily
anyway... open the file for reading, do a while loop on it and put all the lines NOT matching $arg into a list just as they are, the one matching $arg you split to get the "rank" and then do a incr on that and put it into the list aswell, finally close the file, reopen it using [open $file w] and put the whole list into it.. of course you can use lsort or something like that on it to make the file nice and clean-looking