Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to search and see if member has been caught phishing. fix… #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions python/cogs/spam_blocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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']
Expand All @@ -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']
Expand Down Expand Up @@ -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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider creating the embed once, and updating the description based on res to reduce duplication.

color=0x13DC51,
title='Criminal History Check',
description=f'```{rules_broken}```'
)
return await ctx.send(embed=embed)


# ----------------------------------------------
# Cog Tasks
# ----------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions python/db/models/dals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()