replace discord bridge nick with sender nick inside the bot

when the bot has received a message through the discord bridge that
it'll end up reacting to (by creating a countdown item, for instance),
the nick in the event should, for all intents and purposes, be the
sender's nick on the discord side, not the discord bridge itself

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
Brian S. Stephan 2024-05-03 12:48:56 -05:00
parent 03e1269cf2
commit e63740ca70
Signed by: bss
GPG Key ID: 3DE06D3180895FCB

View File

@ -161,8 +161,14 @@ class DrReactor(irc.client.Reactor):
channel = IrcChannel.objects.get(name=sent_location)
if sender_nick == channel.discord_bridge:
short_what = ' '.join(what.split(' ')[1:])
real_source = re.sub(r'^<(\S+)> .*', r'\1!user@discord-bridge', what)
match = re.match(addressed_pattern, short_what, re.IGNORECASE)
event.arguments[0] = short_what
event.source = real_source
sender_nick = irc.client.NickMask(event.source).nick
event.sender_nick = sender_nick
event.in_privmsg = sender_nick == sent_location
else:
match = re.match(addressed_pattern, what, re.IGNORECASE)
except IrcChannel.DoesNotExist:
@ -175,10 +181,10 @@ class DrReactor(irc.client.Reactor):
log.debug("all_nicks: %s, addressed: %s", all_nicks, event.addressed)
# only do aliasing for pubmsg/privmsg
log.debug("checking for alias for %s", what)
log.debug("checking for alias for %s", event.arguments[0])
for alias in Alias.objects.all():
repl = alias.replace(what)
repl = alias.replace(event.arguments[0])
if repl:
# we found an alias for our given string, doing a replace
event.arguments[0] = repl