0

所以我正在尝试通过 mIRC 构建我的 twitch 机器人,我一直希望它为每个站点的链接超时,但来自http://osu.ppy.sh/的任何链接和来自http://puu.sh/的任何链接除外阻止其他任何东西。

我找到了脚本和教程,但是我找不到任何解释如何足够详细地解释异常的每个部分的异常的东西,我也找不到任何在异常中包含这些域的东西

这是我的旧链接保护脚本

on @*:text:*:#:linkpost $1-
on @*:action:*:#:linkpost $1-
on @*:notice:*:#:linkpost $1-
alias -l linkpost {
  if ((!%p) && (!$hfind(permit,$nick))) { inc -u4 %p
    var %purge /^!(link\so(n|ff)|(permit))\b/iS
    var %domain com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk
    var %link /(?<=^|\s)((?>\S{3,8}:\/\/|w{3}\56)\S+)|\56( $+ %domain $+ )\b/iS
    if ($findtok(%chanon1,#,1,32)) && ($nick(#,$nick,vr)) && ($regex($1-,%link)) {
      timeout # $nick | /mode # -b $nick
      msg # $nick You did not have permission to post a link ask a mod to !permit you
      msg # /timeout $nick 1
    }
    elseif (($regex($1-,%purge)) && ($regml(1) = permit) && ($nick isop #) && ($$2 ison #)) {
      hadd -mz permit $v1 30 | notice $v1 You have 30 seconds to post a link. Starting now!
      msg # You now have 30 seconds to post a link!
    }
    elseif (($regml(1) = link on) && ($nick isop #)) {
      goto $iif(!$istok(%chanon1,#,32),a,b) | :a | set %chanon1 $addtok(%chanon,#,32)
      .msg # My Link Protection Is Now on in: $+($chr(2),#)
      halt | :b | .msg # $nick $+ , my link protection is already on in $&
        $+($chr(2),#,$chr(2)) !
    }
    elseif (($regml(1) = link off) && ($nick isop #)) {
      goto $iif($istok(%chanon1,#,32),c,d) | :c | set %chanon1 $remtok(%chanon,#,1,32)
      .msg # My Link Protection Is Now off in: $+($chr(2),#)
      halt | :d | .msg # $nick $+ , My link protection is already off . $&
        !
    }
  }
}

任何将不胜感激,目前该机器人没有其他命令或脚本。

修改后的代码

on @*:text:*:#:linkpost $1-
on @*:action:*:#:linkpost $1-
on @*:notice:*:#:linkpost $1-
alias -l linkpost {
  if ((!%p) && (!$hfind(permit,$nick))) { inc -u4 %p
    var %purge /^!(link\so(n|ff)|(permit))\b/iS
    var %domain com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk
    var %link /(?<=^|\s)((?>\S{3,8}:\/\/|w{3}\56)\S+)|\56( $+ %domain $+ )\b/iS
    var %whitelistPattern = /.*http:\/\/(osu.ppy.sh|puu.sh)\/.*/i
    if (!$regex($1-, %whitelistPattern)) {
      return
    }
    if ($findtok(%chanon1,#,1,32)) && ($nick(#,$nick,vr)) && ($regex($1-,%link)) {
      timeout # $nick | /mode # -b $nick
      msg # $nick You did not have permission to post a link ask a mod to !permit you
      msg # /timeout $nick 1
    }
    elseif (($regex($1-,%purge)) && ($regml(1) = permit) && ($nick isop #) && ($$2 ison #)) {
      hadd -mz permit $v1 30 | notice $v1 You have 30 seconds to post a link. Starting now!
      msg # You now have 30 seconds to post a link!
    }
    elseif (($regml(1) = link on) && ($nick isop #)) {
      goto $iif(!$istok(%chanon1,#,32),a,b) | :a | set %chanon1 $addtok(%chanon,#,32)
      .msg # My Link Protection Is Now on in: $+($chr(2),#)
      halt | :b | .msg # $nick $+ , my link protection is already on in $&
        $+($chr(2),#,$chr(2)) !
    }
    elseif (($regml(1) = link off) && ($nick isop #)) {
      goto $iif($istok(%chanon1,#,32),c,d) | :c | set %chanon1 $remtok(%chanon,#,1,32)
      .msg # My Link Protection Is Now off in: $+($chr(2),#)
      halt | :d | .msg # $nick $+ , My link protection is already off . $&
        !
    }
  }
}

4

1 回答 1

0

一个天真的解决方案是添加条件来检查主机并在脚本不在白名单中时阻止脚本发生。

改成这样:

alias -l linkpost {
    var %whitelistPattern = /.*http:\/\/(osu.ppy.sh|puu.sh)\/.*/i
    if (!$regex($1-, %whitelistPattern)) {
        return
    }
    ; Rest of the current script

修复:忘记%在变量名之前添加。

于 2015-01-20T12:39:02.393 回答