Skip to content

Instantly share code, notes, and snippets.

Last active Mar 8, 2022
What would you like to do?
import re
from supybot import callbacks, ircmsgs, ircutils
# TODO: the nick part of the regexp might need to be a bit more complicated
BRIDGE_MESSAGE_RE = re.compile(r'<(?P<nick>\w+)> (?P<message>.*)')
class BridgeFilter(callbacks.Plugin):
# TODO: add all the other stuff needed in the plugin class
def inFilter(self, irc, msg):
# only process messages, not other kind of commands
if msg.command != 'PRIVMSG':
return msg
# Only process messages from the bridge user.
# TODO: the nick should be configurable
if msg.nick != 'T42':
return msg
channel, text = msg.args
# The bridge adds some colors to the message so strip those away
text = ircutils.stripFormatting(text)
# Parse the nick and original message from the bridge message content
match = BRIDGE_MESSAGE_RE.match(text)
# If it didn't match, pass on the original message
if not match:
return msg
# Construct new IrcMsg object with the original nick and content
original_text ='message')
new_args = (channel, original_text)
original_nick ='nick')
new_prefix = ircutils.joinHostmask(
"[T42]" + original_nick, msg.user,
return ircmsgs.IrcMsg(
msg=msg, # Take other values from the original message
Class = BridgeFilter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment