From 53c874dc216ac3e33906b50850f0bbe8354ff20b Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 25 Apr 2021 12:11:59 -0500 Subject: [PATCH] option to replace IRC control chars with markdown ^C^B isn't allowed through Discord's API, and I'm sure some other stuff like colors that I don't use. this makes it a server option to replace them with Markdown, though I think this would only ever be interesting for BitlBee + Discord --- ircbot/bot.py | 6 ++++++ ...server_replace_irc_control_with_markdown.py | 18 ++++++++++++++++++ ircbot/models.py | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 ircbot/migrations/0018_ircserver_replace_irc_control_with_markdown.py diff --git a/ircbot/bot.py b/ircbot/bot.py index 260dc23..9f9d1cf 100644 --- a/ircbot/bot.py +++ b/ircbot/bot.py @@ -891,6 +891,12 @@ class IRCBot(irc.client.SimpleIRCClient): log.warning("reply() called with no event and no explicit target, aborting") return + # convert characters that don't make sense for Discord (like ^C^B) + if self.connection.server_config.replace_irc_control_with_markdown: + log.debug("old replystr: %s", replystr) + replystr = replystr.replace('\x02', '**') + log.debug("new replystr: %s", replystr) + log.debug("replypath: %s", replypath) if replystr is not None: diff --git a/ircbot/migrations/0018_ircserver_replace_irc_control_with_markdown.py b/ircbot/migrations/0018_ircserver_replace_irc_control_with_markdown.py new file mode 100644 index 0000000..120330f --- /dev/null +++ b/ircbot/migrations/0018_ircserver_replace_irc_control_with_markdown.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.2 on 2021-04-25 17:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ircbot', '0017_ircchannel_server'), + ] + + operations = [ + migrations.AddField( + model_name='ircserver', + name='replace_irc_control_with_markdown', + field=models.BooleanField(default=False), + ), + ] diff --git a/ircbot/models.py b/ircbot/models.py index 0effe57..e03cda5 100644 --- a/ircbot/models.py +++ b/ircbot/models.py @@ -84,6 +84,8 @@ class IrcServer(models.Model): xmlrpc_host = models.CharField(max_length=200, default='localhost') xmlrpc_port = models.PositiveSmallIntegerField(default=13132) + replace_irc_control_with_markdown = models.BooleanField(default=False) + def __str__(self): """Provide string summary of the server.""" return f"{self.name} ({self.hostname}/{self.port})"