From 46583066fa65c9b7a747b881a1fff7f4a5f844d8 Mon Sep 17 00:00:00 2001 From: Bones Date: Thu, 2 Feb 2023 13:36:26 +1100 Subject: [PATCH] add ability to search and see if member has been caught phishing. fix a typo on --- python/cogs/spam_blocker.py | 38 ++++++++++++++++++++++++++++++++++--- python/db/models/dals.py | 7 +++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/python/cogs/spam_blocker.py b/python/cogs/spam_blocker.py index c8560a2..83c69fb 100644 --- a/python/cogs/spam_blocker.py +++ b/python/cogs/spam_blocker.py @@ -27,7 +27,7 @@ from db.models.dals import SpamDAL, SpammerDAL from discord.ext import commands, tasks -from discord import DMChannel, Embed, NotFound, File +from discord import DMChannel, Member, Embed, NotFound, File class SpamBlocker(commands.Cog, name='Spam'): @@ -391,13 +391,12 @@ async def rule_breaker_count(self, ctx): embed = Embed( title='Total Scammers', - description=f'```I have yeeted {count} sammers so far. you\'re welcome!```', + description=f'```I have yeeted {count} scammers so far. you\'re welcome!```', color=0xFFFFFF ) await ctx.send(embed=embed) - @spammer.command( name='list', aliases=['ls'] @@ -418,6 +417,7 @@ async def list_rule_breakers(self, ctx): for block in response: await ctx.send(f'```{"".join(block)}```') if len(block) > 0 else None + @spammer.command( name='remove', aliases=['rm'] @@ -446,6 +446,38 @@ async def remove_spammer_item(self, ctx, _id:int): await ctx.send(embed=embed) + @spammer.command( + name='search', + aliases=['user', 'history'] + ) + async def spammer_search(self, ctx, member: Member = None): + """Search member name to see if they have been caught phishing before.""" + member_id = member.id + async with async_session() as db: + async with db.begin(): + scd = SpammerDAL(db) + res = await scd.search_spammer(member_id) + if not res: + embed = Embed( + color=0x13DC51, + title='Criminal History Check', + description=f'```{await self.client.fetch_user(member_id)} is clean.```' + ) + return await ctx.send(embed=embed) + + rules_broken = '\n'.join([ + f'{row.id} | ' + + f'{await self.client.fetch_user(row.member)} | ' + + f'{row.regex}' for row in res + ]) + embed = Embed( + color=0x13DC51, + title='Criminal History Check', + description=f'```{rules_broken}```' + ) + return await ctx.send(embed=embed) + + # ---------------------------------------------- # Cog Tasks # ---------------------------------------------- diff --git a/python/db/models/dals.py b/python/db/models/dals.py index de83eed..645453b 100644 --- a/python/db/models/dals.py +++ b/python/db/models/dals.py @@ -88,3 +88,10 @@ async def delete_spammer(self, id: str): """Remove spammer item by its id""" query = delete(Spammer).where(Spammer.id == id) await self.db_session.execute(query) + + async def search_spammer(self, member_id: str): + """Search if member snowflake id is in the rule breakers db""" + query = await self.db_session.execute( + select(Spammer).where(Spammer.member == member_id) + ) + return query.scalars().all()