Lots more event debugging
This commit is contained in:
parent
002bf5b150
commit
029743f977
1 changed files with 121 additions and 95 deletions
|
@ -102,6 +102,7 @@ class Jarvis(Snake):
|
||||||
self, ctx: Context, error: Exception, *args: list, **kwargs: dict
|
self, ctx: Context, error: Exception, *args: list, **kwargs: dict
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Lepton on_command_error override."""
|
"""Lepton on_command_error override."""
|
||||||
|
self.logger.debug(f"Handling error in {ctx.invoked_name}: {error}")
|
||||||
if isinstance(error, CommandOnCooldown):
|
if isinstance(error, CommandOnCooldown):
|
||||||
await ctx.send(str(error), ephemeral=True)
|
await ctx.send(str(error), ephemeral=True)
|
||||||
return
|
return
|
||||||
|
@ -191,7 +192,8 @@ class Jarvis(Snake):
|
||||||
guild = user.guild
|
guild = user.guild
|
||||||
unverified = await Setting.find_one(q(guild=guild.id, setting="unverified"))
|
unverified = await Setting.find_one(q(guild=guild.id, setting="unverified"))
|
||||||
if unverified:
|
if unverified:
|
||||||
role = guild.get_role(unverified.value)
|
self.logger.debug(f"Applying unverified role to {user.id} in {guild.id}")
|
||||||
|
role = await guild.fetch_role(unverified.value)
|
||||||
if role not in user.roles:
|
if role not in user.roles:
|
||||||
await user.add_role(role, reason="User just joined and is unverified")
|
await user.add_role(role, reason="User just joined and is unverified")
|
||||||
|
|
||||||
|
@ -199,6 +201,9 @@ class Jarvis(Snake):
|
||||||
"""Handle autopurge events."""
|
"""Handle autopurge events."""
|
||||||
autopurge = await Autopurge.find_one(q(guild=message.guild.id, channel=message.channel.id))
|
autopurge = await Autopurge.find_one(q(guild=message.guild.id, channel=message.channel.id))
|
||||||
if autopurge:
|
if autopurge:
|
||||||
|
self.logger.debug(
|
||||||
|
f"Autopurging message {message.guild.id}/{message.channel.id}/{message.id}"
|
||||||
|
)
|
||||||
await message.delete(delay=autopurge.delay)
|
await message.delete(delay=autopurge.delay)
|
||||||
|
|
||||||
async def autoreact(self, message: Message) -> None:
|
async def autoreact(self, message: Message) -> None:
|
||||||
|
@ -210,6 +215,9 @@ class Jarvis(Snake):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if autoreact:
|
if autoreact:
|
||||||
|
self.logger.debug(
|
||||||
|
f"Autoreacting to message {message.guild.id}/{message.channel.id}/{message.id}"
|
||||||
|
)
|
||||||
for reaction in autoreact.reactions:
|
for reaction in autoreact.reactions:
|
||||||
await message.add_reaction(reaction)
|
await message.add_reaction(reaction)
|
||||||
if autoreact.thread:
|
if autoreact.thread:
|
||||||
|
@ -240,17 +248,17 @@ class Jarvis(Snake):
|
||||||
"VtgZntXcnZ",
|
"VtgZntXcnZ",
|
||||||
"gPfYGbvTCE",
|
"gPfYGbvTCE",
|
||||||
]
|
]
|
||||||
if match.group(1) not in allowed and setting.value:
|
if (m := match.group(1)) not in allowed and setting.value:
|
||||||
|
self.logger.debug(f"Removing non-allowed invite {m} from {message.guild.id}")
|
||||||
await message.delete()
|
await message.delete()
|
||||||
w = Warning(
|
await Warning(
|
||||||
active=True,
|
active=True,
|
||||||
admin=self.user.id,
|
admin=self.user.id,
|
||||||
duration=24,
|
duration=24,
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Sent an invite link",
|
reason="Sent an invite link",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
)
|
).commit()
|
||||||
await w.commit()
|
|
||||||
embed = warning_embed(message.author, "Sent an invite link")
|
embed = warning_embed(message.author, "Sent an invite link")
|
||||||
await message.channel.send(embed=embed)
|
await message.channel.send(embed=embed)
|
||||||
|
|
||||||
|
@ -270,15 +278,17 @@ class Jarvis(Snake):
|
||||||
- (1 if message.author.id in message._mention_ids else 0) # noqa: W503
|
- (1 if message.author.id in message._mention_ids else 0) # noqa: W503
|
||||||
> massmention.value # noqa: W503
|
> massmention.value # noqa: W503
|
||||||
):
|
):
|
||||||
w = Warning(
|
self.logger.debug(
|
||||||
|
f"Massmention threshold on {message.guild.id}/{message.channel.id}/{message.id}"
|
||||||
|
)
|
||||||
|
await Warning(
|
||||||
active=True,
|
active=True,
|
||||||
admin=self.user.id,
|
admin=self.user.id,
|
||||||
duration=24,
|
duration=24,
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Mass Mention",
|
reason="Mass Mention",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
)
|
).commit()
|
||||||
await w.commit()
|
|
||||||
embed = warning_embed(message.author, "Mass Mention")
|
embed = warning_embed(message.author, "Mass Mention")
|
||||||
await message.channel.send(embed=embed)
|
await message.channel.send(embed=embed)
|
||||||
|
|
||||||
|
@ -322,31 +332,35 @@ class Jarvis(Snake):
|
||||||
break
|
break
|
||||||
|
|
||||||
if role_in_rolepings and user_missing_role and not user_is_admin and not user_has_bypass:
|
if role_in_rolepings and user_missing_role and not user_is_admin and not user_has_bypass:
|
||||||
w = Warning(
|
self.logger.debug(
|
||||||
|
f"Rolepinged role in {message.guild.id}/{message.channel.id}/{message.id}"
|
||||||
|
)
|
||||||
|
await Warning(
|
||||||
active=True,
|
active=True,
|
||||||
admin=self.user.id,
|
admin=self.user.id,
|
||||||
duration=24,
|
duration=24,
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Pinged a blocked role/user with a blocked role",
|
reason="Pinged a blocked role/user with a blocked role",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
)
|
).commit()
|
||||||
await w.commit()
|
|
||||||
embed = warning_embed(message.author, "Pinged a blocked role/user with a blocked role")
|
embed = warning_embed(message.author, "Pinged a blocked role/user with a blocked role")
|
||||||
await message.channel.send(embed=embed)
|
await message.channel.send(embed=embed)
|
||||||
|
|
||||||
async def phishing(self, message: Message) -> None:
|
async def phishing(self, message: Message) -> None:
|
||||||
"""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):
|
||||||
if match.group("domain") in self.phishing_domains:
|
if (m := match.group("domain")) in self.phishing_domains:
|
||||||
w = Warning(
|
self.logger.debug(
|
||||||
|
f"Phishing url {m} detected in {message.guild.id}/{message.channel.id}/{message.id}"
|
||||||
|
)
|
||||||
|
await Warning(
|
||||||
active=True,
|
active=True,
|
||||||
admin=self.user.id,
|
admin=self.user.id,
|
||||||
duration=24,
|
duration=24,
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Phishing URL",
|
reason="Phishing URL",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
)
|
).commit()
|
||||||
await w.commit()
|
|
||||||
embed = warning_embed(message.author, "Phishing URL")
|
embed = warning_embed(message.author, "Phishing URL")
|
||||||
await message.channel.send(embed=embed)
|
await message.channel.send(embed=embed)
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
@ -365,15 +379,17 @@ class Jarvis(Snake):
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
for item in data["processed"]["urls"].values():
|
for item in data["processed"]["urls"].values():
|
||||||
if not item["safe"]:
|
if not item["safe"]:
|
||||||
w = Warning(
|
self.logger.debug(
|
||||||
|
f"Phishing url {match.string} detected in {message.guild.id}/{message.channel.id}/{message.id}"
|
||||||
|
)
|
||||||
|
await Warning(
|
||||||
active=True,
|
active=True,
|
||||||
admin=self.user.id,
|
admin=self.user.id,
|
||||||
duration=24,
|
duration=24,
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Unsafe URL",
|
reason="Unsafe URL",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
)
|
).commit()
|
||||||
await w.commit()
|
|
||||||
reasons = ", ".join(item["not_safe_reasons"])
|
reasons = ", ".join(item["not_safe_reasons"])
|
||||||
embed = warning_embed(message.author, reasons)
|
embed = warning_embed(message.author, reasons)
|
||||||
await message.channel.send(embed=embed)
|
await message.channel.send(embed=embed)
|
||||||
|
@ -404,6 +420,7 @@ class Jarvis(Snake):
|
||||||
if modlog:
|
if modlog:
|
||||||
if not before or before.content == after.content or before.content is None:
|
if not before or before.content == after.content or before.content is None:
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
channel = before.guild.get_channel(modlog.value)
|
channel = before.guild.get_channel(modlog.value)
|
||||||
fields = [
|
fields = [
|
||||||
EmbedField(
|
EmbedField(
|
||||||
|
@ -434,6 +451,10 @@ class Jarvis(Snake):
|
||||||
text=f"{after.author.username}#{after.author.discriminator} | {after.author.id}"
|
text=f"{after.author.username}#{after.author.discriminator} | {after.author.id}"
|
||||||
)
|
)
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warn(
|
||||||
|
f"Failed to process edit {before.guild.id}/{before.channel.id}/{before.id}: {e}"
|
||||||
|
)
|
||||||
if not isinstance(after.channel, DMChannel) and not after.author.bot:
|
if not isinstance(after.channel, DMChannel) and not after.author.bot:
|
||||||
await self.massmention(after)
|
await self.massmention(after)
|
||||||
await self.roleping(after)
|
await self.roleping(after)
|
||||||
|
@ -455,6 +476,7 @@ class Jarvis(Snake):
|
||||||
content = "N/A"
|
content = "N/A"
|
||||||
fields = [EmbedField("Original Message", content, False)]
|
fields = [EmbedField("Original Message", content, False)]
|
||||||
|
|
||||||
|
try:
|
||||||
if message.attachments:
|
if message.attachments:
|
||||||
value = "\n".join([f"[{x.filename}]({x.url})" for x in message.attachments])
|
value = "\n".join([f"[{x.filename}]({x.url})" for x in message.attachments])
|
||||||
fields.append(
|
fields.append(
|
||||||
|
@ -505,3 +527,7 @@ class Jarvis(Snake):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warn(
|
||||||
|
f"Failed to process edit {message.guild.id}/{message.channel.id}/{message.id}: {e}"
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue