aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Daniel Brown <[email protected]>2020-11-02 17:09:57 -0600
committerGravatar Daniel Brown <[email protected]>2020-11-02 17:12:48 -0600
commit2a31370dfd0b03fdd117a1457fd691ac644cb470 (patch)
tree4d613c593f17018fd2b65114900180f95d5fab09
parentAdded RedisCache and event (diff)
Added ping message, message id storage and message deletion
- Users who have never joined the voice channels before (and are currently unverified) will receive a ping in the #voice_verification channel - If user is unverified, the message id is stored in the cache along with the user id. - Added a message deletion to the voiceverify command, which removes the ping message if one exists. Also sets stored message ID to None so that it doesn't attempt to delete messages that aren't there - Set timed message deletion for 5 minutes.
-rw-r--r--bot/exts/moderation/voice_gate.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/bot/exts/moderation/voice_gate.py b/bot/exts/moderation/voice_gate.py
index 6636bc3ce..9fc77e5bb 100644
--- a/bot/exts/moderation/voice_gate.py
+++ b/bot/exts/moderation/voice_gate.py
@@ -60,6 +60,13 @@ class VoiceGate(Cog):
- You must have accepted our rules over a certain number of days ago
- You must not be actively banned from using our voice channels
"""
+
+ # If user has received a ping in voice_verification, delete the message
+ if message_id := self.redis_cache.get(ctx.author.id, None) is not None:
+ ping_message = await ctx.channel.fetch_message(message_id)
+ await ping_message.delete()
+ await self.redis_cache.update(ctx.author.id, None)
+
try:
data = await self.bot.api_client.get(f"bot/users/{ctx.author.id}/metricity_data")
except ResponseCodeError as e:
@@ -170,6 +177,10 @@ class VoiceGate(Cog):
async def on_voice_state_update(self, member: Member, *_) -> None:
"""Pings a user if they've never joined the voice chat before and aren't verified"""
+ if member.bot:
+ log.trace("User is a bot. Ignore.")
+ return
+
in_cache = await self.redis_cache.get(member.id)
# member.voice will return None if the user is not in a voice channel
@@ -177,9 +188,21 @@ class VoiceGate(Cog):
log.trace("User not in cache and is in a voice channel")
verified = any(Roles.voice_verified == role.id for role in member.roles)
if verified:
+ log.trace("User is verified, add to the cache and ignore")
await self.redis_cache.set(member.id, None)
return
+ log.trace("User is unverified. Send ping.")
+ message = self._voice_verification_channel.send(
+ f"Hello, {member.mention}! Wondering why you can't talk in the voice channels? "
+ "Use the `!voiceverify` command in here to verify. "
+ "If you don't yet qualify, you'll be told why!"
+ )
+ await self.redis_cache.set(member.id, message.id)
+
+ # Message will try to be deleted after 5 minutes. If it fails, it'll do so silently
+ await message.delete(delay=300)
+
async def cog_command_error(self, ctx: Context, error: Exception) -> None:
"""Check for & ignore any InWhitelistCheckFailure."""
if isinstance(error, InWhitelistCheckFailure):