From 6ab86f773c0a8a5a298419629acb37cac3d435d6 Mon Sep 17 00:00:00 2001 From: Brian Stephan Date: Mon, 17 May 2021 10:07:34 -0500 Subject: [PATCH] irc plugin to turn text into zalgo text --- text_manip/__init__.py | 1 + text_manip/zalgo.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 text_manip/__init__.py create mode 100644 text_manip/zalgo.py diff --git a/text_manip/__init__.py b/text_manip/__init__.py new file mode 100644 index 0000000..0b41c45 --- /dev/null +++ b/text_manip/__init__.py @@ -0,0 +1 @@ +"""Various IRC plugins for messing with text.""" diff --git a/text_manip/zalgo.py b/text_manip/zalgo.py new file mode 100644 index 0000000..421a1a5 --- /dev/null +++ b/text_manip/zalgo.py @@ -0,0 +1,42 @@ +"""Turn text into zalgo text.""" +import logging + +import irc.client +from zalgo_text import zalgo + +from ircbot.lib import Plugin + +logger = logging.getLogger(__name__) + + +class Zalgo(Plugin): + """Zalgoify text on demand.""" + + zalgo_regex = r'^!zalgo\s+(.*)$' + + def start(self): + """Set up the handlers.""" + logger.debug("%s starting up", __name__) + self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], self.zalgo_regex, + self.zalgofy, 0) + + super(Zalgo, self).start() + + def stop(self): + """Tear down handlers.""" + logger.debug("%s shutting down", __name__) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.zalgofy) + + super(Zalgo, self).stop() + + def zalgofy(self, connection, event, match): + """Turn text into zalgo text.""" + who = irc.client.NickMask(event.source).nick + what = match.group(1) + logger.debug("%s requested zelgo text for %s", who, what) + zalgoed = zalgo.zalgo().zalgofy(what) + self.bot.reply(event, f"{zalgoed}") + return 'NO MORE' + + +plugin = Zalgo