irc plugin to turn text into zalgo text

This commit is contained in:
Brian S. Stephan 2021-05-17 10:07:34 -05:00
parent 3d5e6754e8
commit 6ab86f773c
2 changed files with 43 additions and 0 deletions

1
text_manip/__init__.py Normal file
View File

@ -0,0 +1 @@
"""Various IRC plugins for messing with text."""

42
text_manip/zalgo.py Normal file
View File

@ -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