2

目前我有一个 irc 机器人,当用户说出一个关键字时,例如 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 { }
4

1 回答 1

1

$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!
  }
}

编辑:修复了一个导致找不到更高值的问题,因为 %highestCookies 被分配了一个 $null 值而不是 0。


至于你的第二个问题,不同的频道不可能有不同的脚本文件。但是,您可以修改事件捕获器中的位置参数,使其仅捕获特定通道上的事件。例如,这就是 an 的on TEXT样子:

; This event will only listen to the word "hello" in #directpixel and #stackoverflow
on *:TEXT:hello:#directpixel,#stackoverflow:{
  msg $chan Hello $nick $+ !
}
于 2014-03-16T13:35:48.323 回答