diff options
author | Arjun Satarkar <me@arjunsatarkar.net> | 2024-03-22 21:03:33 +0000 |
---|---|---|
committer | Arjun Satarkar <me@arjunsatarkar.net> | 2024-03-22 21:03:33 +0000 |
commit | e64373979384c82580d7b8db582d48897096b992 (patch) | |
tree | 0b162a881da9066f783af1c70c14ec91eab0f2cc /teleport/teleport.py | |
parent | 08069e8d35e10a85087c1938fffb4f5a8c625e14 (diff) | |
download | aps-cogs-e64373979384c82580d7b8db582d48897096b992.tar aps-cogs-e64373979384c82580d7b8db582d48897096b992.tar.gz aps-cogs-e64373979384c82580d7b8db582d48897096b992.zip |
Add teleport cog
Diffstat (limited to 'teleport/teleport.py')
-rw-r--r-- | teleport/teleport.py | 48 |
1 files changed, 48 insertions, 0 deletions
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(), + ) |