2024-08-10 17:30:06 +00:00
|
|
|
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
|
|
|
|
|
2024-08-10 18:12:04 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
2024-08-10 20:48:23 +00:00
|
|
|
async def nextturn(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
|
2024-08-10 18:41:44 +00:00
|
|
|
ogmsg = interaction.message.content.split("\n")
|
2024-08-10 18:12:04 +00:00
|
|
|
ogmsg.pop(0)
|
|
|
|
message = "It has been decreed..\n"
|
|
|
|
found = False
|
2024-08-10 19:48:39 +00:00
|
|
|
turnover = False
|
2024-08-10 19:02:33 +00:00
|
|
|
for i in range(len(ogmsg)):
|
|
|
|
if ogmsg[i].startswith("~"):
|
2024-08-10 19:31:52 +00:00
|
|
|
message = f"{message}{ogmsg[i]}\n"
|
2024-08-10 18:12:04 +00:00
|
|
|
continue
|
|
|
|
if not found:
|
2024-08-10 19:02:33 +00:00
|
|
|
newmsg = "~~" + ogmsg[i] + "~~"
|
|
|
|
message = message + newmsg + "\n"
|
2024-08-10 19:37:41 +00:00
|
|
|
found = True
|
|
|
|
try:
|
|
|
|
turnping = ogmsg[i+1].split("<")[1].split(">")[0]
|
|
|
|
except IndexError:
|
|
|
|
message = message + "The turn is over"
|
|
|
|
turnover = True
|
2024-08-10 18:12:04 +00:00
|
|
|
continue
|
|
|
|
else:
|
2024-08-10 19:02:33 +00:00
|
|
|
message = message + ogmsg[i] + "\n"
|
2024-08-10 19:37:41 +00:00
|
|
|
if turnover:
|
2024-08-10 19:58:42 +00:00
|
|
|
await interaction.response.edit_message(content=message,view=None)
|
|
|
|
await interaction.followup.send(f"The turn has concluded")
|
2024-08-10 19:37:41 +00:00
|
|
|
else:
|
2024-08-10 19:58:42 +00:00
|
|
|
await interaction.response.edit_message(content=message)
|
2024-08-10 19:37:41 +00:00
|
|
|
await interaction.followup.send(f"<{turnping}> it is now your turn!")
|
2024-08-10 18:12:04 +00:00
|
|
|
return
|
|
|
|
|
2024-08-10 17:30:06 +00:00
|
|
|
class gameutils(commands.Cog):
|
|
|
|
|
|
|
|
def __init__(self, bot: commands.Bot):
|
|
|
|
self.bot = bot
|
2024-08-10 19:55:42 +00:00
|
|
|
#errors if first loaded but is needed after
|
|
|
|
try:
|
|
|
|
self.bot.add_view(GameView())
|
|
|
|
except:
|
|
|
|
pass
|
2024-08-10 17:30:06 +00:00
|
|
|
|
2024-08-10 19:20:40 +00:00
|
|
|
@commands.Cog.listener('on_ready')
|
|
|
|
async def gameready(self):
|
|
|
|
self.bot.add_view(GameView())
|
|
|
|
|
2024-08-10 17:30:06 +00:00
|
|
|
@nextcord.slash_command(
|
|
|
|
name="turngen",
|
|
|
|
description="Roll the next turn for a certian role",
|
|
|
|
guild_ids=[699285282276507708],
|
2024-08-10 20:27:03 +00:00
|
|
|
default_member_permissions=nextcord.Permissions(manage_roles=True),
|
2024-08-10 17:30:06 +00:00
|
|
|
)
|
|
|
|
@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)
|
2024-08-10 17:34:27 +00:00
|
|
|
for i in range(len(users)):
|
2024-08-10 18:43:57 +00:00
|
|
|
message = message + f"{str(i+1)}\. <@{users[i].id}>\n"
|
2024-08-10 18:56:01 +00:00
|
|
|
await interaction.response.send_message(message, view=GameView(), allowed_mentions=nextcord.AllowedMentions.none())
|
2024-08-10 18:24:48 +00:00
|
|
|
await interaction.followup.send(f"<@{users[0].id}> it is now your turn!")
|
2024-08-10 17:30:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup(bot: commands.Bot):
|
|
|
|
bot.add_cog(gameutils(bot))
|