mirror of
				https://github.com/osmarks/autobotrobot
				synced 2025-10-31 07:53:00 +00:00 
			
		
		
		
	Improve support for bridging replies
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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) | ||||
| @@ -335,4 +348,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()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user