Add unsafe URL checker via spoopy detector

This commit is contained in:
Zeva Rose 2022-03-17 15:36:54 -06:00
parent 06ab5d105f
commit 89907026cd

View file

@ -468,6 +468,48 @@ class Jarvis(Snake):
text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}"
)
await message.channel.send(embed=embed)
await message.delete()
async def malicious_url(self, message: Message) -> None:
"""Check if the message contains any known phishing domains."""
for match in url.findall(message.content):
async with ClientSession() as session:
resp = await session.get(
"https://spoopy.oceanlord.me/api/check_website", json={"website": match}
)
if resp.status != 200:
break
data = await resp.json()
for item in data["processed"]["urls"].values():
if not item["safe"]:
w = Warning(
active=True,
admin=self.user.id,
duration=24,
guild=message.guild.id,
reason="Unsafe URL",
user=message.author.id,
)
await w.commit()
reasons = ", ".join(item["not_safe_reasons"])
fields = [
EmbedField(name="Reason", value=f"Unsafe URL: {reasons}", inline=False)
]
embed = build_embed(
title="Warning",
description=f"{message.author.mention} has been warned",
fields=fields,
)
embed.set_author(
name=message.author.nick if message.author.nick else message.author.name,
icon_url=message.author.display_avatar.url,
)
embed.set_footer(
text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}"
)
await message.channel.send(embed=embed)
await message.delete()
break
async def on_message(self, event: MessageCreate) -> None:
"""Handle on_message event. Calls other event handlers."""
@ -479,3 +521,4 @@ class Jarvis(Snake):
await self.autopurge(message)
await self.checks(message)
await self.phishing(message)
await self.malicious_url(message)