Skip to content

Commit

Permalink
Fixing a lot more errors with V4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikey committed Dec 31, 2023
1 parent 9a57aff commit 27e07cf
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 166 deletions.
27 changes: 24 additions & 3 deletions cogs/ActivityMonitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ async def activity(self, ctx: commands.Context):
@require_settings()
async def activity_show(self, ctx: commands.Context, duration: str):
settings = await self.bot.settings.find_by_id(ctx.guild.id)

if not settings.get('shift_management').get('enabled'):
return await ctx.send(
embed=discord.Embed(
title="Not Enabled",
description="Shift Logging is not enabled on this server.",
color=BLANK_COLOR
)
)

try:
actual_conversion = time_converter(duration)
Expand All @@ -61,7 +68,12 @@ async def activity_show(self, ctx: commands.Context, duration: str):
if shift_time > 100_000_000:
continue
if shift_document['UserID'] not in all_staff.keys():
member = ctx.guild.get_member(shift_document['UserID'])
try:
member = await ctx.guild.fetch_member(shift_document['UserID'])
except discord.NotFound:
continue
if not member:
continue
roles = member.roles
sorted_roles = sorted(member.roles, key=lambda x: x.position)
selected_quota = 0
Expand Down Expand Up @@ -89,7 +101,16 @@ async def activity_show(self, ctx: commands.Context, duration: str):
for index, (user_id, (seconds, quota)) in enumerate(sorted_staff.items()):
print(seconds, quota)
leaderboard_string += f"**{index+1}.** <@{user_id}> • {td_format(datetime.timedelta(seconds=seconds))} {'<:check:1163142000271429662>' if seconds > quota else '<:xmark:1166139967920164915>'}\n"

if index == len(sorted_staff)-1:
break
else:
return await ctx.send(
embed=discord.Embed(
title="No Data",
description="There is no data to show for this period.",
color=BLANK_COLOR
)
)

embed = discord.Embed(
title=f"Activity Report ({duration})",
Expand Down
5 changes: 1 addition & 4 deletions cogs/ActivityNotices.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ async def send_activity_request(self, guild: discord.Guild, staff_channel: disco
"user_id": author.id,
"accepted": True,
"denied": False,
"voided": False,
"type": request_type.upper()
})]

Expand Down Expand Up @@ -156,7 +155,6 @@ async def core_command_admin(self, ctx: commands.Context, request_type_object: s
"user_id": victim.id,
"accepted": True,
"expired": True,
'started_at': {'$exists': True},
"denied": False,
"voided": False,
"type": request_type_object.upper()
Expand All @@ -167,7 +165,6 @@ async def core_command_admin(self, ctx: commands.Context, request_type_object: s
"user_id": victim.id,
"accepted": True,
"denied": False,
'started_at': {'$exists': True},
"voided": False,
"expired": False,
"type": request_type_object.upper()
Expand Down Expand Up @@ -198,7 +195,7 @@ async def core_command_admin(self, ctx: commands.Context, request_type_object: s
value=(
f"<:replytop:1138257149705863209> **Type:** {request_type_object.upper()}\n"
f"<:replymiddle:1138257195121791046> **Reason:** {current_notice['reason']}\n"
f"<:replymiddle:1138257195121791046> **Starts At:** <t:{current_notice['started_at']}>\n"
f"<:replymiddle:1138257195121791046> **Starts At:** <t:{current_notice.get('started_at', int(current_notice['_id'].split('_')[2]))}>\n"
f"<:replybottom:1138257250448855090> **Ends At:** <t:{current_notice['expiry']}>"
),
inline=False
Expand Down
4 changes: 2 additions & 2 deletions cogs/Punishments.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ async def task(interaction: discord.Interaction, _):

try:
id = int(id)
except:
except ValueError:
return await msg.edit(
embed=discord.Embed(
title="Invalid Identifier",
Expand Down Expand Up @@ -728,7 +728,7 @@ async def task(interaction: discord.Interaction, _):

try:
id = int(id)
except:
except ValueError:
return await msg.edit(
embed=discord.Embed(
title="Invalid Identifier",
Expand Down
184 changes: 99 additions & 85 deletions cogs/ShiftLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ShiftMenu,
AdministratedShiftMenu,
)
from utils.autocompletes import shift_type_autocomplete
from utils.autocompletes import shift_type_autocomplete, all_shift_type_autocomplete
from utils.constants import BLANK_COLOR, GREEN_COLOR, ORANGE_COLOR, RED_COLOR
from utils.paginators import SelectPagination, CustomPage
from utils.timestamp import td_format
Expand Down Expand Up @@ -64,7 +64,7 @@ async def duty_time(self, ctx, member: discord.Member = None):
shift_channel = discord.utils.get(
ctx.guild.channels, id=configItem["shift_management"]["channel"]
)
except:
except KeyError:
return await new_failure_embed(
ctx,
"Incorrect Configuration",
Expand Down Expand Up @@ -116,7 +116,7 @@ async def duty_time(self, ctx, member: discord.Member = None):
value=f"{td_format(datetime.timedelta(seconds=get_elapsed_time(shift)))}",
inline=False,
)
except:
except OverflowError:
if shift:
embed.add_field(
name="Ongoing Shift",
Expand Down Expand Up @@ -216,7 +216,7 @@ async def duty_admin(self, ctx, member: discord.Member, type: str = "Default"):
)
)

shift = await self.bot.shift_management.get_current_shift(ctx.author, ctx.guild.id)
shift = await self.bot.shift_management.get_current_shift(member, ctx.guild.id)

previous_shifts = [i async for i in self.bot.shift_management.shifts.db.find({
"UserID": member.id,
Expand Down Expand Up @@ -463,8 +463,9 @@ async def duty_manage(self, ctx, *, type: str = "Default"):
extras={"category": "Shift Management"}
)
@require_settings()
@app_commands.autocomplete(type=all_shift_type_autocomplete)
@is_staff()
async def duty_active(self, ctx):
async def duty_active(self, ctx: commands.Context, type: str):
if self.bot.shift_management_disabled is True:
return await new_failure_embed(
ctx,
Expand All @@ -485,57 +486,63 @@ async def duty_active(self, ctx):
shift_type = None
if configItem.get("shift_types"):
shift_types = configItem.get("shift_types")
if shift_types.get("enabled") is True:
if len(shift_types.get("types")) > 1:
shift_types = shift_types.get("types")

view = CustomSelectMenu(
ctx.author.id,
[
discord.SelectOption(
label=i["name"],
value=i["id"],
description=i["name"],
)
for i in shift_types
]
+ [
discord.SelectOption(
label="All",
value="all",
description="Data from all shift types",
)
],
)
if len(shift_types.get("types")) > 1:
shift_types = shift_types.get("types")

view = CustomSelectMenu(
ctx.author.id,
[
discord.SelectOption(
label=i["name"],
value=i["id"],
description=i["name"],
)
for i in shift_types
]
+ [
discord.SelectOption(
label="All",
value="all",
description="Data from all shift types",
)
],
)
if not type.lower() in [i["name"].lower() for i in shift_types]:
msg = await ctx.reply(
embed=discord.Embed(
title="Shift Types",
description=f"You have **{len(shift_types)}** shift types. Which ones would you like to see?",
title="Incorrect Shift Type",
description="The shift type provided is not valid.",
color=BLANK_COLOR
),
view=view
)

timeout = await view.wait()
if timeout:
return

if view.value:
if view.value == "all":
shift_type = 0
type_value = view.value
else:
type_value = type

if type_value:
if type_value.lower() == "all":
shift_type = None
else:
shift_type_str = type_value
shift_list = [
i for i in shift_types if i["name"].lower() == shift_type_str.lower()
]
if shift_list:
shift_type = shift_list[0]
else:
shift_type = view.value
shift_list = [
i for i in shift_types if i["id"] == int(shift_type)
]
if shift_list:
shift_type = shift_list[0]
else:
return await new_failure_embed(
ctx,
"Critical Error",
"if you somehow encounter this error, please contact [ERM Support](https://discord.gg/FAC629TzBy)",
)
return await new_failure_embed(
ctx,
"Critical Error",
"if you somehow encounter this error, please contact [ERM Support](https://discord.gg/FAC629TzBy)",
)
else:
return

embed = discord.Embed(
title="Active Shifts", color=BLANK_COLOR
Expand Down Expand Up @@ -662,8 +669,9 @@ async def duty_active(self, ctx):
aliases=["lb"],
)
@require_settings()
@app_commands.autocomplete(type=all_shift_type_autocomplete)
@is_staff()
async def shift_leaderboard(self, ctx):
async def shift_leaderboard(self, ctx: commands.Context, *, type: str = None):
if self.bot.shift_management_disabled is True:
return await new_failure_embed(
ctx,
Expand All @@ -685,57 +693,63 @@ async def shift_leaderboard(self, ctx):
shift_type = None
if configItem.get("shift_types"):
shift_types = configItem.get("shift_types")
if shift_types.get("enabled") is True:
if len(shift_types.get("types")) > 1:
shift_types = shift_types.get("types")

view = CustomSelectMenu(
ctx.author.id,
[
discord.SelectOption(
label=i["name"],
value=i["id"],
description=i["name"],
)
for i in shift_types
]
+ [
discord.SelectOption(
label="All",
value="all",
description="Data from all shift types",
)
],
)
if len(shift_types.get("types")) > 1:
shift_types = shift_types.get("types")

view = CustomSelectMenu(
ctx.author.id,
[
discord.SelectOption(
label=i["name"],
value=i["id"],
description=i["name"],
)
for i in shift_types
]
+ [
discord.SelectOption(
label="All",
value="all",
description="Data from all shift types",
)
],
)
if not type.lower() in [i["name"].lower() for i in shift_types]:
msg = await ctx.reply(
embed=discord.Embed(
title="Shift Types",
description=f"You have **{len(shift_types)}** shift types. Which ones would you like to see?",
title="Incorrect Shift Type",
description="The shift type provided is not valid.",
color=BLANK_COLOR
),
view=view
)

timeout = await view.wait()
if timeout:
return

if view.value:
if view.value == "all":
shift_type = 0
type_value = view.value
else:
type_value = type

if type_value:
if type_value.lower() == "all":
shift_type = 0
else:
shift_type_str = type_value
shift_list = [
i for i in shift_types if i["name"].lower() == shift_type_str.lower()
]
if shift_list:
shift_type = shift_list[0]
else:
shift_type = view.value
shift_list = [
i for i in shift_types if i["id"] == int(shift_type)
]
if shift_list:
shift_type = shift_list[0]
else:
return await new_failure_embed(
ctx,
"Critical Error",
"if you somehow encounter this error, please contact [ERM Support](https://discord.gg/FAC629TzBy)",
)
return await new_failure_embed(
ctx,
"Critical Error",
"if you somehow encounter this error, please contact [ERM Support](https://discord.gg/FAC629TzBy)",
)
else:
return

all_staff = [{"id": None, "total_seconds": 0}]

Expand Down Expand Up @@ -858,7 +872,7 @@ async def shift_leaderboard(self, ctx):
for index, i in enumerate(sorted_staff):
try:
member = await ctx.guild.fetch_member(i["id"])
except:
except discord.NotFound:
member = None
# print(index)
# print(i)
Expand Down
2 changes: 1 addition & 1 deletion cogs/StaffConduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def manage(self, ctx: commands.Context):

try:
infraction_type_name = view.modal.type_name.value
except:
except AttributeError:
return

await message.edit(
Expand Down
4 changes: 2 additions & 2 deletions datamodels/ShiftManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def add_shift_by_user(
"Authorization": config('INTERNAL_API_AUTH')
}):
pass
except:
except ValueError:
pass

return data["_id"]
Expand Down Expand Up @@ -161,7 +161,7 @@ async def end_shift(self, identifier: str, guild_id: int | None = None):
"Authorization": config('INTERNAL_API_AUTH')
}):
pass
except:
except ValueError:
pass

await self.shifts.update_by_id(document)
Expand Down
Loading

0 comments on commit 27e07cf

Please sign in to comment.