aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-08-06 23:45:53 +0200
committerGravatar kwzrd <[email protected]>2020-08-06 23:45:53 +0200
commitfe50d6457081e0e6ef86d821bcfab81a8a164ca5 (patch)
treed6535fd2818a5fd9e48a9817db5fac949ec65f72
parentMerge 'd.py' 1.4 bump from 'origin/master' branch (diff)
Verification: add command interface for task management
Allow checking whether tasks are running, starting them, and stopping them. Currently, the tasks cannot be started or stopped separately. It is not believed that we would need such a level of granularity. Calling `cancel` on a task that isn't running is a no-op.
-rw-r--r--bot/cogs/verification.py62
1 files changed, 60 insertions, 2 deletions
diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py
index 963a2369e..152118d92 100644
--- a/bot/cogs/verification.py
+++ b/bot/cogs/verification.py
@@ -6,13 +6,13 @@ from datetime import datetime, timedelta
import discord
from discord.ext import tasks
-from discord.ext.commands import Cog, Context, command
+from discord.ext.commands import Cog, Context, command, group
from discord.utils import snowflake_time
from bot import constants
from bot.bot import Bot
from bot.cogs.moderation import ModLog
-from bot.decorators import in_whitelist, without_role
+from bot.decorators import in_whitelist, with_role, without_role
from bot.utils.checks import InWhitelistCheckFailure, without_role_check
from bot.utils.redis_cache import RedisCache
@@ -449,6 +449,64 @@ class Verification(Cog):
await ctx.message.delete()
# endregion
+ # region: task management commands
+
+ @with_role(*constants.MODERATION_ROLES)
+ @group(name="verification")
+ async def verification_group(self, ctx: Context) -> None:
+ """Manage internal verification tasks."""
+ if ctx.invoked_subcommand is None:
+ await ctx.send_help(ctx.command)
+
+ @verification_group.command(name="status")
+ async def status_cmd(self, ctx: Context) -> None:
+ """Check whether verification tasks are running."""
+ log.trace("Checking status of verification tasks")
+
+ if self.update_unverified_members.is_running():
+ update_status = f"{constants.Emojis.incident_actioned} Member update task is running."
+ else:
+ update_status = f"{constants.Emojis.incident_unactioned} Member update task is **not** running."
+
+ mention = f"<@&{constants.Roles.unverified}>"
+ if self.ping_unverified.is_running():
+ ping_status = f"{constants.Emojis.incident_actioned} Ping {mention} is running."
+ else:
+ ping_status = f"{constants.Emojis.incident_unactioned} Ping {mention} is **not** running."
+
+ embed = discord.Embed(
+ title="Verification system",
+ description=f"{update_status}\n{ping_status}",
+ colour=discord.Colour.blurple(),
+ )
+ await ctx.send(embed=embed)
+
+ @verification_group.command(name="start")
+ async def start_cmd(self, ctx: Context) -> None:
+ """Start verification tasks if they are not already running."""
+ log.info("Starting verification tasks")
+
+ if not self.update_unverified_members.is_running():
+ self.update_unverified_members.start()
+
+ if not self.ping_unverified.is_running():
+ self.ping_unverified.start()
+
+ colour = discord.Colour.blurple()
+ await ctx.send(embed=discord.Embed(title="Verification system", description="Done. :ok_hand:", colour=colour))
+
+ @verification_group.command(name="stop", aliases=["kill"])
+ async def stop_cmd(self, ctx: Context) -> None:
+ """Stop verification tasks."""
+ log.info("Stopping verification tasks")
+
+ self.update_unverified_members.cancel()
+ self.ping_unverified.cancel()
+
+ colour = discord.Colour.blurple()
+ await ctx.send(embed=discord.Embed(title="Verification system", description="Tasks canceled.", colour=colour))
+
+ # endregion
# region: accept and subscribe commands
def _bump_verified_stats(self, verified_member: discord.Member) -> None: