This commit is contained in:
osmarks 2021-12-30 13:54:30 +00:00
commit ae6830dba5
2 changed files with 24 additions and 8 deletions

View File

@ -71,11 +71,14 @@ async def initialize():
if channel_name in util.config["irc"]["channels"]:
if channel_name not in joined: conn.join(channel_name)
if msg.reply:
reply_line = render_line(msg.reply[0], render_formatting(msg.reply[1])).encode("utf-8")
reply_line_new, reply_line_u = bytewise_truncate(reply_line, 300)
if reply_line_new != reply_line:
reply_line_u += " ..."
conn.privmsg(channel_name, f"[Replying to {reply_line_u}]")
if msg.reply[0] and msg.reply[1]:
reply_line = render_line(msg.reply[0], render_formatting(msg.reply[1])).encode("utf-8")
reply_line_new, reply_line_u = bytewise_truncate(reply_line, 300)
if reply_line_new != reply_line:
reply_line_u += " ..."
conn.privmsg(channel_name, f"[Replying to {reply_line_u}]")
else:
conn.privmsg(channel_name, "[Replying to an unknown message]")
lines = []
content = render_formatting(msg.message).encode("utf-8")
# somewhat accursedly break string into valid UTF-8 substrings with <=400 bytes

View File

@ -114,9 +114,22 @@ class Telephone(commands.Cog):
if (msg.author == self.bot.user and msg.content[0] == "<") or msg.author.discriminator == "0000": return
channel_id = msg.channel.id
reply = None
if msg.reference and msg.reference.cached_message:
replying_to = msg.reference.cached_message
reply = (eventbus.AuthorInfo(replying_to.author.name, replying_to.author.id, str(replying_to.author.avatar_url), replying_to.author.bot), parse_formatting(self.bot, replying_to.content))
if msg.reference:
if isinstance(msg.reference.resolved, discord.DeletedReferencedMessage):
replying_to = None
elif msg.reference.resolved:
replying_to = msg.reference.resolved
elif msg.reference.cached_message:
replying_to = msg.reference.cached_message
else:
try:
replying_to = await self.bot.get_guild(msg.reference.guild_id).get_channel(msg.reference.channel_id).fetch_message(msg.reference.message_id)
except discord.HTTPException:
replying_to = None
if replying_to:
reply = (eventbus.AuthorInfo(replying_to.author.name, replying_to.author.id, str(replying_to.author.avatar_url), replying_to.author.bot), parse_formatting(self.bot, replying_to.content))
else:
reply = (None, None)
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() ], reply=reply)
await eventbus.push(msg)