Skip to content

Commit 7b1596f

Browse files
authored
Merge pull request #92 from Tibo-Ulens/feature/unverify
Add an unverify command
2 parents ef0cf48 + ac630e4 commit 7b1596f

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

bot/extensions/moderation/verification.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async def on_submit(self, ia: Interaction):
136136
other = await Profile.find_by_email(email)
137137
if other is not None:
138138
self.bot.discord_logger.warning(
139-
f"user {ia.user.mention} attempted to verify with duplicate email '{email}'",
139+
f"user {ia.user.mention} attempted to verify with duplicate email '{email}'\ntheir other account is <@{other.discord_id}>",
140140
guild=self.guild,
141141
log_type="verification",
142142
)
@@ -419,6 +419,41 @@ async def verify(self, ia: Interaction):
419419

420420
return await ia.followup.send(content=msg, ephemeral=True)
421421

422+
@app_commands.command(
423+
name="unverify", description="Remove somebody from the verified users database"
424+
)
425+
@app_commands.describe(user="The user to unverify")
426+
@app_commands.guild_only()
427+
async def unverify(self, ia: Interaction, user: Member):
428+
guild_config = await Config.get(ia.guild.id)
429+
if guild_config is None:
430+
raise MissingConfig(ia.guild)
431+
432+
await ia.response.defer(ephemeral=True, thinking=True)
433+
434+
profile_statistics = await ProfileStatistics.get_all_for_user(user.id)
435+
stat_futures = [stat.delete() for stat in profile_statistics]
436+
await asyncio.gather(*stat_futures)
437+
438+
profile = await Profile.find_by_discord_id(user.id)
439+
if profile:
440+
await profile.delete()
441+
442+
if guild_config.verified_role:
443+
verified_role = discord.utils.get(
444+
ia.guild.roles, id=guild_config.verified_role
445+
)
446+
if verified_role:
447+
await user.remove_roles(verified_role)
448+
449+
self.bot.discord_logger.info(
450+
f"{user.mention} was unverified manually",
451+
guild=self.guild,
452+
log_type="verification",
453+
)
454+
455+
return await ia.followup.send("done")
456+
422457
@ErrorHandledCog.listener("on_member_join")
423458
async def handle_member_join(self, member: Member):
424459
if member.bot:

models/profile_statistics.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ async def get(cls, discord_id: int, guild_id: int) -> "ProfileStatistics":
7474

7575
return r[0]
7676

77+
@classmethod
78+
async def get_all_for_user(cls, discord_id: int) -> list["ProfileStatistics"]:
79+
"""
80+
Get all profile statistics for a given user
81+
"""
82+
83+
async with session_factory() as session:
84+
result: Result = await session.execute(
85+
select(cls).where(cls.profile_discord_id == discord_id)
86+
)
87+
88+
return result.scalars().all()
89+
7790
@classmethod
7891
async def increment_spendable_freudpoints(cls):
7992
"""Increment the spendable freudpoints for each profile by 1 up to the max"""

0 commit comments

Comments
 (0)