# -*- coding: utf-8 -*- """ IRC3 Bot Plugin: Matrix-style Character Rain This plugin for an IRC bot generates and displays a Matrix-style rain of characters in a specified channel. The characters are randomly selected and colorized to create the visual effect. Features: - Generates a specified number of lines of random characters. - Colorizes each character with a random IRC color. - Sends the generated lines to the target channel. Usage: ====== To use this module, load it as a plugin in your IRC bot configuration. Example: @command def matrix(self, mask, target, args): %%matrix Author: kevinpostal Date: 2025-02-13 06:12:10 (UTC) """ import random import irc3 from irc3.plugins.command import command # List of characters to be used in the Matrix-style rain CHAR_LIST = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "#", "$", "%", "^", "&", "(", ")", "-", "+", "=", "[", "]", "{", "}", "|", ";", ":", "<", ">", ",", ".", "?", "~", "`", "@", "*", "_", "'", "\\", "/", '"' ] # Dictionary of IRC color codes IRC_COLORS = { 'white': '\x0300', 'black': '\x0301', 'blue': '\x0302', 'green': '\x0303', 'red': '\x0304', 'brown': '\x0305', 'purple': '\x0306', 'orange': '\x0307', 'yellow': '\x0308', 'light_green': '\x0309', 'cyan': '\x0310', 'light_cyan': '\x0311', 'light_blue': '\x0312', 'pink': '\x0313', 'grey': '\x0314', 'light_grey': '\x0315' } @irc3.plugin class MatrixPlugin: """A plugin to display a Matrix-style rain of characters in a channel.""" def __init__(self, bot): """ Initialize the plugin with bot reference. Args: bot (irc3.IrcBot): The IRC bot instance. """ self.bot = bot @command def matrix(self, mask, target, args): """ Display a Matrix-style rain of characters. Args: mask (str): The user mask. target (str): The target channel or user. args (dict): Command arguments. Usage: %%matrix """ matrix_lines = self.generate_matrix_lines(80, 120) for line in matrix_lines: self.bot.privmsg(target, line) def generate_matrix_lines(self, lines, length): """ Generate lines of Matrix-style rain characters. Args: lines (int): Number of lines to generate. length (int): Length of each line. Returns: list: List of generated lines. """ matrix_lines = [] for _ in range(lines): line = ''.join(random.choice(CHAR_LIST) for _ in range(length)) line = self.colorize(line) matrix_lines.append(line) return matrix_lines def colorize(self, text): """ Apply random IRC colors to each character in the text. Args: text (str): The text to colorize. Returns: str: Colorized text. """ colored_text = "" for char in text: color = random.choice(list(IRC_COLORS.values())) colored_text += f"{color}{char}" return colored_text