-1

So I am trying to build my twitch bot through mIRC and I have been wanting it to timeout links for everysite except for any links from http://osu.ppy.sh/ and any links from http://puu.sh/ but block out anything else.

I have found script and tutorials but I cannot find anything that explains how to make an exception in enough detail to explain what each part of the exception is for nor can I find anything that includes these domains in the exception

Here is my old link protection script

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

Any will be appreciated, there is no other commands or script currently for the bot.

Code after edit

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 . $&
        !
    }
  }
}
aynber
  • 22,380
  • 8
  • 50
  • 63

1 Answers1

0

A naive solution will be to add condition that will check the host and to stop the script from happening if it's not in the white list.

Change to this:

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

Fix: Forgot adding % before variable name.

Orel Eraki
  • 11,940
  • 3
  • 28
  • 36
  • I attempted the above, did not work and I even tried a varied number of locations as well. – Eric Nielsen Jan 21 '15 at 05:36
  • Still didn't work, after adding in the code, still didn't work. Still times out for posting those links. – Eric Nielsen Jan 22 '15 at 09:34
  • No, it breaks the code completely, doesn't catch links, doesn't allow me to turn the protection on or off/ – Eric Nielsen Feb 01 '15 at 06:11
  • @EricNielsen, I pretty sure it's working after the code changed (added '%') Please be sure to update just what i gave you. – Orel Eraki Feb 01 '15 at 17:16
  • @Orek Eraki, I made those changes, shown in OP, and my entire script stops working. I cannot turn on or off the protections and the links are not timed out. Unless I am putting this in the wrong location, the fix you suggested has not worked so far. even by changing the appropriate if to elseif. – Eric Nielsen Feb 02 '15 at 03:44