Skip to content

Commit

Permalink
Fixing staff requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikey committed Jan 7, 2025
1 parent dbd41d8 commit 21de081
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cogs/GameLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def staff_request(self, ctx: commands.Context, reason: str):
)
)

last_submitted_staff_request = [i async for i in self.bot.staff_requests.find({"user_id": ctx.author.id, "guild_id": ctx.guild.id}).sort({"_id": -1}).limit(1)]
last_submitted_staff_request = [i async for i in self.bot.staff_requests.db.find({"user_id": ctx.author.id, "guild_id": ctx.guild.id}).sort({"_id": -1}).limit(1)]
if len(last_submitted_staff_request) != 0:
last_submitted_staff_request = last_submitted_staff_request[0]
document_id: ObjectId = last_submitted_staff_request["_id"]
Expand Down
83 changes: 83 additions & 0 deletions events/on_staff_request_send.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import aiohttp
import discord
from discord.ext import commands
import bson
from erm import Bot
from bson import ObjectId
from decouple import config

from menus import AcknowledgeStaffRequest
from utils import prc_api
from utils.constants import BLANK_COLOR


class OnStaffRequestSend(commands.Cog):
def __init__(self, bot: Bot):
self.bot = bot

@commands.Cog.listener()
async def on_staff_request_send(self, o_id: ObjectId):
doc = await self.bot.staff_requests.db.find_one({"_id": o_id})
user_id = doc["user_id"]
guild_id = doc["guild_id"]
reason = doc["reason"]

settings = await self.bot.settings.db.find_one({"_id": guild_id})
staff_requests = settings.get("game_logging", {}).get("staff_requests", {})
if staff_requests == {}:
return

is_erlc = bool(await self.bot.server_keys.db.count_documents({"_id": guild_id}))
players_ingame = -1
staff_ingame = -1
if is_erlc:
try:
players = await self.bot.prc_api.get_server_players(
guild_id
)
except prc_api.ResponseFailure:
players = []

if len(players) > 0:
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})

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)
newline = "\n"

embed = discord.Embed(
title="Staff Request Received",
description="A new staff request has been received from <@{0}> ({0})".format(user_id),
color=BLANK_COLOR
).set_thumbnail(
url=user.display_avatar.url
).add_field(
name="Request Information",
value=(
f"> **Reason:** {reason}\n"
f"> **Requested By:** <@{user_id}>"
),
inline=False
).add_field(
name="Staff Information",
value=(
f"{'> **Players In-Game:** {0}{1}'.format(str(players_ingame), newline) if players_ingame > 0 else ''}"
f"> **Staff Clocked In:** {staff_clocked_in}\n"
f"{'> **Staff In-Game:** {0}{1}'.format(str(staff_ingame), newline) if staff_ingame > 0 else ''}"
)
)

mentioned_roles = staff_requests.get("mentioned_roles", [])
channel_id = staff_requests["channel"]
channel = guild.get_channel(channel_id) or await guild.fetch_channel(channel_id)

await channel.send(
', '.join(["<@&{0}>".format(role) for role in mentioned_roles]),
embed=embed,
allowed_mentions=discord.AllowedMentions.all(),
view=AcknowledgeStaffRequest(o_id)
)

0 comments on commit 21de081

Please sign in to comment.