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

50 lines
1.9 KiB
Python

import random
import irc3
from irc3.plugins.command import command
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", "!", "#", "$",
"%", "^", "&", "(", ")", "-", "+", "=", "[", "]", "{", "}", "|",
";", ":", "<", ">", ",", ".", "?", "~", "`", "@", "*", "_", "'",
"\\", "/", '"']
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:
def __init__(self, bot):
self.bot = bot
@command
def matrix(self, mask, target, args):
"""
Display a Matrix-style rain of characters.
%%matrix
"""
matrix_lines = self.generate_matrix_lines(20, 80)
for line in matrix_lines:
self.bot.privmsg(target, line)
def generate_matrix_lines(self, lines, length):
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):
colored_text = ""
for char in text:
color = random.choice(list(IRC_COLORS.values()))
colored_text += f"{color}{char}"
return colored_text