g1mp/plugins/matrix.py

113 lines
3.5 KiB
Python
Raw Permalink Normal View History

2025-02-13 06:35:15 +00:00
# -*- 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)
"""
2025-02-13 04:55:42 +00:00
import random
import irc3
from irc3.plugins.command import command
2025-02-13 06:35:15 +00:00
# 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", "!", "#", "$",
"%", "^", "&", "(", ")", "-", "+", "=", "[", "]", "{", "}", "|",
";", ":", "<", ">", ",", ".", "?", "~", "`", "@", "*", "_", "'",
"\\", "/", '"'
]
2025-02-13 04:55:42 +00:00
2025-02-13 06:35:15 +00:00
# Dictionary of IRC color codes
2025-02-13 04:55:42 +00:00
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:
2025-02-13 06:35:15 +00:00
"""A plugin to display a Matrix-style rain of characters in a channel."""
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 matrix(self, mask, target, args):
"""
Display a Matrix-style rain of characters.
2025-02-13 06:35:15 +00:00
Args:
mask (str): The user mask.
target (str): The target channel or user.
args (dict): Command arguments.
Usage:
%%matrix
2025-02-13 04:55:42 +00:00
"""
2025-02-15 04:03:21 +00:00
matrix_lines = self.generate_matrix_lines(80, 120)
2025-02-13 04:55:42 +00:00
for line in matrix_lines:
self.bot.privmsg(target, line)
def generate_matrix_lines(self, lines, length):
2025-02-13 06:35:15 +00:00
"""
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.
"""
2025-02-13 04:55:42 +00:00
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):
2025-02-13 06:35:15 +00:00
"""
Apply random IRC colors to each character in the text.
Args:
text (str): The text to colorize.
Returns:
str: Colorized text.
"""
2025-02-13 04:55:42 +00:00
colored_text = ""
for char in text:
color = random.choice(list(IRC_COLORS.values()))
colored_text += f"{color}{char}"
return colored_text