Skip to content

Commit

Permalink
fix(autojoinroles): fix permission check when owner
Browse files Browse the repository at this point in the history
  • Loading branch information
Pukimaa committed Feb 2, 2023
1 parent c6f7f5d commit c2bdbb4
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions cogs/config/autojoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,32 @@
async def autojoin_logic(
bot: TakoBot, interaction: discord.Interaction, role: discord.Role, column: str
):
language = get_language(bot, interaction.guild.id)
language = get_language(bot, interaction.guild_id)
if (
role.is_default()
or role.is_bot_managed()
or role.managed
or not role.is_assignable()
or role >= interaction.user.top_role
or role >= interaction.user.top_role # type: ignore
and interaction.guild.owner_id != interaction.user.id if interaction.guild else True
):
return await interaction.response.send_message(
i18n.t("config.invalid_role", locale=language), ephemeral=True
)
data = await bot.db_pool.fetchrow(
"SELECT * FROM guilds WHERE guild_id = $1", interaction.guild.id
"SELECT * FROM guilds WHERE guild_id = $1", interaction.guild_id
)
if not data:
if column == "join_roles_user":
await bot.db_pool.execute(
"INSERT INTO guilds (guild_id, join_roles_user) VALUES ($1, $2)",
interaction.guild.id,
interaction.guild_id,
[role.id],
)
else:
await bot.db_pool.execute(
"INSERT INTO guilds (guild_id, join_roles_bot) VALUES ($1, $2)",
interaction.guild.id,
interaction.guild_id,
[role.id],
)
return await interaction.response.send_message(
Expand All @@ -49,13 +50,13 @@ async def autojoin_logic(
await bot.db_pool.execute(
"UPDATE guilds SET join_roles_user = $1 WHERE guild_id = $2",
array,
interaction.guild.id,
interaction.guild_id,
)
else:
await bot.db_pool.execute(
"UPDATE guilds SET join_roles_bot = $1 WHERE guild_id = $2",
array,
interaction.guild.id,
interaction.guild_id,
)
return await interaction.response.send_message(
i18n.t("config.autojoinroles_added", role=role.name, locale=language),
Expand All @@ -66,13 +67,13 @@ async def autojoin_logic(
await bot.db_pool.execute(
"UPDATE guilds SET join_roles_user = $1 WHERE guild_id = $2",
array,
interaction.guild.id,
interaction.guild_id,
)
else:
await bot.db_pool.execute(
"UPDATE guilds SET join_roles_bot = $1 WHERE guild_id = $2",
array,
interaction.guild.id,
interaction.guild_id,
)
return await interaction.response.send_message(
i18n.t("config.autojoinroles_removed", role=role.name, locale=language),
Expand Down Expand Up @@ -108,6 +109,7 @@ async def user(self, interaction: discord.Interaction, role: discord.Role):
)
@app_commands.checks.has_permissions(manage_roles=True)
@app_commands.checks.bot_has_permissions(manage_roles=True)
@app_commands.guild_only()
@app_commands.describe(
role="The role that should be toggled in the autojoinrole list"
)
Expand All @@ -121,7 +123,7 @@ async def list(self, interaction: discord.Interaction):
await interaction.response.defer()
language = get_language(self.bot, interaction.guild.id)
data = await self.bot.db_pool.fetchrow(
"SELECT * FROM guilds WHERE guild_id = $1", interaction.guild.id
"SELECT * FROM guilds WHERE guild_id = $1", interaction.guild_id
)
thumbnail_path = await thumbnail(interaction.guild.id, "role", self.bot)
file = discord.File(thumbnail_path, filename="thumbnail.png")
Expand All @@ -132,7 +134,7 @@ async def list(self, interaction: discord.Interaction):
locale=language,
),
description=i18n.t("config.autojoinroles_desc", locale=language),
color=await get_color(self.bot, interaction.guild.id),
color=await get_color(self.bot, interaction.guild.id), # type: ignore
)
embed.set_thumbnail(url="attachment://thumbnail.png")
if not data:
Expand Down Expand Up @@ -160,7 +162,7 @@ async def list(self, interaction: discord.Interaction):
inline=False,
)
await interaction.followup.send(embed=embed, file=file)
delete_thumbnail(interaction.guild.id, "role")
delete_thumbnail(interaction.guild_id, "role") # type: ignore

@commands.Cog.listener()
async def on_member_join(self, member: discord.Member):
Expand Down

0 comments on commit c2bdbb4

Please sign in to comment.