This commit is contained in:
insert 2024-08-10 16:48:23 -04:00
parent 08986386b3
commit af7a4bce0a
Signed by: insert
GPG key ID: A70775C389ACF105
2 changed files with 34 additions and 11 deletions

View file

@ -15,7 +15,7 @@ class GameView(nextcord.ui.View):
@nextcord.ui.button(
label="Next Turn", style=nextcord.ButtonStyle.green, custom_id="gameutils:nextturn"
)
async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
async def nextturn(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
ogmsg = interaction.message.content.split("\n")
ogmsg.pop(0)
message = "It has been decreed..\n"

View file

@ -15,21 +15,14 @@ class RoleView(nextcord.ui.View):
for b in buttonlist:
b.callback = self.buttoncallback
self.add_item(b)
#res = await self.bot.cur.execute(f"SELECT roleid FROM rolebutton WHERE serverid = {self.bot.roleguild.id}")
button = nextcord.ui.Button(label="Test", style=nextcord.ButtonStyle.gray, custom_id="rolebutton:821095192831852554")
button.callback = self.buttoncallback
self.add_item(button)
button = nextcord.ui.Button(label="Test 2", style=nextcord.ButtonStyle.gray, custom_id="rolebutton:1058708072064884736")
button.callback = self.buttoncallback
self.add_item(button)
async def buttoncallback(self, interaction: nextcord.Interaction) -> None:
role = interaction.guild.get_role(int(interaction.data["custom_id"].split(":")[1]))
if role in interaction.user.roles:
await interaction.user.remove_roles(role, reason=f"{interaction.user.display_name} used role button")
await interaction.user.remove_roles(role, reason=f"{interaction.user.name} used role button")
await interaction.response.send_message(f"Removed <@&{role.id}> from you!", ephemeral=True, allowed_mentions=nextcord.AllowedMentions.none())
else:
await interaction.user.add_roles(role, reason=f"{interaction.user.display_name} used role button")
await interaction.user.add_roles(role, reason=f"{interaction.user.name} used role button")
await interaction.response.send_message(f"Added <@&{role.id}> to you!", ephemeral=True, allowed_mentions=nextcord.AllowedMentions.none())
return
@ -60,9 +53,10 @@ class rolebutton(commands.Cog):
await interaction.response.send_message(view=RoleView(self.bot))
@nextcord.message_command(
name="Refresh role buttons",
name="Refresh Role Buttons",
default_member_permissions=nextcord.Permissions(manage_roles=True),
)
@nextcord.ext.application_checks.has_permissions(manage_roles=True)
async def rolerefresh(self, interaction: nextcord.Interaction, message: nextcord.Message):
if message.author.id != self.bot.application_id:
@ -79,6 +73,24 @@ class rolebutton(commands.Cog):
await message.edit(view=RoleView(self.bot))
await interaction.response.send_message("Edited!", ephemeral=True)
@rolebuttons.subcommand(
name="create",
description="Create a role message",
)
@nextcord.ext.application_checks.has_permissions(manage_roles=True)
async def rolecreate(self, interaction: nextcord.Interaction, content: str):
res = await self.bot.cur.execute(f"SELECT roleid FROM rolebutton WHERE serverid = {interaction.guild.id}")
res = await res.fetchall()
buttonlist.clear()
for [r] in res:
role = interaction.guild.get_role(int(r))
role.name
button = nextcord.ui.Button(label=role.name, style=nextcord.ButtonStyle.gray, custom_id=f"rolebutton:{role.id}")
buttonlist.append(button)
await interaction.channel.send(content=content, view=RoleView(self.bot))
await interaction.response.send_message("Done", ephemeral=True)
@rolebuttons.subcommand(
name="add",
description="add a role to the selection message",
@ -91,6 +103,17 @@ class rolebutton(commands.Cog):
await self.bot.db.commit()
await interaction.response.send_message("Done", ephemeral=True)
@rolebuttons.subcommand(
name="remove",
description="remove a role from the selection message",
)
async def roleremove(self, interaction: nextcord.Interaction, role: nextcord.Role):
await self.bot.cur.execute(f"""
DELETE FROM rolebutton WHERE serverid = {interaction.guild.id} AND roleid = {role.id})
""")
await self.bot.db.commit()
await interaction.response.send_message("Done", ephemeral=True)
def setup(bot: commands.Bot):
bot.add_cog(rolebutton(bot))