g1mp/plugins/unicode_say.py

120 lines
4.3 KiB
Python
Raw Normal View History

2025-02-13 06:35:15 +00:00
# -*- coding: utf-8 -*-
"""
IRC3 Bot Plugin: Say Command with Text Styling
This plugin for an IRC bot allows the bot to send styled messages to a specified channel using the say command.
The messages are styled with random IRC color codes, bold, and underline, along with Unicode combining characters.
Features:
- Sends a styled message to a specified channel.
- Applies random IRC colors, bold, and underline styles to the message.
- Uses Unicode combining characters to create a glitch effect.
Usage:
======
To use this module, load it as a plugin in your IRC bot configuration.
Example:
@command
def say(self, mask, target, args):
%%say <channel> <message>...
Author: Zodiac
Date: 2025-02-13 06:24:46 (UTC)
"""
2025-02-13 04:55:42 +00:00
import irc3
import random
from irc3.plugins.command import command
@irc3.plugin
class SayPlugin:
2025-02-13 06:35:15 +00:00
"""A plugin to send styled messages to a specified channel using the say command."""
2025-02-13 04:55:42 +00:00
def __init__(self, bot):
2025-02-13 06:35:15 +00:00
"""
Initialize the plugin with bot reference.
Args:
bot (irc3.IrcBot): The IRC bot instance.
"""
2025-02-13 04:55:42 +00:00
self.bot = bot
@command
def say(self, mask, target, args):
2025-02-13 06:35:15 +00:00
"""
Say command to send a styled message to a specified channel.
Args:
mask (str): The user mask.
target (str): The target channel or user.
args (dict): Command arguments.
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
%%say <channel> <message>...
"""
channel = args.get('<channel>')
message = ' '.join(args['<message>'])
if not channel or not message:
self.bot.privmsg(target, "Usage: !say <channel> <message>")
return
styled_message = self.style_message(message)
self.bot.privmsg(channel, styled_message)
def add_combining_characters(self, char):
2025-02-13 06:35:15 +00:00
"""
Add random combining characters (with style and color codes) to a character.
Args:
char (str): The character to style.
Returns:
str: The styled character.
"""
2025-02-13 04:55:42 +00:00
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'
]
glitched_char = char
for _ in range(random.randint(1, 1)):
color = random.randint(0, 15)
style = random.choice(['\x02', '\x1F']) # Bold and Underline
combining_char = random.choice(combining_chars)
glitched_char += f'\x03{color}{style}{combining_char}\x0F'
return glitched_char
def style_message(self, message):
2025-02-13 06:35:15 +00:00
"""
Apply styling to each character in the message.
Args:
message (str): The message to style.
Returns:
str: The styled message.
"""
2025-02-13 04:55:42 +00:00
white_color_code = '\x0300' # White color
styled_message = ''
for char in message:
char_with_combining = self.add_combining_characters(char)
styled_message += f'{white_color_code}{char_with_combining}'
return styled_message.strip() # Remove the trailing space