Skip to content
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(

Copy link
Copy Markdown

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()