diff options
| author | 2020-08-04 19:33:42 +0200 | |
|---|---|---|
| committer | 2020-08-04 19:48:21 +0200 | |
| commit | 4b1100500681d1f4b670f91fe0566e4e85c8371b (patch) | |
| tree | e1e0ee654bc7fc147d67379d6e76f3e9ea8a6497 | |
| parent | Verification: repurpose & rename `_check_users` (diff) | |
Verification: create task to update unverified members
| -rw-r--r-- | bot/cogs/verification.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py index 4a9983ac8..cc8d8eb7d 100644 --- a/bot/cogs/verification.py +++ b/bot/cogs/verification.py @@ -5,6 +5,7 @@ from contextlib import suppress from datetime import datetime, timedelta import discord +from discord.ext import tasks from discord.ext.commands import Cog, Context, command from bot import constants @@ -207,6 +208,42 @@ class Verification(Cog): log.debug(f"Found {len(for_role)} users for {unverified} role, {len(for_kick)} users to be kicked") return for_role, for_kick + @tasks.loop(minutes=30) + async def update_unverified_members(self) -> None: + """ + Periodically call `_check_members` and update unverified members accordingly. + + After each run, a summary will be sent to the modlog channel. If a suspiciously high + amount of members to be kicked is found, the operation is guarded by `_verify_kick`. + """ + log.info("Updating unverified guild members") + + await self.bot.wait_until_guild_available() + unverified = self.bot.get_guild(constants.Guild.id).get_role(constants.Roles.unverified) + + for_role, for_kick = await self._check_members() + + if not for_role: + role_report = f"Found no users to be assigned the {unverified.mention} role." + else: + n_roles = await self._give_role(for_role, unverified) + role_report = f"Assigned {unverified.mention} role to `{n_roles}`/`{len(for_role)}` members." + + if not for_kick: + kick_report = "Found no users to be kicked." + elif not await self._verify_kick(len(for_kick)): + kick_report = f"Not authorized to kick `{len(for_kick)}` members." + else: + n_kicks = await self._kick_members(for_kick) + kick_report = f"Kicked `{n_kicks}`/`{len(for_kick)}` members from the guild." + + await self.mod_log.send_log_message( + icon_url=self.bot.user.avatar_url, + colour=discord.Colour.blurple(), + title="Verification system", + text=f"{kick_report}\n{role_report}", + ) + @property def mod_log(self) -> ModLog: """Get currently loaded ModLog cog instance.""" |