Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions techsupport_bot/commands/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import datetime
from enum import Enum
from typing import TYPE_CHECKING, Self

Expand Down Expand Up @@ -114,6 +115,13 @@ async def setup(bot: bot.TechSupportBot) -> None:
description="The ID of the role to ping when a new application is created",
default="",
)
config.add(
key="max_age",
datatype="int",
title="Max days an application can live",
description="After this many days, the system will auto reject the applications.",
default=30,
)
await bot.add_cog(ApplicationManager(bot=bot, extension_name="application"))
await bot.add_cog(ApplicationNotifier(bot=bot, extension_name="application"))
bot.add_extension_config("application", config)
Expand Down Expand Up @@ -927,6 +935,8 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None
user = await guild.fetch_member(int(app.applicant_id))
except discord.NotFound:
user = None

# User who made application left
if not user:
audit_log.append(
f"Application by user: `{app.applicant_name}` was rejected because"
Expand All @@ -937,6 +947,21 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None
).apply()
continue

# Application has been pending for max_age days
max_age_config = config.extensions.application.max_age.value
if app.application_time < datetime.datetime.now() - datetime.timedelta(
days=max_age_config
):
audit_log.append(
f"Application by user: `{user.name}` was rejected since it's been"
f" inactive for {max_age_config} days"
)
await app.update(
application_status=ApplicationStatus.REJECTED.value
).apply()
continue

# User changed their name
if user.name != app.applicant_name:
audit_log.append(
f"Application by user: `{app.applicant_name}` had the stored name"
Expand All @@ -948,6 +973,7 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None
int(config.extensions.application.application_role.value)
)

# User has the helper role
if role in getattr(user, "roles", []):
audit_log.append(
f"Application by user: `{user.name}` was approved since they have"
Expand All @@ -956,6 +982,7 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None
await app.update(
application_status=ApplicationStatus.APPROVED.value
).apply()

if audit_log:
embed = discord.Embed(title="Application manage events")
for event in audit_log:
Expand Down
Loading