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