use preexisting message data & clean up code a bit

This commit is contained in:
all-other-usernames-were-taken 2021-10-06 16:33:50 -04:00
parent e928ba7550
commit abc1eb15be
3 changed files with 36 additions and 7 deletions

View File

@ -26,12 +26,13 @@ class Message:
message: list[typing.Union[str, dict]]
source: (str, any)
id: int
replyee: AuthorInfo
attachments: list[discord.Attachment]
evbus_messages = prometheus_client.Counter("abr_evbus_messages", "Messages processed by event bus", ["source_type"])
evbus_messages_dropped = prometheus_client.Counter("abr_evbus_messages_dropped", "Messages received by event bus but dropped by rate limits", ["source_type"])
# maps each bridge destination type (discord/APIONET/etc) to the listeners for it.
# maps each bridge destination type (discord/APIONET/etc) to the listeners for it
listeners = collections.defaultdict(set)
# maintains a list of all the unidirectional links between channels - key is source, values are targets

View File

@ -58,16 +58,21 @@ async def initialize():
async def on_bridge_message(channel_name, msg):
if channel_name in util.config["irc"]["channels"]:
if channel_name not in joined: conn.join(channel_name)
# if its a reply
dmsg = discord.fetch_message(msg.id)
if dmsg.reference.message_id:
conn.privmessage(channel_name, f"Replying to @{random_color(dmsg.reference.cached_message.author.id)}{dmsg.reference.cached_message.author.name}{color_code('')}:")
if msg.replyee:
conn.privmessage (channel_name, f"Replying to @{random_color(msg.replyee.id)}{msg.replyee.name}{color_code('')}:")
# ping fix - zero width space embedded in messages
line = f"<{random_color(msg.author.id)}{msg.author.name[0]}\u200B{msg.author.name[1:]}{color_code('')}> " + render_formatting(msg.message)[:400]
conn.privmsg(channel_name, line)
for at in msg.attachments:
conn.privmsg(channel_name, f"-> {at.filename}: {at.proxy_url}")
else:
logging.warning("IRC channel %s not allowed", channel_name)

View File

@ -113,8 +113,31 @@ class Telephone(commands.Cog):
if msg.content == "" and len(msg.attachments) == 0: return
if (msg.author == self.bot.user and msg.content[0] == "<") or msg.author.discriminator == "0000": return
channel_id = msg.channel.id
msg = eventbus.Message(eventbus.AuthorInfo(msg.author.name, msg.author.id, str(msg.author.avatar_url), msg.author.bot),
parse_formatting(self.bot, msg.content), ("discord", channel_id), msg.id, [ at for at in msg.attachments if not at.is_spoiler() ])
msg = eventbus.Message(
eventbus.AuthorInfo(
msg.author.name,
msg.author.id,
str(msg.author.avatar_url),
msg.author.bot
),
parse_formatting (self.bot, msg.content),
("discord", channel_id),
msg.id,
eventbus.AuthorInfo(
msg.reference.cached_message.author.name,
msg.reference.cached_message.author.id,
str(msg.reference.cached_message.author.avatar_url),
msg.reference.cached_message.author.bot
),
[ at for at in msg.attachments if not at.is_spoiler() ]
)
await eventbus.push(msg)
def cog_unload(self):
@ -331,4 +354,4 @@ When you want to end a call, use hangup.
def setup(bot):
cog = Telephone(bot)
bot.add_cog(cog)
asyncio.create_task(cog.initial_load_webhooks())
asyncio.create_task(cog.initial_load_webhooks())