New antiphish, faster yachts sink

This commit is contained in:
Zeva Rose 2022-08-29 09:40:59 -06:00
parent 23dc1e7de2
commit 7ecc217a92

View file

@ -81,6 +81,7 @@ class Jarvis(StatsClient):
self.logger = logging.getLogger(__name__)
self.phishing_domains = []
self.pre_run_callback = self._prerun
self.synced = False
async def _chunk_all(self) -> None:
"""Chunk all guilds."""
@ -88,15 +89,17 @@ class Jarvis(StatsClient):
self.logger.debug(f"Chunking guild {guild.name} <{guild.id}>")
await guild.chunk_guild()
@Task.create(IntervalTrigger(hours=1))
@Task.create(IntervalTrigger(minutes=1))
async def _update_domains(self) -> None:
self.logger.debug("Updating phishing domains")
async with ClientSession(headers={"X-Identity": "Discord: zevaryx#5779"}) as session:
response = await session.get("https://phish.sinking.yachts/v2/recent/3700")
response = await session.get("https://phish.sinking.yachts/v2/recent/60")
response.raise_for_status()
data = await response.json()
self.logger.debug(f"Found {len(data)} changes to phishing domains")
if len(data) == 0:
return
add = 0
sub = 0
@ -141,9 +144,11 @@ class Jarvis(StatsClient):
async def on_ready(self) -> None:
"""NAFF on_ready override."""
try:
if not self.synced:
await self._sync_domains()
self._update_domains.start()
asyncio.create_task(self._chunk_all())
self.synced = True
except Exception as e:
self.logger.error("Failed to load anti-phishing", exc_info=e)
self.logger.info("Logged in as {}".format(self.user)) # noqa: T001
@ -662,14 +667,18 @@ class Jarvis(StatsClient):
"""Check if the message contains any known phishing domains."""
for match in url.finditer(message.content):
async with ClientSession() as session:
resp = await session.get(
"https://spoopy.oceanlord.me/api/check_website", json={"website": match.string}
resp = await session.post(
"https://anti-fish.bitflow.dev/check",
json={"message": match.string},
headers={
"Application-Name": "JARVIS",
"Application-Link": "https://git.zevaryx.com/stark-industries/jarvis",
},
)
if resp.status != 200:
break
data = await resp.json()
for item in data["processed"]["urls"].values():
if not item["safe"]:
if data["match"]:
self.logger.debug(
f"Scam url `{match.string}` detected in {message.guild.id}/{message.channel.id}/{message.id}"
)
@ -687,7 +696,7 @@ class Jarvis(StatsClient):
guild_id=message.guild.id, guild_name=message.guild.name
)
tracker.inc()
reasons = ", ".join(item["not_safe_reasons"])
reasons = ", ".join(f"{m['source']}: {m['type']}" for m in data["matches"])
embed = warning_embed(message.author, reasons)
try:
await message.channel.send(embeds=embed)