Search code examples
mirc

mIRC Link Bot for Twitch


This is quite a long post (specially the code below), so bear with me.

With help from @Siris_Black, I've managed to get this thing working.

//LINK PROTECTION
    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|tv
        var %exception /(?:http?:\/\/)?w{3}\.(youtube|imgur|i.imgur)\.com/
        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)) && (!$regex($1-,%exception)) {
          timeout 30 # $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 # Link Protection Is Now on in: $+($chr(2),#)
          halt | :b | .msg # $nick $+ , 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 # Link Protection Is now off in: $+($chr(2),#)
          halt | :d | .msg # $nick $+ , Link Protection is already off . $&
            !
        }
      }
    }

However, even with the extensive script, there are some problems:

'Whitelisted' links that are being blocked

https://i.sstatic.net/Ww4rK.png

As you can see, Alexander_CJ and Psychosis06 posted Imgur links and were timedout (I have BetterTwitchTV, so I can reveal what was purged). Is there something that I have set up wrongly here?

The !permit command doesn't always work There seems to be issues where the permit command fails to actually permit anyone. The primary issue were user names (which I figured out: all user names are lower case). But there still seems to be issues with the !permit + username command. Are there any conflicts that exist here?

Link Script allows certain links that have text before or after them

This is pretty self explanatory, there are situations where the link bot allows a link that seems to have normal text after it or before it. Unless I haven't set up the rule properly, there are situations where the issue crops up.

The Link Protection seems to interfere with other scripts

These are my other scripts:

//Commands
on *:TEXT:!commands:#circon: { 
  if ((%floodcommands) || ($($+(%,floodcommands.,$nick),2))) { return }
  set -u5 %floodcommands On
  set -u15 %floodcommands. $+ $nick On
  msg $chan /me Currently available commands (place a '!' before the word) - donate|song|mods. Please don't spam commands. $+
}

//Song
on *:TEXT:!song:#circon: { 
  if ((%floodsong) || ($($+(%,floodsong.,$nick),2))) { return }
  set -u5 %floodsong On
  set -u15 %floodsong. $+ $nick On
  msg $chan /me You can find Circon's songs here, wait for the song to finish and it will be the last played song: http://grooveshark.com/#!/circonflexes/listens $+
}

//Soccer Link
on *:TEXT:!football:#circon:{
  if ((%floodfootball) || ($($+(%,floodfootball.,$nick),2))) { return }
  set -u5 %floodfootball On
  set -u15 %floodfootball. $+ $nick On
  msg $chan /me Circon is watching the World Cup here!: <LINK> $+
} 

//Mods Link
on *:TEXT:!mods:#circon:{
  if ((%floodmods) || ($($+(%,floodmods.,$nick),2))) { return }
  set -u5 %floodmods On
  set -u15 %floodmods. $+ $nick On
  msg $chan /me Circon's mods are here: http://youtu.be/N-IHaIKQvns. Servercross2 Recticle add-on - https://www.dropbox.com/s/dkd0b1fqp9oaz2e/ServerCross2.rar Dont forget to virus scan before use. :) $+
}

//Donate
on *:TEXT:!donate:#circon:{
  if ((%flooddonate) || ($($+(%,flooddonate.,$nick),2))) { return }
  set -u5 %flooddonate On
  set -u15 %flooddonate. $+ $nick On
  msg $chan /me Please donate to Circon here: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KRQXH2YM3WGSW $+
}

Once in a while, a command that is input correctly (i.e. !song) will not display the text. In fact, nothing happens. Is there anything that is conflicting? I'm not able to see any issues with what I've done. There are two sets of these scripts (for two Twitch channels).

I'm sorry that this is a lot. I'm a complete newbie to MSL and just need some pointers/tips. I'd primarily appreciate any guidance as to set up the most strict link protection - i.e. disallow ANY linking except youtube and imgur.

Thanks!


Solution

  • first, the other on text script (!command,!song,!footbal,!mods) needs to be in another remote file
    since u have an on text script that matches anything on link protection script

    try this

    on @*:text:*:#:linkpost $1-
    on @*:action:*:#:linkpost $1-
    on @*:notice:*:#:linkpost $1-
    alias -l linkpost {
    if (!$hfind(permit,$nick)) {
    var %purge /^!(link\so(n|ff)|(permit))\b/iS
    var %domain com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|tv
    var %exception /(?:http?:\/\/)?(?:w{3}\.)?.+(youtube|\Qimgur\E)\.com/
    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)) && (!$regex($1-,%exception)) {
      timeout 30 # $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 # $$2 $+ , 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 # Link Protection Is Now on in: $+($chr(2),#)
      halt | :b | .msg # $nick $+ , 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 # Link Protection Is now off in: $+($chr(2),#)
      halt | :d | .msg # $nick $+ , Link Protection is already off . $&
        !
    }
    }
    }