mIRC Bot for Twitch Chat Link Moderation Issues

I’m having trouble with my mIRC script for moderating links in Twitch chat. The bot is supposed to allow only YouTube and Imgur links while blocking everything else, but I’m running into several problems.

//URL FILTER
on @*:text:*:#:filterlinks $1-
on @*:action:*:#:filterlinks $1-
on @*:notice:*:#:filterlinks $1-
alias -l filterlinks {
  if ((!%block) && (!$hfind(allowed,$nick))) { inc -u4 %block
    var %cmdcheck /^!(url\s(enable|disable)|(allow))\b/iS
    var %sites net|com|org|info|tv|uk|us|ca|gov|edu|mil|biz
    var %safe /(?:https?:\/\/)?w{3}\.(youtube|imgur|i\.imgur)\.com/
    var %urlpattern /(?<=^|\s)((?>\.S{3,8}:\/\/|w{3}\56)\S+)|\56( $+ %sites $+ )\b/iS
    if ($findtok(%active1,#,1,32)) && ($nick(#,$nick,vr)) && ($regex($1-,%urlpattern)) && (!$regex($1-,%safe)) {
      timeout 30 # $nick | /mode # -b $nick
      msg # $nick $+ , links require permission first. Ask a moderator to !allow you.
      msg # /timeout $nick 1
    }
    elseif (($regex($1-,%cmdcheck)) && ($regml(1) = allow) && ($nick isop #) && ($$2 ison #)) {
      hadd -mz allowed $v1 30 | notice $v1 You can post a link for the next 30 seconds!
      msg # Link permission granted for 30 seconds!
    }
  }
}

Main issues I’m facing:

  1. Whitelisted sites getting blocked - Even Imgur links that should be allowed are timing out users

  2. Permission command not working reliably - The !allow command sometimes fails to grant permission to users

  3. Script conflicts - My other bot commands (like !song, !donate) occasionally stop responding completely

I also have basic command handlers for things like donation links and music info, but they seem to interfere with the link filter somehow.

I’m pretty new to mIRC scripting and could really use some help fixing these issues. The goal is to have very strict link filtering that only allows YouTube and Imgur while blocking everything else.

Any suggestions on what might be going wrong with the regex patterns or command handling?

honestly that script looks way overcomplicated for what ur trying to do. ive been running link moderation for years and found keeping it simple works better. try breaking down the regex into seperate checks instead of one massive pattern - check for urls first, then whitelist after. also that %block variable is probly whats killing your other commands since its blocking everything globally

Been working with mIRC bots for Twitch moderation for about three years now and ran into similar headaches. The main culprit is usually the regex escaping in mIRC which behaves differently than standard regex engines. Your %safe pattern needs double backslashes for proper escaping, and the dot before S{3,8} should probably be \S{3,8} for non-whitespace matching.

What fixed it for me was switching to a two-step verification process instead of trying to do everything in one regex. First detect any potential URLs with a simple pattern, then run a separate check against your whitelist. This way you can debug each part independently.

For the command conflicts, that global %block timer is definitely the issue. Each command trigger waits for that timer to expire before processing anything else. Switch to using %block. $+ $nick instead so each user has their own rate limit rather than blocking the entire bot.

Also make sure your other event handlers aren’t using the same priority level as the link filter, otherwise they compete for processing time.

Your regex patterns have some fundamental issues that are causing the problems. The %safe pattern uses w{3} instead of \w{3} for matching www, and the backslashes aren’t properly escaped for mIRC. Also, your URL detection pattern is overly complex and prone to false matches.

I’d suggest simplifying the approach entirely. Instead of trying to catch every possible URL format, focus on detecting common patterns like http/https prefixes and domains with TLDs. Your current pattern (?<=^|\s)((?> uses lookbehinds which can be unreliable in mIRC’s regex implementation.

For the command conflicts, you’re likely hitting the rate limiting with inc -u4 %block too aggressively. This prevents multiple commands from processing properly within the 4-second window. Consider using nick-specific variables instead of a global block timer.

The permission system fails because $v1 might not contain what you expect when the regex matching occurs. Try storing $2 in a separate variable before the hadd command to ensure you’re granting permission to the right user.