Skip to content

Commit

Permalink
PRC Integration Act 5
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeyUsersREC committed Mar 2, 2024
1 parent 56c0e5a commit 75a3226
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 121 deletions.
2 changes: 1 addition & 1 deletion cogs/ERLC.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def predicate(ctx: commands.Context):

async def secure_logging(self, guild_id, author_id, interpret_type: typing.Literal['Message', 'Hint', 'Command'], command_string: str, attempted: bool = False):
settings = await self.bot.settings.find_by_id(guild_id)
channel = ((settings or {}).get('game_security', {}) or {}).get('webhook_channel')
channel = ((settings or {}).get('game_security', {}) or {}).get('channel')
try:
channel = await (await self.bot.fetch_guild(guild_id)).fetch_channel(channel)
except discord.HTTPException:
Expand Down
145 changes: 144 additions & 1 deletion cogs/Privacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, bot):
description="Change your privacy settings.",
extras={"category": "Privacy"},
)
async def consent(self, ctx):
async def consent(self, ctx: commands.Context):
bot = self.bot
punishments_enabled = True
ai_enabled = True
Expand All @@ -40,6 +40,10 @@ async def consent(self, ctx):
if document.get("ai_predictions") is not None
else True
)
automatic_shifts_enabled = (
document.get('auto_shifts')
if document.get('auto_shifts') is not None else True
)
selected = document
embed = discord.Embed(
title="User Settings",
Expand All @@ -51,6 +55,7 @@ async def consent(self, ctx):
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"
),
inline=False
)
Expand Down Expand Up @@ -116,6 +121,8 @@ async def punishment_alerts(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"

),
inline=False
)
Expand Down Expand Up @@ -158,6 +165,7 @@ async def punishment_alerts(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"
),
inline=False
)
Expand Down Expand Up @@ -235,6 +243,7 @@ async def punishment_predictions(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"
),
inline=False
)
Expand Down Expand Up @@ -276,6 +285,7 @@ async def punishment_predictions(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"
),
inline=False
)
Expand Down Expand Up @@ -353,6 +363,7 @@ async def shift_reports(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"
),
inline=False
)
Expand Down Expand Up @@ -398,6 +409,132 @@ async def shift_reports(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"
),
inline=False
)
embed.set_author(
name=ctx.guild.name,
icon_url=ctx.guild.icon.url if ctx.guild.icon else ''
)
embed.set_thumbnail(
url=ctx.author.display_avatar.url
)
embed.set_footer(
text="User Settings"
)
embed.timestamp = datetime.datetime.now()
button.style = discord.ButtonStyle.danger
await interaction.message.edit(
content='',
embed=embed,
view=button.view,
)
else:
await interaction.response.send_message(embed=discord.Embed(
title="Not Permitted",
description="You are not permitted to interact with these buttons.",
color=BLANK_COLOR
), ephemeral=True)

async def automatic_shifts(
interaction: discord.Interaction, button: discord.ui.Button
):
if interaction.user.id == ctx.author.id:
nonlocal selected
nonlocal automatic_shifts_enabled
await interaction.response.defer()
view = CustomSelectMenu(
ctx.author.id,
[
discord.SelectOption(
label="Enable",
value="enable",
description="Enable Automatic Shifts.",
),
discord.SelectOption(
label="Disable",
value="disable",
description="Disable Automatic Shifts.",
),
],
)

await interaction.message.edit(
view=view
)
await view.wait()
if view.value == "enable":
if selected is None:
selected = {"_id": ctx.author.id, "automatic_shifts": True}
await bot.consent.insert(
selected
)
else:
selected["automatic_shifts"] = True
if not selected.get('_id'):
selected['_id'] = ctx.author.id
await bot.consent.update_by_id(selected)
shift_reports_enabled = True
embed = discord.Embed(
title="User Settings",
color=BLANK_COLOR
)
embed.add_field(
name="Configurations",
value=(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"

),
inline=False
)
embed.set_author(
name=ctx.guild.name,
icon_url=ctx.guild.icon.url if ctx.guild.icon else ''
)
embed.set_thumbnail(
url=ctx.author.display_avatar.url
)
embed.set_footer(
text="User Settings"
)
embed.timestamp = datetime.datetime.now()
button.style = discord.ButtonStyle.success

await interaction.edit_original_response(
content='',
embed=embed,
view=button.view,
)

elif view.value == "disable":
if selected is None:
selected = {"_id": ctx.author.id, "automatic_shifts": False}
await bot.consent.insert(
selected
)
else:
selected["automatic_shifts"] = False
if not selected.get('_id'):
selected['_id'] = ctx.author.id

await bot.consent.update_by_id(selected)
shift_reports_enabled = False
embed = discord.Embed(
title="User Settings",
color=BLANK_COLOR
)
embed.add_field(
name="Configurations",
value=(
f"> **Punishment Alerts:** {'<:check:1163142000271429662>' if punishments_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Shift Reports:** {'<:check:1163142000271429662>' if shift_reports_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **AI Predictions:** {'<:check:1163142000271429662>' if ai_enabled is True else '<:xmark:1166139967920164915>'}\n"
f"> **Automatic Shifts:** {'<:check:1163142000271429662>' if automatic_shifts_enabled is True else '<:xmark:1166139967920164915>'}"

),
inline=False
)
Expand Down Expand Up @@ -444,6 +581,12 @@ async def shift_reports(
style=discord.ButtonStyle.danger if not ai_enabled else discord.ButtonStyle.success,
func=punishment_predictions,
),
CustomExecutionButton(
ctx.author.id,
label="Automatic Shifts",
style=discord.ButtonStyle.danger if not automatic_shifts_enabled else discord.ButtonStyle.success,
func=automatic_shifts,
)
]

for child in buttons:
Expand Down
28 changes: 15 additions & 13 deletions cogs/ShiftLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ async def duty_time(self, ctx, member: discord.Member = None):
"Not Enabled",
"Shift Logging is not enabled on this server."
)
try:
shift_channel = discord.utils.get(
ctx.guild.channels, id=configItem["shift_management"]["channel"]
)
except KeyError:
return await new_failure_embed(
ctx,
"Incorrect Configuration",
'This server is not configured correctly.',
)

embed = discord.Embed(
title=f"Total Shifts" if member == ctx.author else f'{member.name}\'s Total Shifts',
Expand Down Expand Up @@ -104,11 +94,23 @@ async def duty_time(self, ctx, member: discord.Member = None):
shifts.append(s)

total_seconds = sum([get_elapsed_time(i) for i in shifts])
sorted_roles = sorted(member.roles, key=lambda x: x.position)
selected_quota = 0
specified_quota_roles = configItem.get('shift_management', {}).get('role_quotas', [])
for role in sorted_roles:
print(role)
print(specified_quota_roles)
if role.id in [t['role'] for t in specified_quota_roles]:
found_item = [t for t in specified_quota_roles if t['role'] == role.id][0]
selected_quota = found_item['quota']


if selected_quota == 0:
selected_quota = configItem.get('shift_management').get('quota', 0)

quota = configItem.get('shift_management', {}).get('quota', 0)
met_quota = None
if quota != 0:
met_quota = bool(total_seconds > quota)
if selected_quota != 0:
met_quota = bool(total_seconds > selected_quota)

try:
if shift:
Expand Down
8 changes: 4 additions & 4 deletions datamodels/ShiftManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def fetch_shift(self, object_id: ObjectId) -> ShiftItem | None:
)

async def add_shift_by_user(
self, member: discord.Member, shift_type: str, breaks: list, guild: int
self, member: discord.Member, shift_type: str, breaks: list, guild: int, timestamp: int = 0
):
"""
Adds a shift for the specified user to the database, with the provided
Expand Down Expand Up @@ -92,7 +92,7 @@ async def add_shift_by_user(
"Nickname": member.display_name,
"UserID": member.id,
"Type": shift_type,
"StartEpoch": datetime.datetime.now().timestamp(),
"StartEpoch": datetime.datetime.now().timestamp() if timestamp in [0, None] else timestamp,
"Breaks": breaks,
"Guild": guild,
"Moderations": [],
Expand Down Expand Up @@ -134,7 +134,7 @@ async def remove_time_from_shift(self, identifier: str, seconds: int):
await self.shifts.update_by_id(document)
return document

async def end_shift(self, identifier: str, guild_id: int | None = None):
async def end_shift(self, identifier: str, guild_id: int | None = None, timestamp: int | None = None):
"""
Ends the specified user's shift.
"""
Expand All @@ -150,7 +150,7 @@ async def end_shift(self, identifier: str, guild_id: int | None = None):

for breaks in document["Breaks"]:
if breaks["EndEpoch"] == 0:
breaks["EndEpoch"] = int(datetime.datetime.now().timestamp())
breaks["EndEpoch"] = int(datetime.datetime.now().timestamp()) if timestamp in [None, 0] else timestamp

try:
url_var = config("BASE_API_URL")
Expand Down
Loading

0 comments on commit 75a3226

Please sign in to comment.