import nextcord from nextcord.ext import commands, application_checks from nextcord import TextInputStyle import random import aiosqlite as sqlite3 import aiohttp from urllib.parse import urlparse import os class GameView(nextcord.ui.View): def __init__(self): super().__init__(timeout=None) @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): if application_checks.check(application_checks.has_permissions(manage_roles=True)): await interaction.response.send_message(f"You don't have permission! {application_checks.check(application_checks.has_permissions(manage_roles=True))}", ephemeral=True) ogmsg = interaction.message.content.split("\n") ogmsg.pop(0) message = "It has been decreed..\n" found = False turnover = False for i in range(len(ogmsg)): if ogmsg[i].startswith("~"): message = f"{message}{ogmsg[i]}\n" continue if not found: newmsg = "~~" + ogmsg[i] + "~~" message = message + newmsg + "\n" found = True try: turnping = ogmsg[i+1].split("<")[1].split(">")[0] except IndexError: message = message + "The turn is over" turnover = True continue else: message = message + ogmsg[i] + "\n" print(interaction.user.guild_permissions) await interaction.response.edit_message(content=message) if turnover: await interaction.followup.send(f"The turn has concluded") else: await interaction.followup.send(f"<{turnping}> it is now your turn!") return class gameutils(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot @commands.Cog.listener('on_ready') async def gameready(self): self.bot.add_view(GameView()) @nextcord.slash_command( name="turngen", description="Roll the next turn for a certian role", guild_ids=[699285282276507708], ) @nextcord.ext.application_checks.has_permissions(manage_roles=True) async def turngen(self, interaction: nextcord.Interaction, role: nextcord.Role): message = "It has been decreed..\n" users = role.members random.shuffle(users) for i in range(len(users)): message = message + f"{str(i+1)}\. <@{users[i].id}>\n" await interaction.response.send_message(message, view=GameView(), allowed_mentions=nextcord.AllowedMentions.none()) await interaction.followup.send(f"<@{users[0].id}> it is now your turn!") def setup(bot: commands.Bot): bot.add_cog(gameutils(bot))