aboutsummaryrefslogtreecommitdiff
path: root/teleport
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-03-26 19:26:06 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-03-26 19:26:06 +0000
commit23ba0fb8fc5070ba30a43035970775247da370f3 (patch)
treecf5ece53be0c5197a0c2b9d8c7233436ec6ba2e9 /teleport
parent8b0d67202a0ebbfa17d53d56bef9e515574bdb66 (diff)
downloadaps-cogs-23ba0fb8fc5070ba30a43035970775247da370f3.tar
aps-cogs-23ba0fb8fc5070ba30a43035970775247da370f3.tar.gz
aps-cogs-23ba0fb8fc5070ba30a43035970775247da370f3.zip
teleport: don't teleport within same channel, better text
Diffstat (limited to 'teleport')
-rw-r--r--teleport/teleport.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/teleport/teleport.py b/teleport/teleport.py
index a4c8100..f529e91 100644
--- a/teleport/teleport.py
+++ b/teleport/teleport.py
@@ -2,6 +2,7 @@ import discord
from redbot.core import commands
import redbot.core
+
class Teleport(commands.Cog):
def __init__(self, bot):
self.bot = bot
@@ -13,7 +14,7 @@ class Teleport(commands.Cog):
ctx: commands.GuildContext,
destination: discord.abc.GuildChannel | discord.Thread,
*,
- reason: str | None
+ topic: str | None,
):
if isinstance(destination, discord.Thread):
parent = destination.parent
@@ -27,26 +28,35 @@ class Teleport(commands.Cog):
not isinstance(destination, discord.Thread)
or parent.permissions_for(ctx.author).send_messages_in_threads
)
+ ) or (
+ (type(ctx.channel) is type(destination))
+ and ctx.channel.id == destination.id
):
await ctx.react_quietly("❌")
return
- formatted_reason = redbot.core.utils.chat_formatting.italics(reason) if reason else ""
+ formatted_topic = (
+ redbot.core.utils.chat_formatting.italics(topic) if topic else ""
+ )
- portal_to_template = "Portal opened to {dest}" f" : {formatted_reason}\n*(done by {ctx.author.mention})*"
+ # The space before the colon is necessary to prevent unwanted embeds
+ # of the link due to the way Discord parses messages as of 2024-03-24.
+ portal_to_template = (
+ "Portal opened to {dest}"
+ + (f" : {formatted_topic}" if formatted_topic else "")
+ + f"\n*(done by {ctx.author.mention})*"
+ )
source_message = await ctx.send(
- portal_to_template.format(
- dest=destination.mention
- ),
+ portal_to_template.format(dest=destination.mention),
allowed_mentions=discord.AllowedMentions.none(),
)
dest_message = await destination.send(
- f"Portal opened from {source_message.jump_url} : {formatted_reason}\n*(done by {ctx.author.mention})*",
+ f"Portal opened from {source_message.jump_url}"
+ + (f" : {formatted_topic}" if formatted_topic else "")
+ + f"\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
- ),
+ content=portal_to_template.format(dest=dest_message.jump_url),
allowed_mentions=discord.AllowedMentions.none(),
)