g1mp/plugins/disregard.py

110 lines
3.8 KiB
Python
Raw Permalink Normal View History

2025-02-13 06:35:15 +00:00
# -*- coding: utf-8 -*-
"""
========================================================
IRC3 Disregard Plugin (Flood-Based Message Suppression)
========================================================
This plugin listens for messages from a **target user** and floods the
channel with **empty messages** to suppress visibility of their messages.
Features:
- **Admin-controlled** disregard system.
- **Flood-based suppression** (sends invisible characters).
- **Command to start/stop disregarding users**.
Commands:
!disregard <nick> -> Starts disregarding the specified user.
!stopdisregard -> Stops disregarding the current user.
Usage:
- The bot **detects messages** from the target nick and **floods** the chat.
- The bot **stops flooding** when the target is removed.
"""
import asyncio
2025-02-13 04:55:42 +00:00
import irc3
from irc3.plugins.command import command
2025-02-13 06:35:15 +00:00
2025-02-13 04:55:42 +00:00
@irc3.plugin
class DisregardPlugin:
2025-02-13 06:35:15 +00:00
"""A plugin that disregards a user by flooding the chat with empty messages."""
def __init__(self, bot: irc3.IrcBot):
"""
Initialize the DisregardPlugin.
Args:
bot (irc3.IrcBot): The IRC bot instance.
"""
2025-02-13 04:55:42 +00:00
self.bot = bot
self.target = None # The nick to disregard
2025-02-13 06:35:15 +00:00
self.flood_count = 25 # Number of empty messages to send per detection
self.flood_message = '\u00A0\u2002\u2003' * 50 # Invisible characters
2025-02-13 04:55:42 +00:00
@irc3.event(irc3.rfc.PRIVMSG)
2025-02-13 06:35:15 +00:00
async def on_privmsg(self, mask, event, target, data):
2025-02-13 04:55:42 +00:00
"""
2025-02-13 06:35:15 +00:00
Listens for messages and floods the channel if the sender is the target nick.
2025-02-13 04:55:42 +00:00
2025-02-13 06:35:15 +00:00
Args:
mask (str): Contains info about the sender (mask.nick is the sender's nick).
event (str): The IRC event type.
target (str): The channel or user receiving the message.
data (str): The message content.
2025-02-13 04:55:42 +00:00
"""
2025-02-13 06:35:15 +00:00
if self.target and mask.nick.lower() == self.target.lower():
self.bot.log.info(f"Flooding {target} due to message from {self.target}.")
# Async flooding to avoid blocking
2025-02-13 04:55:42 +00:00
for _ in range(self.flood_count):
2025-02-13 06:35:15 +00:00
self.bot.privmsg(target, self.flood_message)
await asyncio.sleep(0.1) # Prevents immediate rate-limiting
2025-02-13 04:55:42 +00:00
@command(permission='admin', public=True)
def disregard(self, mask, target, args):
"""
2025-02-13 06:35:15 +00:00
Set a target nick to disregard (flood when they send messages).
2025-02-13 04:55:42 +00:00
2025-02-13 06:35:15 +00:00
Usage:
2025-02-13 04:55:42 +00:00
%%disregard <nick>
2025-02-13 06:35:15 +00:00
Args:
mask (str): Sender mask.
target (str): The channel where the command was sent.
args (dict): Command arguments.
Returns:
str: Confirmation message.
2025-02-13 04:55:42 +00:00
"""
user = args.get('<nick>')
if not user:
2025-02-13 06:35:15 +00:00
return "Usage: !disregard <nick>"
2025-02-13 04:55:42 +00:00
2025-02-13 06:35:15 +00:00
self.target = user.lower()
2025-02-13 04:55:42 +00:00
self.bot.privmsg(target, f"Now disregarding {user}. Their messages will trigger empty floods.")
2025-02-13 06:35:15 +00:00
self.bot.log.info(f"Started disregarding {user}.")
2025-02-13 04:55:42 +00:00
@command(permission='admin', public=True)
def stopdisregard(self, mask, target, args):
"""
2025-02-13 06:35:15 +00:00
Stop disregarding the current target nick.
2025-02-13 04:55:42 +00:00
2025-02-13 06:35:15 +00:00
Usage:
2025-02-13 04:55:42 +00:00
%%stopdisregard
2025-02-13 06:35:15 +00:00
Args:
mask (str): Sender mask.
target (str): The channel where the command was sent.
args (dict): Command arguments.
Returns:
str: Confirmation message.
2025-02-13 04:55:42 +00:00
"""
if self.target:
self.bot.privmsg(target, f"Stopped disregarding {self.target}.")
2025-02-13 06:35:15 +00:00
self.bot.log.info(f"Stopped disregarding {self.target}.")
2025-02-13 04:55:42 +00:00
self.target = None
else:
self.bot.privmsg(target, "No target is currently being disregarded.")