g1mp/plugins/imitate.py
2025-02-12 20:55:42 -08:00

90 lines
3.6 KiB
Python

import irc3
from irc3.plugins.command import command
import random
# Pre-define the list of Unicode combining characters.
COMBINING_CHARS = [
'\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305',
'\u0306', '\u0307', '\u0308', '\u0309', '\u030A', '\u030B',
'\u030C', '\u030D', '\u030E', '\u030F', '\u0310', '\u0311',
'\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317',
'\u0318', '\u0319', '\u031A', '\u031B', '\u031C', '\u031D',
'\u031E', '\u031F', '\u0320', '\u0321', '\u0322', '\u0323',
'\u0324', '\u0325', '\u0326', '\u0327', '\u0328', '\u0329',
'\u032A', '\u032B', '\u032C', '\u032D', '\u032E', '\u032F',
'\u0330', '\u0331', '\u0332', '\u0333', '\u0334', '\u0335',
'\u0336', '\u0337', '\u0338', '\u0339', '\u033A', '\u033B',
'\u033C', '\u033D', '\u033E', '\u033F', '\u0340', '\u0341',
'\u0342', '\u0343', '\u0344', '\u0345', '\u0346', '\u0347',
'\u0348', '\u0349', '\u034A', '\u034B', '\u034C', '\u034D',
'\u034E', '\u034F', '\u0350', '\u0351', '\u0352', '\u0353',
'\u0354', '\u0355', '\u0356', '\u0357', '\u0358', '\u0359',
'\u035A', '\u035B', '\u035C', '\u035D', '\u035E', '\u035F',
'\u0360', '\u0361', '\u0362'
]
@irc3.plugin
class Imitator:
def __init__(self, bot):
self.bot = bot
self.target = None
self.unicode_mode = False # Flag to enable Unicode glitch styling
def add_combining_characters(self, char):
"""Add random combining characters (with style and color codes) to a character."""
glitched_char = char
# Append between 1 and 3 randomly styled combining characters.
for _ in range(random.randint(1, 3)):
color = random.randint(0, 15)
style = random.choice(['\x02', '\x1F']) # Bold or Underline.
combining_char = random.choice(COMBINING_CHARS)
glitched_char += f'\x03{color}{style}{combining_char}\x0F'
return glitched_char
def style_message(self, message):
"""Apply glitch styling to each character in the message."""
white_color_code = '\x0300' # IRC color code for white.
styled_chars = [
f'{white_color_code}{self.add_combining_characters(c)}'
for c in message
]
return ''.join(styled_chars).strip()
@irc3.event(irc3.rfc.PRIVMSG)
def on_privmsg(self, mask, event, target, data):
"""If a message is received from the target user, repeat it with optional glitch styling."""
if self.target and mask.nick == self.target:
if self.unicode_mode:
data = self.style_message(data)
self.bot.privmsg(target, data)
@command(permission='admin', public=True)
def imitate(self, mask, target, args):
"""
%%imitate [--stop] [--unicode] [<nick>]
Options:
--stop Stop imitating.
--unicode Enable Unicode glitch styling.
"""
stop = args.get('--stop')
nick = args.get('<nick>')
unicode = args.get('--unicode')
if stop:
self.target = None
self.unicode_mode = False
self.bot.privmsg(target, "Stopped imitating.")
return
if not nick:
self.bot.privmsg(target, "Error: You must specify a nick to imitate.")
return
self.target = nick
self.unicode_mode = unicode
self.bot.send_line(f'NICK {nick}_')
if self.unicode_mode:
self.bot.privmsg(target, f"Now imitating {nick} with Unicode glitches!")
else:
self.bot.privmsg(target, f"Now imitating {nick}!")