目前我有一个irc bot,当用户说一个关键字,例如test1,他们得到+1添加到他们的计数,这是存储在一个文件中。但是我想知道谁的票数最多(谁赢了)。我认为像while循环这样的东西会起作用,寻找针对昵称的数字,不幸的是,虽然我的伪代码是正确的,但理论代码不是那么多。
这是我目前所掌握的。
on *:TEXT:!winning:#:{
var %i = 1, %highest = 0, %mycookie = $readini(cookies.ini,n,#,$nick)
while (%i < $lines(cookies.ini)) {
if (%mycookie > %highest) {
%highest = %mycookie
if (%highest == 1) {
msg $chan $nick is winning with %highest count. }
elseif (%highest > 1) {
msg $chan $nick is winning with %highest counts. }
else {
msg $chan No one has any count! Must try harder! }
}
else { return }
inc %i
}
}
我希望循环遍历文件,每当它发现比%highest(从0开始)更高的数字时,将其放入变量中,并移动到下一个名称。同样,我知道使用$nick是错误的,因为它将显示我的昵称,而不是从文件中抓取昵称…我能从文件中获取昵称吗?
感谢同样,在一个完全不相关的注释上。有没有一种方法在mIRC使用不同的脚本文件每个通道?比如:
if ($chan == #mychan) {
$remote == script1.ini }
else { }
可以使用$ini()
标识符循环遍历INI文件的内容。$ini(cookies.ini, $chan, 0)
将返回在该通道上有记录的人的总数,而$ini(cookies.ini, $chan, N)
将返回第n个人的名字(然后可以将其作为$readini()
中的最后一个参数传递)。
此外,不要在while循环中包含带有if/elseif/else结构的消息;您可能希望在找到最高记录后,将结果发送一次消息:
on *:TEXT:!winning:#:{
var %i = 1, %highestCookies = 0, %highestUser
; This will run as long as %i is smaller than or equal to the number of lines in the ini section $chan
while (%i <= $ini(cookies.ini, $chan, 0)) {
; As we loop through the file, store the item name (the nickname) and the cookies (the value)
var %user = $ini(cookies.ini, $chan, %i), %cookies = $readini(cookies.ini, n, $chan, %user)
; Is this the highest found so far?
if (%cookies > %highestCookies) {
var %highestCookies = %cookies
var %highestUser = %user
}
inc %i
}
; Now that we have the correct values in our variables, display the message once
if (%highestCookies == 1) {
msg $chan %highestUser is winning with %highestCookies count.
}
elseif (%highestCookies > 1) {
msg $chan %highestUser is winning with %highestCookies counts.
}
else {
msg $chan No one has any count! Must try harder!
}
}
Edit:修复了由于%highestCookies被分配了一个$null值而不是0而导致没有找到更高值的问题。
关于你的第二个问题,不同的通道不可能有不同的脚本文件。但是,您可以修改事件捕获程序中的location参数,以便它只捕获特定通道上的事件。作为一个例子,on TEXT
应该是这样的:
; This event will only listen to the word "hello" in #directpixel and #stackoverflow
on *:TEXT:hello:#directpixel,#stackoverflow:{
msg $chan Hello $nick $+ !
}