From e64373979384c82580d7b8db582d48897096b992 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Fri, 22 Mar 2024 17:03:33 -0400 Subject: Add teleport cog --- teleport/__init__.py | 5 +++++ teleport/info.json | 5 +++++ teleport/teleport.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 teleport/__init__.py create mode 100644 teleport/info.json create mode 100644 teleport/teleport.py diff --git a/teleport/__init__.py b/teleport/__init__.py new file mode 100644 index 0000000..f5b87c9 --- /dev/null +++ b/teleport/__init__.py @@ -0,0 +1,5 @@ +from .teleport import Teleport + + +async def setup(bot): + await bot.add_cog(Teleport(bot)) diff --git a/teleport/info.json b/teleport/info.json new file mode 100644 index 0000000..58b1a65 --- /dev/null +++ b/teleport/info.json @@ -0,0 +1,5 @@ +{ + "author": ["Arjun Satarkar"], + "description": "Teleport between channels to move a discussion easily.", + "short": "Teleport between channels to move a discussion easily." +} diff --git a/teleport/teleport.py b/teleport/teleport.py new file mode 100644 index 0000000..2f4b5a6 --- /dev/null +++ b/teleport/teleport.py @@ -0,0 +1,48 @@ +import discord +from redbot.core import commands + + +class Teleport(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command() + @commands.guild_only() + async def teleport( + self, + ctx: commands.GuildContext, + destination: discord.abc.GuildChannel | discord.Thread, + ): + if isinstance(destination, discord.Thread): + parent = destination.parent + else: + parent = destination + + if not ( + hasattr(destination, "send") + and parent.permissions_for(ctx.author).send_messages + and ( + not isinstance(destination, discord.Thread) + or parent.permissions_for(ctx.author).send_messages_in_threads + ) + ): + await ctx.react_quietly("❌") + return + + portal_to_template = "Portal opened to {dest}\n*(done by {user})*" + source_message = await ctx.send( + portal_to_template.format( + dest=destination.mention, user=ctx.author.mention + ), + allowed_mentions=discord.AllowedMentions.none(), + ) + dest_message = await destination.send( + f"Portal opened from {source_message.jump_url}\n*(done by {ctx.author.mention})*", + allowed_mentions=discord.AllowedMentions.none(), + ) + await source_message.edit( + content=portal_to_template.format( + dest=dest_message.jump_url, user=ctx.author.mention + ), + allowed_mentions=discord.AllowedMentions.none(), + ) -- cgit v1.2.3-57-g22cb