Skip to content

Commit

Permalink
Fixed most issues with staff requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikey committed Jan 7, 2025
1 parent a3c80c8 commit 29de4af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
23 changes: 23 additions & 0 deletions cogs/GameLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ async def staff_request(self, ctx: commands.Context, reason: str):
color=BLANK_COLOR
)
)


staff_clocked_in = await self.bot.shift_management.shifts.db.count_documents({"EndEpoch": 0, "Guild": ctx.guild.id})
if staff_requests.get("min_staff") is not None and staff_requests.get("min_staff") > 0:
if staff_clocked_in >= staff_requests.get("min_staff", 0):
return await ctx.send(
embed=discord.Embed(
title="Minimum Staff",
description=f"**{staff_requests.get('min_staff')}** members of staff are required to be in-game for a Staff Request!",
color=BLANK_COLOR
)
)

if staff_requests.get("max_staff") is not None and staff_requests.get("max_staff") > 0:
if staff_clocked_in < staff_requests.get("max_staff", 0):
return await ctx.send(
embed=discord.Embed(
title="Maximum Staff",
description="There are more than the maximum number of staff online for a Staff Request!",
color=BLANK_COLOR
)
)

document = {
"user_id": ctx.author.id,
"guild_id": ctx.guild.id,
Expand Down
4 changes: 2 additions & 2 deletions events/on_staff_request_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def on_staff_request_send(self, o_id: ObjectId):
players_ingame = len(players)
staff_ingame = len(list(filter(lambda x: x.permission != "Player", players)))

staff_clocked_in = await self.bot.shift_management.db.count_documents({"EndEpoch": 0, "Guild": guild_id})
staff_clocked_in = await self.bot.shift_management.shifts.db.count_documents({"EndEpoch": 0, "Guild": guild_id})

guild = self.bot.get_guild(guild_id) or await self.bot.fetch_guild(guild_id)
user = guild.get_member(user_id) or await self.bot.fetch_user(user_id)
Expand Down Expand Up @@ -78,7 +78,7 @@ async def on_staff_request_send(self, o_id: ObjectId):
', '.join(["<@&{0}>".format(role) for role in mentioned_roles]),
embed=embed,
allowed_mentions=discord.AllowedMentions.all(),
view=AcknowledgeStaffRequest(o_id)
view=AcknowledgeStaffRequest(self.bot, o_id)
)

async def setup(bot):
Expand Down
14 changes: 8 additions & 6 deletions menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4467,13 +4467,14 @@ async def _delete(self, interaction: discord.Interaction, button: discord.ui.But
self.stop()

class AcknowledgeStaffRequest(discord.ui.View):
def __init__(self, o_id: ObjectId):
super().__init__()
def __init__(self, bot: commands.Bot, o_id: ObjectId):
super().__init__(timeout=None)
self.bot = bot
self.o_id = o_id

@discord.ui.button(label="Acknowledge", style=discord.ButtonStyle.secondary)
async def acknowledge(self, interaction: discord.Interaction, button: discord.ui.Button):
document = await interaction.bot.staff_requests.find_one({"_id": self.o_id})
document = await self.bot.staff_requests.db.find_one({"_id": self.o_id})
if interaction.user.id in document["acked"]:
return await interaction.response.send_message(
embed=discord.Embed(
Expand All @@ -4484,13 +4485,14 @@ async def acknowledge(self, interaction: discord.Interaction, button: discord.ui
ephemeral=True
)
document["acked"].append(interaction.user.id)
await self.bot.staff_requests.db.update_one({"_id": document["_id"]}, {"$set": {"acked": document["acked"]}})
embed = interaction.message.embeds[0]
if embed.fields[-1].name == "Acknowledgements":
if embed.fields[-1].name.startswith("Acknowledgements"):
index = len(embed.fields) - 1
embed.set_field_at(index, value="\n".join(["> <@{}>".format(u) for u in document["acked"]]))
embed.set_field_at(index, name="Acknowledgements [{}]".format(len(document["acked"])), value="\n".join(["> <@{}>".format(u) for u in document["acked"]]))
else:
embed.add_field(
name="Acknowledgements",
name="Acknowledgements [1]",
value="\n".join(["> <@{}>".format(u) for u in document["acked"]]),
inline=False
)
Expand Down

0 comments on commit 29de4af

Please sign in to comment.