Creating a Chat Moderation Bot for Streaming Platform Using mIRC

Chat Moderation Script Issues

I’m working on a moderation script for streaming chat and running into several problems. Here’s my current setup:

//MODERATION SYSTEM
on @*:text:*:#:checkMessage $1-
on @*:action:*:#:checkMessage $1-
on @*:notice:*:#:checkMessage $1-

alias -l checkMessage {
  if ((!%cooldown) && (!$hfind(allowed,$nick))) { inc -u3 %cooldown
    var %modCommands /^!(filter\so(n|ff)|(allow))\b/iS
    var %sites net|org|com|edu|info|co|uk|de|fr
    var %whitelist /(?:https?:\/\/)?w{3}\.(twitch|gyazo|prntscr)\.com/
    var %urlPattern /(?<=^|\s)((?>\S{4,9}:\/\/|w{3}\56)\S+)|\56( $+ %sites $+ )\b/iS
    
    if ($findtok(%activeChannels,#,1,32)) && ($nick(#,$nick,vr)) && ($regex($1-,%urlPattern)) && (!$regex($1-,%whitelist)) {
      timeout 45 # $nick | /mode # -b $nick
      msg # $nick $+ , links require moderator approval. Request !allow permission first.
      msg # /timeout $nick 2
    }
    elseif (($regex($1-,%modCommands)) && ($regml(1) = allow) && ($nick isop #) && ($$2 ison #)) {
      hadd -mz allowed $v1 45 | notice $v1 Link posting enabled for 45 seconds!
      msg # Permission granted for 45 seconds!
    }
    elseif (($regml(1) = filter on) && ($nick isop #)) {
      goto $iif(!$istok(%activeChannels,#,32),enable,skip)
      :enable | set %activeChannels $addtok(%activeChannels,#,32)
      .msg # URL Filter activated for: $+($chr(2),#)
      halt | :skip | .msg # Filter already running in $+($chr(2),#,$chr(2))
    }
  }
}

Main Problems:

Approved links getting blocked anyway

My whitelist isn’t working right. URLs from approved sites still trigger timeouts even though they should be allowed through.

Permission system fails randomly

The !allow command works sometimes but not always. I think it might be related to username formatting but I’m not sure what’s causing the inconsistency.

Script conflicts with other features

I have basic command responses that sometimes stop working:

//Basic Commands
on *:TEXT:!help:#mychannel: {
  if ((%helpFlood) || ($($+(%,helpFlood.,$nick),2))) { return }
  set -u10 %helpFlood On
  set -u20 %helpFlood. $+ $nick On
  msg $chan Available commands: !schedule|!discord|!social
}

on *:TEXT:!schedule:#mychannel: {
  if ((%schedFlood) || ($($+(%,schedFlood.,$nick),2))) { return }
  set -u10 %schedFlood On  
  set -u20 %schedFlood. $+ $nick On
  msg $chan Stream schedule: Monday/Wednesday/Friday 8PM EST
}

Sometimes these commands just don’t respond at all. Could my moderation script be interfering?

I’m pretty new to mIRC scripting and could really use some help debugging these issues. My goal is to block all URLs except a few trusted domains. Any suggestions would be great!

The Problem: Your mIRC moderation script is experiencing several issues: approved links are still being blocked, the !allow command is unreliable, and your basic commands sometimes fail to respond. These problems stem from regex errors, variable scoping issues, and potential conflicts between your moderation script and other mIRC events.

TL;DR: The Quick Fix:

  1. Regex Corrections: Fix your regular expressions. Use proper escaping for periods (. should be \.) and ensure you are using consistent regex syntax (PCRE or mIRC’s basic regex) throughout.
  2. Variable Scoping: Correct variable handling in your !allow command. Store the username ($2) in a temporary variable before using it in the hadd command to prevent overwriting.
  3. Event Ordering: Reorder your mIRC events. Place your basic commands (!help, !schedule, etc.) before the moderation script’s events to prevent the moderation script from interrupting them. Alternatively, add channel checks to your moderation script to ensure it only runs in channels where the URL filter is explicitly enabled.
  4. Debug Statements: Add temporary echo statements to track the execution flow and identify where your script is failing. This will help you pinpoint the exact source of the problems.

:thinking: Understanding the “Why” (The Root Cause):

Your issues are primarily caused by a combination of incorrect regular expression syntax and improper variable handling within your mIRC script. The use of @*:text:*:# as an event prefix restricts your commands’ execution to only when the bot has operator status, explaining why some functionalities fail intermittently.

Your whitelist regex isn’t functioning correctly because of incorrect escaping of the dot character and potential issues with word boundaries. The !allow command’s unreliability results from the $v1 variable being overwritten before the hadd command can use it. The conflict with basic commands occurs because the moderation script is likely halting execution before other events can process.

:gear: Step-by-Step Guide:

  1. Refine Your Regular Expressions: Carefully review your regular expressions (%urlPattern and %whitelist). Ensure you are using consistent regex syntax (either PCRE or mIRC’s basic regex). The use of \\56 for a literal dot (.) is incorrect; it should be \.. Check your word boundary (\b) usage, as it might be interfering with your lookahead structure, preventing accurate matching.

  2. Improve Variable Handling: Modify the !allow command to store $2 (the username) in a temporary variable before using it with the hadd command. This prevents the variable from being overwritten before the hadd command executes. For example:

elseif (($regex($1-,%modCommands)) && ($regml(1) = allow) && ($nick isop #) && ($$2 ison #)) {
  var %tempUser $2
  hadd -mz allowed %tempUser 45 | notice %tempUser Link posting enabled for 45 seconds!
  msg # Permission granted for 45 seconds!
}
  1. Reorder Events: Rearrange your mIRC script to place your basic commands (!help, !schedule, etc.) above your moderation script’s events. This ensures they’re processed before the moderation script can potentially interrupt them. For example:
//Basic Commands
on *:TEXT:!help:#mychannel: { ... }
on *:TEXT:!schedule:#mychannel: { ... }

//MODERATION SYSTEM
on *:text:*:#:checkMessage $1-  // Changed from @*:text:*:#
on *:action:*:#:checkMessage $1- // Changed from @*:action:*:#
on *:notice:*:#:checkMessage $1- // Changed from @*:notice:*:#
... rest of moderation script

Note that changing the @ prefix in the on commands for the moderation system will make the events trigger for all users, rather than just ops.

  1. Implement Debugging: Add echo statements to your script for debugging purposes. For instance:
echo -a Debug: $1-
echo -a Regex result: $regml(1)

Place these statements strategically throughout your script to track the values of variables and the results of your regular expression matches. Remove them once you’ve identified the problem.

:mag: Common Pitfalls & What to Check Next:

  • Regex Debuggers: Consider using an online regex debugger to test your patterns before implementing them in your mIRC script.
  • mIRC Documentation: Review the official mIRC documentation to understand the intricacies of its regular expression engine and event handling.
  • Alternative Moderation Tools: For more complex moderation needs, explore alternative tools or platforms better suited for chat moderation, which might offer more robust and maintainable solutions.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

Your main problem is that @*:text:*:# event prefix - it only triggers for ops. When your bot loses op status temporarily, everything breaks. I had the same issue where commands would randomly die.

For the whitelist, your regex escapes are wrong. Use \. instead of \56 for literal dots. The word boundaries aren’t matching because of your lookahead structure.

The permission system fails because you’re using $v1 for the username, but that variable gets overwritten between the regex match and hadd command. Store $2 in a temp variable first.

Your basic commands conflict because the moderation script runs first and sometimes halts execution before reaching those events. Move your simple commands above the moderation events, or add explicit channel checks in the moderation script so it only processes channels where filtering’s actually enabled.

Quick fix that helped me - add debug output to see what’s actually matching. Temporarily add echo -a Debug: $1- | echo -a Regex result: $regml(1) to track where things break.

Your mIRC script has classic regex and timing issues that are a pain to debug. The whitelist regex has word boundary problems and your permission system is fighting with variable scoping.

Honestly though, using mIRC scripts for chat moderation is like using a hammer for surgery. I ditched similar setups for automated solutions that actually work.

The real fix? Move your moderation logic to a proper automation platform. Build the same filtering system with webhook triggers that catch chat messages, run URL validation, check your whitelist database, and fire moderation actions back to your streaming platform.

I built something like this that handles multiple channels, keeps persistent user permissions, and never conflicts with other bot features. It processes chat events in real time, stores approved users in a database, and handles timeout commands through API calls.

Best part - you get proper logging, can tweak rules without restarting scripts, and add new features without breaking existing ones.

Your current approach will keep having random failures because mIRC wasn’t designed for complex automation. Moving to a dedicated platform solves the reliability issues and gives you way more flexibility.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.