Skip to content

Commit

Permalink
fix: only check send_messages where inbox will be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
thegamecracks committed Jul 2, 2024
1 parent cdc36e3 commit 4425493
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 174 deletions.
34 changes: 24 additions & 10 deletions src/theticketbot/cogs/inbox/cog_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
if TYPE_CHECKING:
from theticketbot.cogs.select import MessageCallback

REQUIRED_DESTINATION_PERMISSIONS = discord.Permissions(
view_channel=True,
create_private_threads=True,
send_messages_in_threads=True,
)

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -134,18 +140,13 @@ async def check_inbox_message(
content = content.format(message.jump_url)
raise AppCommandResponse(content)

async def check_inbox_permissions(
async def check_bot_permissions(
self,
interaction: discord.Interaction,
channel: discord.TextChannel,
required: discord.Permissions,
) -> None:
bot_permissions = channel.permissions_for(channel.guild.me)
required = discord.Permissions(
view_channel=True,
send_messages=True,
create_private_threads=True,
send_messages_in_threads=True,
)
missing = bot_permissions & required ^ required
if missing:
missing = ", ".join(f"`{name}`" for name, value in missing if value)
Expand Down Expand Up @@ -182,10 +183,19 @@ async def create(
destination: discord.TextChannel | None,
):
assert interaction.guild is not None
destination = destination or channel

# TODO: limit number of inboxes per guild
destination = destination or channel
await self.check_inbox_permissions(interaction, destination)

channel_perms = discord.Permissions(view_channel=True, send_messages=True)
destination_perms = REQUIRED_DESTINATION_PERMISSIONS

if channel != destination:
await self.check_bot_permissions(interaction, channel, channel_perms)
else:
destination_perms = destination_perms | channel_perms

await self.check_bot_permissions(interaction, destination, destination_perms)

content = _(
# Message sent when the user is creating a new inbox in a channel,
Expand Down Expand Up @@ -348,7 +358,11 @@ async def channel(
interaction: discord.Interaction,
channel: discord.TextChannel,
):
await self.check_inbox_permissions(interaction, channel)
await self.check_bot_permissions(
interaction,
channel,
REQUIRED_DESTINATION_PERMISSIONS,
)
content = _(
# Message sent when a user is editing an inbox's destination,
# and an inbox needs to be selected
Expand Down
82 changes: 41 additions & 41 deletions src/theticketbot/locales/de/LC_MESSAGES/theticketbot.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.4.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-01 16:38-0400\n"
"POT-Creation-Date: 2024-07-01 22:44-0400\n"
"PO-Revision-Date: 2024-06-07 17:04+0200\n"
"Last-Translator: MRGalaxy <[email protected]."
"com>\n"
Expand Down Expand Up @@ -118,19 +118,19 @@ msgstr ""

#. Command group name
#. (alternatively translated as "panel")
#: src/theticketbot/cogs/inbox/cog_group.py:62
#: src/theticketbot/cogs/inbox/cog_group.py:68
msgid "inbox"
msgstr "panel"

#. Command group description ("inbox")
#: src/theticketbot/cogs/inbox/cog_group.py:64
#: src/theticketbot/cogs/inbox/cog_group.py:70
msgid "Manage the server's ticket inboxes."
msgstr "Verwalten Sie die Ticket-Panels des Servers."

#. Message sent when selecting a non-inbox message
#. that looks like the message used to be an inbox
#. {0}: the message's link
#: src/theticketbot/cogs/inbox/cog_group.py:122
#: src/theticketbot/cogs/inbox/cog_group.py:128
#, python-brace-format
msgid "Sorry, {0} is no longer recognized as an inbox and must be re-created."
msgstr ""
Expand All @@ -139,7 +139,7 @@ msgstr ""

#. Message sent when selecting a non-inbox message
#. {0}: the message's link
#: src/theticketbot/cogs/inbox/cog_group.py:129
#: src/theticketbot/cogs/inbox/cog_group.py:135
#, python-brace-format
msgid ""
"Sorry, {0} is not an inbox. The message you select should have a **Create "
Expand All @@ -151,44 +151,44 @@ msgstr ""
#. Message sent when attempting to create an inbox with insufficient permissions
#. {0}: the channel's mention
#. {1}: a list of permissions that are missing
#: src/theticketbot/cogs/inbox/cog_group.py:155
#: src/theticketbot/cogs/inbox/cog_group.py:156
#, python-brace-format
msgid "I need the following permissions in {0}: {1}"
msgstr "Ich benötige die folgenden Berechtigungen in {0}: {1}"

#. Subcommand name ("inbox")
#: src/theticketbot/cogs/inbox/cog_group.py:162
#: src/theticketbot/cogs/inbox/cog_group.py:163
msgid "create"
msgstr "erstelle"

#. Subcommand description ("inbox create")
#: src/theticketbot/cogs/inbox/cog_group.py:164
#: src/theticketbot/cogs/inbox/cog_group.py:165
msgid "Create a new inbox."
msgstr "Erstellen Sie ein neues Panel."

#. Subcommand parameter name ("inbox create")
#. Subcommand parameter name ("inbox destination")
#: src/theticketbot/cogs/inbox/cog_group.py:168
#: src/theticketbot/cogs/inbox/cog_group.py:340
#: src/theticketbot/cogs/inbox/cog_group.py:169
#: src/theticketbot/cogs/inbox/cog_group.py:350
msgid "channel"
msgstr "kanal"

#. Subcommand parameter name ("inbox create")
#. Subcommand name ("inbox")
#: src/theticketbot/cogs/inbox/cog_group.py:170
#: src/theticketbot/cogs/inbox/cog_group.py:334
#: src/theticketbot/cogs/inbox/cog_group.py:171
#: src/theticketbot/cogs/inbox/cog_group.py:344
msgid "destination"
msgstr ""

#. Subcommand parameter description ("inbox create <channel>")
#: src/theticketbot/cogs/inbox/cog_group.py:174
#: src/theticketbot/cogs/inbox/cog_group.py:175
msgid "The channel to post the inbox."
msgstr "Der Kanal, in dem das Panel gepostet wird."

#. Subcommand parameter description ("inbox create <channel>")
#. Subcommand parameter description ("inbox destination <channel>")
#: src/theticketbot/cogs/inbox/cog_group.py:176
#: src/theticketbot/cogs/inbox/cog_group.py:344
#: src/theticketbot/cogs/inbox/cog_group.py:177
#: src/theticketbot/cogs/inbox/cog_group.py:354
#, fuzzy
msgid "The channel to route new tickets."
msgstr "Der Kanal, in dem das Panel gepostet wird."
Expand All @@ -197,7 +197,7 @@ msgstr "Der Kanal, in dem das Panel gepostet wird."
#. and the inbox needs a message to be included
#. {0}: the channel's mention
#. {1}: the destination's mention
#: src/theticketbot/cogs/inbox/cog_group.py:195
#: src/theticketbot/cogs/inbox/cog_group.py:205
#, fuzzy, python-brace-format
msgid ""
"Your inbox will be posted in {0} and tickets will be created in {1}. You "
Expand All @@ -212,7 +212,7 @@ msgstr ""
"auswählen*."

#. The default starter message content for new tickets
#: src/theticketbot/cogs/inbox/cog_group.py:248
#: src/theticketbot/cogs/inbox/cog_group.py:258
msgid ""
"$author Thank you for creating a ticket!\n"
"$staff"
Expand All @@ -222,14 +222,14 @@ msgstr ""

#. Message sent after a user creates an inbox
#. {0}: the inbox's link
#: src/theticketbot/cogs/inbox/cog_group.py:267
#: src/theticketbot/cogs/inbox/cog_group.py:277
#, python-brace-format
msgid "Your inbox has been created! {0}"
msgstr "Ihr Panel wurde erstellt! {0}"

#. Message sent when attempting to create an inbox with too large attachments
#. {0}: the maximum cumulative filesize
#: src/theticketbot/cogs/inbox/cog_group.py:289
#: src/theticketbot/cogs/inbox/cog_group.py:299
#, python-brace-format
msgid ""
"The message's attachments are too large! The total size must be under {0}."
Expand All @@ -238,7 +238,7 @@ msgstr ""
"liegen."

#. Subcommand description ("inbox destination")
#: src/theticketbot/cogs/inbox/cog_group.py:336
#: src/theticketbot/cogs/inbox/cog_group.py:346
#, fuzzy
msgid "Edit the destination channel for an inbox."
msgstr "Bearbeiten Sie die Nachricht für ein Panel."
Expand All @@ -251,10 +251,10 @@ msgstr "Bearbeiten Sie die Nachricht für ein Panel."
#. and an inbox needs to be selected
#. Message sent when a user is changing the name for new tickets,
#. and an inbox needs to be selected
#: src/theticketbot/cogs/inbox/cog_group.py:355
#: src/theticketbot/cogs/inbox/cog_group.py:409
#: src/theticketbot/cogs/inbox/cog_group.py:533
#: src/theticketbot/cogs/inbox/cog_group.py:562
#: src/theticketbot/cogs/inbox/cog_group.py:369
#: src/theticketbot/cogs/inbox/cog_group.py:423
#: src/theticketbot/cogs/inbox/cog_group.py:547
#: src/theticketbot/cogs/inbox/cog_group.py:576
msgid ""
"You must now select the inbox you want to edit. To do this, right click or "
"long tap a message, then open Apps and pick the *Select this message* "
Expand All @@ -268,7 +268,7 @@ msgstr ""
#. Message sent when an inbox's old and new destination are the same
#. {0}: the inbox's link
#. {1}: the destination's link
#: src/theticketbot/cogs/inbox/cog_group.py:379
#: src/theticketbot/cogs/inbox/cog_group.py:393
#, python-brace-format
msgid "{0} is already routing tickets to {1} !"
msgstr ""
Expand All @@ -277,33 +277,33 @@ msgstr ""
#. {0}: the inbox's link
#. {1}: the old destination's link
#. {2}: the new destination's link
#: src/theticketbot/cogs/inbox/cog_group.py:394
#: src/theticketbot/cogs/inbox/cog_group.py:408
#, python-brace-format
msgid "{0} will now route tickets to {2} instead of {1} !"
msgstr ""

#. Subcommand name ("inbox")
#: src/theticketbot/cogs/inbox/cog_group.py:401
#: src/theticketbot/cogs/inbox/cog_group.py:415
msgid "message"
msgstr "nachricht"

#. Subcommand description ("inbox message")
#: src/theticketbot/cogs/inbox/cog_group.py:403
#: src/theticketbot/cogs/inbox/cog_group.py:417
msgid "Edit the message for an inbox."
msgstr "Bearbeiten Sie die Nachricht für ein Panel."

#. Message sent when a user is editing an inbox's message,
#. and a second message needs to be selected to copy its contents
#. {0}: the inbox's link
#: src/theticketbot/cogs/inbox/cog_group.py:429
#: src/theticketbot/cogs/inbox/cog_group.py:443
#, python-brace-format
msgid "{0} will be edited. Please select the message you want to copy."
msgstr ""
"{0} wird bearbeitet. Bitte wählen Sie die Nachricht aus, die Sie kopieren "
"möchten."

#. Message sent when a user tries to edit an inbox message with itself
#: src/theticketbot/cogs/inbox/cog_group.py:447
#: src/theticketbot/cogs/inbox/cog_group.py:461
msgid ""
"The inbox message cannot be edited with itself. Please select another "
"message you want to copy."
Expand All @@ -313,25 +313,25 @@ msgstr ""

#. Message sent after a user edits an inbox's message
#. {0}: the inbox's link
#: src/theticketbot/cogs/inbox/cog_group.py:471
#: src/theticketbot/cogs/inbox/cog_group.py:485
#, python-brace-format
msgid "{0} has been updated!"
msgstr "{0} wurde aktualisiert!"

# The German translation means team member which is more fitting in German as we are not employed.
#. Subcommand name ("inbox")
#: src/theticketbot/cogs/inbox/cog_group.py:477
#: src/theticketbot/cogs/inbox/cog_group.py:491
msgid "staff"
msgstr "teammitglieder"

#. Subcommand description ("inbox staff")
#: src/theticketbot/cogs/inbox/cog_group.py:479
#: src/theticketbot/cogs/inbox/cog_group.py:493
msgid "Manage staff for an inbox."
msgstr "Verwalten Sie die Teammitglieder für ein Panel."

#. Message sent when a user is managing staff for an inbox,
#. and an inbox needs to be selected
#: src/theticketbot/cogs/inbox/cog_group.py:485
#: src/theticketbot/cogs/inbox/cog_group.py:499
msgid ""
"You must now select the inbox you want to manage staff for. To do this, "
"right click or long tap a message, then open Apps and pick the *Select this "
Expand All @@ -344,38 +344,38 @@ msgstr ""

#. Message sent above select menus when presenting an inbox's staff
#. {0}: the inbox's link
#: src/theticketbot/cogs/inbox/cog_group.py:505
#: src/theticketbot/cogs/inbox/cog_group.py:519
#, python-brace-format
msgid "Staff for {0} :"
msgstr "Teammitglieder für {0} :"

#. Subcommand group name ("inbox")
#: src/theticketbot/cogs/inbox/cog_group.py:518
#: src/theticketbot/cogs/inbox/cog_group.py:532
msgid "new-tickets"
msgstr "neue-tickets"

#. Subcommand group description ("inbox new-tickets")
#: src/theticketbot/cogs/inbox/cog_group.py:520
#: src/theticketbot/cogs/inbox/cog_group.py:534
msgid "Manage new tickets created by an inbox."
msgstr "Verwalten Sie neue Tickets, die von einem Panel erstellt wurden."

#. Subcommand name ("inbox new-tickets")
#: src/theticketbot/cogs/inbox/cog_group.py:525
#: src/theticketbot/cogs/inbox/cog_group.py:539
msgid "starter"
msgstr "startnachricht"

#. Subcommand description ("inbox new-tickets starter")
#: src/theticketbot/cogs/inbox/cog_group.py:527
#: src/theticketbot/cogs/inbox/cog_group.py:541
msgid "Set the starting message for new tickets."
msgstr "Legen Sie die Startnachricht für neue Tickets fest."

#. Subcommand name ("inbox new-tickets")
#: src/theticketbot/cogs/inbox/cog_group.py:554
#: src/theticketbot/cogs/inbox/cog_group.py:568
msgid "name"
msgstr "name"

#. Subcommand description ("inbox new-tickets name")
#: src/theticketbot/cogs/inbox/cog_group.py:556
#: src/theticketbot/cogs/inbox/cog_group.py:570
msgid "Set the name for new tickets."
msgstr "Legen Sie den Namen für neue Tickets fest."

Expand Down
Loading

0 comments on commit 4425493

Please sign in to comment.