diff --git a/techsupport_bot/commands/application.py b/techsupport_bot/commands/application.py index 5cfca588..a56fd219 100644 --- a/techsupport_bot/commands/application.py +++ b/techsupport_bot/commands/application.py @@ -2,6 +2,7 @@ from __future__ import annotations +import datetime from enum import Enum from typing import TYPE_CHECKING, Self @@ -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) @@ -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" @@ -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" @@ -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" @@ -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: