Fix some breakages related to beanie
This commit is contained in:
parent
c73732432b
commit
ac71dbd5fd
15 changed files with 83 additions and 87 deletions
2
.flake8
2
.flake8
|
@ -9,7 +9,7 @@ extend-ignore =
|
||||||
D401, # First line should be in imperative mood; try rephrasing
|
D401, # First line should be in imperative mood; try rephrasing
|
||||||
D400, # First line should end with a period
|
D400, # First line should end with a period
|
||||||
D101, # Missing docstring in public class
|
D101, # Missing docstring in public class
|
||||||
|
E712, # is bool, beanie requires == bool
|
||||||
# Plugins we don't currently include: flake8-return
|
# Plugins we don't currently include: flake8-return
|
||||||
R502, # do not implicitly return None in function able to return non-None value.
|
R502, # do not implicitly return None in function able to return non-None value.
|
||||||
R503, # missing explicit return at the end of function ableto return non-None value.
|
R503, # missing explicit return at the end of function ableto return non-None value.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from interactions import Client
|
|
||||||
from interactions.ext.prefixed_commands.context import PrefixedContext
|
from interactions.ext.prefixed_commands.context import PrefixedContext
|
||||||
from interactions.models.internal.context import BaseContext, InteractionContext
|
from interactions.models.internal.context import BaseContext, InteractionContext
|
||||||
from jarvis_core.util.ansi import Fore, Format, fmt
|
from jarvis_core.util.ansi import Fore, Format, fmt
|
||||||
|
|
|
@ -9,7 +9,6 @@ from interactions.models.discord.channel import DMChannel
|
||||||
from interactions.models.discord.embed import EmbedField
|
from interactions.models.discord.embed import EmbedField
|
||||||
from interactions.models.internal.application_commands import ContextMenu
|
from interactions.models.internal.application_commands import ContextMenu
|
||||||
from interactions.models.internal.context import BaseContext, InteractionContext
|
from interactions.models.internal.context import BaseContext, InteractionContext
|
||||||
from jarvis_core.db import q
|
|
||||||
from jarvis_core.db.models import Reminder, Setting
|
from jarvis_core.db.models import Reminder, Setting
|
||||||
from jarvis_core.util.ansi import RESET, Fore, Format, fmt
|
from jarvis_core.util.ansi import RESET, Fore, Format, fmt
|
||||||
from statipy.db import StaticStat
|
from statipy.db import StaticStat
|
||||||
|
@ -114,8 +113,8 @@ class EventMixin(MemberEventMixin, MessageEventMixin, ComponentEventMixin):
|
||||||
"""NAFF on_command override."""
|
"""NAFF on_command override."""
|
||||||
name = ctx.invoke_target
|
name = ctx.invoke_target
|
||||||
if not isinstance(ctx.channel, DMChannel) and name not in ["pw"]:
|
if not isinstance(ctx.channel, DMChannel) and name not in ["pw"]:
|
||||||
modlog = await Setting.find_one(q(guild=ctx.guild.id, setting="activitylog"))
|
modlog = await Setting.find_one(Setting.guild == ctx.guild.id, Setting.setting == "activitylog")
|
||||||
ignore = await Setting.find_one(q(guild=ctx.guild.id, setting="log_ignore"))
|
ignore = await Setting.find_one(Setting.guild == ctx.guild.id, Setting.setting == "log_ignore")
|
||||||
if modlog and (ignore and ctx.channel.id not in ignore.value):
|
if modlog and (ignore and ctx.channel.id not in ignore.value):
|
||||||
channel = await ctx.guild.fetch_channel(modlog.value)
|
channel = await ctx.guild.fetch_channel(modlog.value)
|
||||||
args = []
|
args = []
|
||||||
|
|
|
@ -3,8 +3,7 @@ from interactions import listen
|
||||||
from interactions.api.events.internal import ButtonPressed
|
from interactions.api.events.internal import ButtonPressed
|
||||||
from interactions.models.discord.embed import EmbedField
|
from interactions.models.discord.embed import EmbedField
|
||||||
from interactions.models.discord.enums import Permissions
|
from interactions.models.discord.enums import Permissions
|
||||||
from jarvis_core.db import q
|
from jarvis_core.db.models import Action, Modlog, Note, Phishlist, Pin, Reminder
|
||||||
from jarvis_core.db.models import Action, Modlog, Note, Phishlist, Reminder, Star
|
|
||||||
|
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
|
|
||||||
|
@ -34,7 +33,9 @@ class ComponentEventMixin:
|
||||||
name, parent = action_data.split("|")[:2]
|
name, parent = action_data.split("|")[:2]
|
||||||
action = Action(action_type=name, parent=parent)
|
action = Action(action_type=name, parent=parent)
|
||||||
note = Note(admin=context.author.id, content="Moderation case opened via message")
|
note = Note(admin=context.author.id, content="Moderation case opened via message")
|
||||||
modlog = await Modlog.find_one(q(user=user.id, guild=context.guild.id, open=True))
|
modlog = await Modlog.find_one(
|
||||||
|
Modlog.user == user.id, Modlog.guild == context.guild.id, Modlog.open == True
|
||||||
|
)
|
||||||
if modlog:
|
if modlog:
|
||||||
self.logger.debug("User already has active case in guild")
|
self.logger.debug("User already has active case in guild")
|
||||||
await context.send(f"User already has open case: {modlog.nanoid}", ephemeral=True)
|
await context.send(f"User already has open case: {modlog.nanoid}", ephemeral=True)
|
||||||
|
@ -46,7 +47,7 @@ class ComponentEventMixin:
|
||||||
actions=[action],
|
actions=[action],
|
||||||
notes=[note],
|
notes=[note],
|
||||||
)
|
)
|
||||||
await modlog.commit()
|
await modlog.save()
|
||||||
|
|
||||||
fields = (
|
fields = (
|
||||||
EmbedField(name="Admin", value=context.author.mention),
|
EmbedField(name="Admin", value=context.author.mention),
|
||||||
|
@ -100,8 +101,8 @@ class ComponentEventMixin:
|
||||||
await context.send("I'm afraid I can't let you do that", ephemeral=True)
|
await context.send("I'm afraid I can't let you do that", ephemeral=True)
|
||||||
return True # User does not have perms to delete
|
return True # User does not have perms to delete
|
||||||
|
|
||||||
if star := await Star.find_one(q(star=context.message.id, guild=context.guild.id)):
|
if pin := await Pin.find_one(Pin.pin == context.message.id, Pin.guild == context.guild.id):
|
||||||
await star.delete()
|
await pin.delete()
|
||||||
|
|
||||||
await context.message.delete()
|
await context.message.delete()
|
||||||
await context.send("Message deleted", ephemeral=True)
|
await context.send("Message deleted", ephemeral=True)
|
||||||
|
@ -118,7 +119,7 @@ class ComponentEventMixin:
|
||||||
|
|
||||||
what, rid = context.custom_id.split("|")[1:]
|
what, rid = context.custom_id.split("|")[1:]
|
||||||
if what == "rme":
|
if what == "rme":
|
||||||
reminder = await Reminder.find_one(q(_id=rid))
|
reminder = await Reminder.find_one(Reminder.id == rid)
|
||||||
if reminder:
|
if reminder:
|
||||||
new_reminder = Reminder(
|
new_reminder = Reminder(
|
||||||
user=context.author.id,
|
user=context.author.id,
|
||||||
|
@ -129,7 +130,7 @@ class ComponentEventMixin:
|
||||||
private=reminder.private,
|
private=reminder.private,
|
||||||
active=reminder.active,
|
active=reminder.active,
|
||||||
)
|
)
|
||||||
await new_reminder.commit()
|
await new_reminder.save()
|
||||||
|
|
||||||
await context.send("Reminder copied!", ephemeral=True)
|
await context.send("Reminder copied!", ephemeral=True)
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ class ComponentEventMixin:
|
||||||
|
|
||||||
_, valid, id_ = context.custom_id.split("|")
|
_, valid, id_ = context.custom_id.split("|")
|
||||||
valid = valid == "valid"
|
valid = valid == "valid"
|
||||||
pl = await Phishlist.find_one(q(_id=id_))
|
pl = await Phishlist.find_one(Phishlist.id == id_)
|
||||||
if not pl:
|
if not pl:
|
||||||
self.logger.warn(f"Phishlist {id_} does not exist!")
|
self.logger.warn(f"Phishlist {id_} does not exist!")
|
||||||
return False
|
return False
|
||||||
|
@ -153,7 +154,7 @@ class ComponentEventMixin:
|
||||||
pl.valid = valid
|
pl.valid = valid
|
||||||
pl.confirmed = True
|
pl.confirmed = True
|
||||||
|
|
||||||
await pl.commit()
|
await pl.save()
|
||||||
|
|
||||||
for row in context.message.components:
|
for row in context.message.components:
|
||||||
for component in row.components:
|
for component in row.components:
|
||||||
|
|
|
@ -7,7 +7,6 @@ from interactions.client.utils.misc_utils import get
|
||||||
from interactions.models.discord.embed import Embed, EmbedField
|
from interactions.models.discord.embed import Embed, EmbedField
|
||||||
from interactions.models.discord.enums import AuditLogEventType
|
from interactions.models.discord.enums import AuditLogEventType
|
||||||
from interactions.models.discord.user import Member
|
from interactions.models.discord.user import Member
|
||||||
from jarvis_core.db import q
|
|
||||||
from jarvis_core.db.models import Setting
|
from jarvis_core.db.models import Setting
|
||||||
|
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
|
@ -21,7 +20,7 @@ class MemberEventMixin:
|
||||||
"""Handle on_member_add event."""
|
"""Handle on_member_add event."""
|
||||||
user = event.member
|
user = event.member
|
||||||
guild = event.guild
|
guild = event.guild
|
||||||
unverified = await Setting.find_one(q(guild=guild.id, setting="unverified"))
|
unverified = await Setting.find_one(Setting.guild == guild.id, Setting.setting == "unverified")
|
||||||
if unverified:
|
if unverified:
|
||||||
self.logger.debug(f"Applying unverified role to {user.id} in {guild.id}")
|
self.logger.debug(f"Applying unverified role to {user.id} in {guild.id}")
|
||||||
role = await guild.fetch_role(unverified.value)
|
role = await guild.fetch_role(unverified.value)
|
||||||
|
@ -33,7 +32,7 @@ class MemberEventMixin:
|
||||||
"""Handle on_member_remove event."""
|
"""Handle on_member_remove event."""
|
||||||
user = event.member
|
user = event.member
|
||||||
guild = event.guild
|
guild = event.guild
|
||||||
log = await Setting.find_one(q(guild=guild.id, setting="activitylog"))
|
log = await Setting.find_one(Setting.guild == guild.id, Setting.setting == "activitylog")
|
||||||
if log:
|
if log:
|
||||||
self.logger.debug(f"User {user.id} left {guild.id}")
|
self.logger.debug(f"User {user.id} left {guild.id}")
|
||||||
channel = await guild.fetch_channel(log.value)
|
channel = await guild.fetch_channel(log.value)
|
||||||
|
@ -137,13 +136,13 @@ class MemberEventMixin:
|
||||||
if (before.display_name == after.display_name and before.roles == after.roles) or (not after or not before):
|
if (before.display_name == after.display_name and before.roles == after.roles) or (not after or not before):
|
||||||
return
|
return
|
||||||
|
|
||||||
log = await Setting.find_one(q(guild=before.guild.id, setting="activitylog"))
|
log = await Setting.find_one(Setting.guild == before.guild.id, Setting.setting == "activitylog")
|
||||||
if log:
|
if log:
|
||||||
channel = await before.guild.fetch_channel(log.value)
|
channel = await before.guild.fetch_channel(log.value)
|
||||||
await asyncio.sleep(0.5) # Wait for audit log
|
await asyncio.sleep(0.5) # Wait for audit log
|
||||||
embed = None
|
embed = None
|
||||||
if before._role_ids != after._role_ids:
|
if before._role_ids != after._role_ids:
|
||||||
verified = await Setting.find_one(q(guild=before.guild.id, setting="verified"))
|
verified = await Setting.find_one(Setting.guild == before.guild.id, Setting.setting == "verified")
|
||||||
v_role = None
|
v_role = None
|
||||||
if verified:
|
if verified:
|
||||||
v_role = await before.guild.fetch_role(verified.value)
|
v_role = await before.guild.fetch_role(verified.value)
|
||||||
|
|
|
@ -3,7 +3,6 @@ import re
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from beanie.operators import Inc, Set
|
|
||||||
from interactions import listen
|
from interactions import listen
|
||||||
from interactions.api.events.discord import MessageCreate, MessageDelete, MessageUpdate
|
from interactions.api.events.discord import MessageCreate, MessageDelete, MessageUpdate
|
||||||
from interactions.client.utils.misc_utils import find_all
|
from interactions.client.utils.misc_utils import find_all
|
||||||
|
@ -13,7 +12,6 @@ from interactions.models.discord.embed import EmbedField
|
||||||
from interactions.models.discord.enums import ButtonStyle, Permissions
|
from interactions.models.discord.enums import ButtonStyle, Permissions
|
||||||
from interactions.models.discord.message import Message
|
from interactions.models.discord.message import Message
|
||||||
from interactions.models.discord.user import Member
|
from interactions.models.discord.user import Member
|
||||||
from jarvis_core.db import q
|
|
||||||
from jarvis_core.db.models import (
|
from jarvis_core.db.models import (
|
||||||
Autopurge,
|
Autopurge,
|
||||||
Autoreact,
|
Autoreact,
|
||||||
|
@ -37,7 +35,9 @@ class MessageEventMixin:
|
||||||
# Message
|
# Message
|
||||||
async def autopurge(self, message: Message) -> None:
|
async def autopurge(self, message: Message) -> None:
|
||||||
"""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(
|
||||||
|
Autopurge.guild == message.guild.id, Autopurge.channel == message.channel.id
|
||||||
|
)
|
||||||
if autopurge:
|
if autopurge:
|
||||||
if not message.author.has_permission(Permissions.ADMINISTRATOR):
|
if not message.author.has_permission(Permissions.ADMINISTRATOR):
|
||||||
self.logger.debug(f"Autopurging message {message.guild.id}/{message.channel.id}/{message.id}")
|
self.logger.debug(f"Autopurging message {message.guild.id}/{message.channel.id}/{message.id}")
|
||||||
|
@ -46,10 +46,8 @@ class MessageEventMixin:
|
||||||
async def autoreact(self, message: Message) -> None:
|
async def autoreact(self, message: Message) -> None:
|
||||||
"""Handle autoreact events."""
|
"""Handle autoreact events."""
|
||||||
autoreact = await Autoreact.find_one(
|
autoreact = await Autoreact.find_one(
|
||||||
q(
|
Autoreact.guild == message.guild.id,
|
||||||
guild=message.guild.id,
|
Autoreact.channel == message.channel.id,
|
||||||
channel=message.channel.id,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
if autoreact:
|
if autoreact:
|
||||||
self.logger.debug(f"Autoreacting to message {message.guild.id}/{message.channel.id}/{message.id}")
|
self.logger.debug(f"Autoreacting to message {message.guild.id}/{message.channel.id}/{message.id}")
|
||||||
|
@ -72,10 +70,10 @@ class MessageEventMixin:
|
||||||
# )
|
# )
|
||||||
content = re.sub(r"\s+", "", message.content)
|
content = re.sub(r"\s+", "", message.content)
|
||||||
match = invites.search(content)
|
match = invites.search(content)
|
||||||
setting = await Setting.find_one(q(guild=message.guild.id, setting="noinvite"))
|
setting = await Setting.find_one(Setting.guild == message.guild.id, Setting.setting == "noinvite")
|
||||||
if not setting:
|
if not setting:
|
||||||
setting = Setting(guild=message.guild.id, setting="noinvite", value=True)
|
setting = Setting(guild=message.guild.id, setting="noinvite", value=True)
|
||||||
await setting.commit()
|
await setting.save()
|
||||||
if match:
|
if match:
|
||||||
guild_invites = [x.code for x in await message.guild.fetch_invites()]
|
guild_invites = [x.code for x in await message.guild.fetch_invites()]
|
||||||
if message.guild.vanity_url_code:
|
if message.guild.vanity_url_code:
|
||||||
|
@ -100,17 +98,16 @@ class MessageEventMixin:
|
||||||
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()
|
).save()
|
||||||
md = WarningMetadata(
|
md = WarningMetadata(
|
||||||
client_id=self.user.id,
|
client_id=self.user.id,
|
||||||
client_name=self.client_name,
|
client_name=self.client_name,
|
||||||
name="warning",
|
|
||||||
type="invite",
|
type="invite",
|
||||||
guild_id=message.guild.id,
|
guild_id=message.guild.id,
|
||||||
guild_name=message.guild.name,
|
guild_name=message.guild.name,
|
||||||
value=1,
|
value=1,
|
||||||
)
|
)
|
||||||
await Stat(meta=md).insert()
|
await Stat(meta=md, name="warning").insert()
|
||||||
embed = warning_embed(message.author, "Sent an invite link", self.user)
|
embed = warning_embed(message.author, "Sent an invite link", self.user)
|
||||||
try:
|
try:
|
||||||
await message.channel.send(embeds=embed)
|
await message.channel.send(embeds=embed)
|
||||||
|
@ -119,8 +116,8 @@ class MessageEventMixin:
|
||||||
|
|
||||||
async def filters(self, message: Message) -> None:
|
async def filters(self, message: Message) -> None:
|
||||||
"""Handle filter evennts."""
|
"""Handle filter evennts."""
|
||||||
filters = await Filter.find(q(guild=message.guild.id)).to_list(None)
|
filters = Filter.find(Filter.guild == message.guild.id)
|
||||||
for item in filters:
|
async for item in filters:
|
||||||
for f in item.filters:
|
for f in item.filters:
|
||||||
if re.search(f, message.content, re.IGNORECASE):
|
if re.search(f, message.content, re.IGNORECASE):
|
||||||
expires_at = datetime.now(tz=timezone.utc) + timedelta(hours=24)
|
expires_at = datetime.now(tz=timezone.utc) + timedelta(hours=24)
|
||||||
|
@ -132,17 +129,16 @@ class MessageEventMixin:
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Sent a message with a filtered word",
|
reason="Sent a message with a filtered word",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
).commit()
|
).save()
|
||||||
md = WarningMetadata(
|
md = WarningMetadata(
|
||||||
client_id=self.user.id,
|
client_id=self.user.id,
|
||||||
client_name=self.client_name,
|
client_name=self.client_name,
|
||||||
name="warning",
|
|
||||||
type="filter",
|
type="filter",
|
||||||
guild_id=message.guild.id,
|
guild_id=message.guild.id,
|
||||||
guild_name=message.guild.name,
|
guild_name=message.guild.name,
|
||||||
value=1,
|
value=1,
|
||||||
)
|
)
|
||||||
await Stat(meta=md).insert()
|
await Stat(meta=md, name="warning").insert()
|
||||||
embed = warning_embed(message.author, "Sent a message with a filtered word", self.user)
|
embed = warning_embed(message.author, "Sent a message with a filtered word", self.user)
|
||||||
try:
|
try:
|
||||||
await message.reply(embeds=embed)
|
await message.reply(embeds=embed)
|
||||||
|
@ -158,10 +154,8 @@ class MessageEventMixin:
|
||||||
async def massmention(self, message: Message) -> None:
|
async def massmention(self, message: Message) -> None:
|
||||||
"""Handle massmention events."""
|
"""Handle massmention events."""
|
||||||
massmention = await Setting.find_one(
|
massmention = await Setting.find_one(
|
||||||
q(
|
Setting.guild == message.guild.id,
|
||||||
guild=message.guild.id,
|
Setting.setting == "massmention",
|
||||||
setting="massmention",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
is_mod = message.author.has_permission(Permissions.MANAGE_GUILD) or message.author.has_permission(
|
is_mod = message.author.has_permission(Permissions.MANAGE_GUILD) or message.author.has_permission(
|
||||||
|
@ -186,17 +180,16 @@ class MessageEventMixin:
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Mass Mention",
|
reason="Mass Mention",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
).commit()
|
).save()
|
||||||
md = WarningMetadata(
|
md = WarningMetadata(
|
||||||
client_id=self.user.id,
|
client_id=self.user.id,
|
||||||
client_name=self.client_name,
|
client_name=self.client_name,
|
||||||
name="warning",
|
|
||||||
type="massmention",
|
type="massmention",
|
||||||
guild_id=message.guild.id,
|
guild_id=message.guild.id,
|
||||||
guild_name=message.guild.name,
|
guild_name=message.guild.name,
|
||||||
value=1,
|
value=1,
|
||||||
)
|
)
|
||||||
await Stat(meta=md).insert()
|
await Stat(meta=md, name="warning").insert()
|
||||||
embed = warning_embed(message.author, "Mass Mention", self.user)
|
embed = warning_embed(message.author, "Mass Mention", self.user)
|
||||||
try:
|
try:
|
||||||
await message.channel.send(embeds=embed)
|
await message.channel.send(embeds=embed)
|
||||||
|
@ -210,9 +203,10 @@ class MessageEventMixin:
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("Failed to get permissions, pretending check failed", exc_info=e)
|
self.logger.error("Failed to get permissions, pretending check failed", exc_info=e)
|
||||||
if await Roleping.collection.count_documents(q(guild=message.guild.id, active=True)) == 0:
|
|
||||||
|
if await Roleping.find(Roleping.guild == message.guild.id, Roleping.active == True).count() == 0:
|
||||||
return
|
return
|
||||||
rolepings = await Roleping.find(q(guild=message.guild.id, active=True)).to_list(None)
|
rolepings = await Roleping.find(Roleping.guild == message.guild.id, Roleping.active == True).to_list()
|
||||||
|
|
||||||
# Get all role IDs involved with message
|
# Get all role IDs involved with message
|
||||||
roles = [x.id async for x in message.mention_roles]
|
roles = [x.id async for x in message.mention_roles]
|
||||||
|
@ -236,11 +230,11 @@ class MessageEventMixin:
|
||||||
|
|
||||||
# Check if user in a bypass list
|
# Check if user in a bypass list
|
||||||
def check_has_role(roleping: Roleping) -> bool:
|
def check_has_role(roleping: Roleping) -> bool:
|
||||||
return any(role.id in roleping.bypass["roles"] for role in message.author.roles)
|
return any(role.id in roleping.bypass.roles for role in message.author.roles)
|
||||||
|
|
||||||
user_has_bypass = False
|
user_has_bypass = False
|
||||||
for roleping in rolepings:
|
for roleping in rolepings:
|
||||||
if message.author.id in roleping.bypass["users"]:
|
if message.author.id in roleping.bypass.users:
|
||||||
user_has_bypass = True
|
user_has_bypass = True
|
||||||
break
|
break
|
||||||
if check_has_role(roleping):
|
if check_has_role(roleping):
|
||||||
|
@ -258,17 +252,16 @@ class MessageEventMixin:
|
||||||
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()
|
).save()
|
||||||
md = WarningMetadata(
|
md = WarningMetadata(
|
||||||
client_id=self.user.id,
|
client_id=self.user.id,
|
||||||
client_name=self.client_name,
|
client_name=self.client_name,
|
||||||
name="warning",
|
|
||||||
type="roleping",
|
type="roleping",
|
||||||
guild_id=message.guild.id,
|
guild_id=message.guild.id,
|
||||||
guild_name=message.guild.name,
|
guild_name=message.guild.name,
|
||||||
value=1,
|
value=1,
|
||||||
)
|
)
|
||||||
await Stat(meta=md).insert()
|
await Stat(meta=md, name="warning").insert()
|
||||||
embed = warning_embed(message.author, "Pinged a blocked role/user with a blocked role", self.user)
|
embed = warning_embed(message.author, "Pinged a blocked role/user with a blocked role", self.user)
|
||||||
try:
|
try:
|
||||||
await message.channel.send(embeds=embed)
|
await message.channel.send(embeds=embed)
|
||||||
|
@ -279,7 +272,7 @@ class MessageEventMixin:
|
||||||
"""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 (m := match.group("domain")) in self.phishing_domains:
|
if (m := match.group("domain")) in self.phishing_domains:
|
||||||
pl = await Phishlist.find_one(q(url=m))
|
pl = await Phishlist.find_one(Phishlist.url == m)
|
||||||
if pl and pl.confirmed and not pl.valid:
|
if pl and pl.confirmed and not pl.valid:
|
||||||
return False
|
return False
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
|
@ -294,17 +287,16 @@ class MessageEventMixin:
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Phishing URL",
|
reason="Phishing URL",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
).commit()
|
).save()
|
||||||
md = WarningMetadata(
|
md = WarningMetadata(
|
||||||
client_id=self.user.id,
|
client_id=self.user.id,
|
||||||
client_name=self.client_name,
|
client_name=self.client_name,
|
||||||
name="warning",
|
name="warning",
|
||||||
type="phishing",
|
|
||||||
guild_id=message.guild.id,
|
guild_id=message.guild.id,
|
||||||
guild_name=message.guild.name,
|
guild_name=message.guild.name,
|
||||||
value=1,
|
value=1,
|
||||||
)
|
)
|
||||||
await Stat(meta=md).insert()
|
await Stat(meta=md, name="warning").insert()
|
||||||
embed = warning_embed(message.author, "Phishing URL", self.user)
|
embed = warning_embed(message.author, "Phishing URL", self.user)
|
||||||
try:
|
try:
|
||||||
await message.channel.send(embeds=embed)
|
await message.channel.send(embeds=embed)
|
||||||
|
@ -318,7 +310,7 @@ class MessageEventMixin:
|
||||||
if not pl or not pl.confirmed:
|
if not pl or not pl.confirmed:
|
||||||
if not pl:
|
if not pl:
|
||||||
pl = Phishlist(url=m)
|
pl = Phishlist(url=m)
|
||||||
await pl.commit()
|
await pl.save()
|
||||||
|
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="Phishing URL detected",
|
title="Phishing URL detected",
|
||||||
|
@ -342,7 +334,7 @@ class MessageEventMixin:
|
||||||
"""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):
|
||||||
m = match.group("domain")
|
m = match.group("domain")
|
||||||
pl = await Phishlist.find_one(q(url=m))
|
pl = await Phishlist.find_one(Phishlist.url == m)
|
||||||
if pl and pl.confirmed and not pl.valid:
|
if pl and pl.confirmed and not pl.valid:
|
||||||
return False
|
return False
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
|
@ -370,17 +362,16 @@ class MessageEventMixin:
|
||||||
guild=message.guild.id,
|
guild=message.guild.id,
|
||||||
reason="Unsafe URL",
|
reason="Unsafe URL",
|
||||||
user=message.author.id,
|
user=message.author.id,
|
||||||
).commit()
|
).save()
|
||||||
md = WarningMetadata(
|
md = WarningMetadata(
|
||||||
client_id=self.user.id,
|
client_id=self.user.id,
|
||||||
client_name=self.client_name,
|
client_name=self.client_name,
|
||||||
name="warning",
|
|
||||||
type="malicious",
|
type="malicious",
|
||||||
guild_id=message.guild.id,
|
guild_id=message.guild.id,
|
||||||
guild_name=message.guild.name,
|
guild_name=message.guild.name,
|
||||||
value=1,
|
value=1,
|
||||||
)
|
)
|
||||||
await Stat(meta=md).insert()
|
await Stat(meta=md, name="warning").insert()
|
||||||
reasons = ", ".join(f"{m['source']}: {m['type']}" for m in data["matches"])
|
reasons = ", ".join(f"{m['source']}: {m['type']}" for m in data["matches"])
|
||||||
embed = warning_embed(message.author, reasons, self.user)
|
embed = warning_embed(message.author, reasons, self.user)
|
||||||
try:
|
try:
|
||||||
|
@ -395,7 +386,7 @@ class MessageEventMixin:
|
||||||
if not pl or not pl.confirmed:
|
if not pl or not pl.confirmed:
|
||||||
if not pl:
|
if not pl:
|
||||||
pl = Phishlist(url=m)
|
pl = Phishlist(url=m)
|
||||||
await pl.commit()
|
await pl.save()
|
||||||
|
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="Malicious URL detected",
|
title="Malicious URL detected",
|
||||||
|
@ -427,7 +418,7 @@ class MessageEventMixin:
|
||||||
guild=user.guild.id,
|
guild=user.guild.id,
|
||||||
duration=30,
|
duration=30,
|
||||||
active=True,
|
active=True,
|
||||||
).commit()
|
).save()
|
||||||
ts = int(expires_at.timestamp())
|
ts = int(expires_at.timestamp())
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="User Muted",
|
title="User Muted",
|
||||||
|
@ -468,8 +459,8 @@ class MessageEventMixin:
|
||||||
before = event.before
|
before = event.before
|
||||||
after = event.after
|
after = event.after
|
||||||
if not after.author.bot:
|
if not after.author.bot:
|
||||||
modlog = await Setting.find_one(q(guild=after.guild.id, setting="activitylog"))
|
modlog = await Setting.find_one(Setting.guild == after.guild.id, Setting.setting == "activitylog")
|
||||||
ignore = await Setting.find_one(q(guild=after.guild.id, setting="log_ignore"))
|
ignore = await Setting.find_one(Setting.guild == after.guild.id, Setting.setting == "log_ignore")
|
||||||
if modlog and (not ignore or (ignore and after.channel.id not in ignore.value)):
|
if modlog and (not ignore or (ignore and after.channel.id not in ignore.value)):
|
||||||
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
|
||||||
|
@ -521,8 +512,8 @@ class MessageEventMixin:
|
||||||
async def on_message_delete(self, event: MessageDelete) -> None:
|
async def on_message_delete(self, event: MessageDelete) -> None:
|
||||||
"""Process on_message_delete events."""
|
"""Process on_message_delete events."""
|
||||||
message = event.message
|
message = event.message
|
||||||
modlog = await Setting.find_one(q(guild=message.guild.id, setting="activitylog"))
|
modlog = await Setting.find_one(Setting.guild == message.guild.id, Setting.setting == "activitylog")
|
||||||
ignore = await Setting.find_one(q(guild=message.guild.id, setting="log_ignore"))
|
ignore = await Setting.find_one(Setting.guild == message.guild.id, Setting.setting == "log_ignore")
|
||||||
if modlog and (not ignore or (ignore and message.channel.id not in ignore.value)):
|
if modlog and (not ignore or (ignore and message.channel.id not in ignore.value)):
|
||||||
try:
|
try:
|
||||||
content = message.content or "N/A"
|
content = message.content or "N/A"
|
||||||
|
|
|
@ -248,7 +248,7 @@ class BanCog(ModcaseCog):
|
||||||
if not discord_ban_info:
|
if not discord_ban_info:
|
||||||
if isinstance(user, User):
|
if isinstance(user, User):
|
||||||
database_ban_info = await Ban.find_one(
|
database_ban_info = await Ban.find_one(
|
||||||
Ban.guild == ctx.guild.id, Ban.user == user.id, Ban.active is True
|
Ban.guild == ctx.guild.id, Ban.user == user.id, Ban.active == True
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
search = {
|
search = {
|
||||||
|
|
|
@ -99,7 +99,7 @@ class LockCog(Extension):
|
||||||
) -> None:
|
) -> None:
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = ctx.channel
|
channel = ctx.channel
|
||||||
lock = await Lock.find_one(Lock.guild == ctx.guild.id, Lock.channel == channel.id, Lock.active is True)
|
lock = await Lock.find_one(Lock.guild == ctx.guild.id, Lock.channel == channel.id, Lock.active == True)
|
||||||
if not lock:
|
if not lock:
|
||||||
await ctx.send(f"{channel.mention} not locked.", ephemeral=True)
|
await ctx.send(f"{channel.mention} not locked.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
|
@ -72,7 +72,7 @@ async def unlock_all(bot: Client, guild: Guild, admin: Member) -> None:
|
||||||
target: Target channel
|
target: Target channel
|
||||||
admin: Admin who ended lockdown
|
admin: Admin who ended lockdown
|
||||||
"""
|
"""
|
||||||
locks = Lock.find(Lock.guild == guild.id, Lock.active is True)
|
locks = Lock.find(Lock.guild == guild.id, Lock.active == True)
|
||||||
async for lock in locks:
|
async for lock in locks:
|
||||||
target = await guild.fetch_channel(lock.channel)
|
target = await guild.fetch_channel(lock.channel)
|
||||||
if target:
|
if target:
|
||||||
|
@ -85,7 +85,7 @@ async def unlock_all(bot: Client, guild: Guild, admin: Member) -> None:
|
||||||
await target.delete_permission(target=overwrite, reason="Lockdown end")
|
await target.delete_permission(target=overwrite, reason="Lockdown end")
|
||||||
lock.active = False
|
lock.active = False
|
||||||
await lock.save()
|
await lock.save()
|
||||||
lockdown = await Lockdown.find_one(Lockdown.guild == guild.id, Lockdown.active is True)
|
lockdown = await Lockdown.find_one(Lockdown.guild == guild.id, Lockdown.active == True)
|
||||||
if lockdown:
|
if lockdown:
|
||||||
lockdown.active = False
|
lockdown.active = False
|
||||||
await lockdown.save()
|
await lockdown.save()
|
||||||
|
@ -129,7 +129,7 @@ class LockdownCog(Extension):
|
||||||
await ctx.send("Duration must be <= 7 days", ephemeral=True)
|
await ctx.send("Duration must be <= 7 days", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
exists = await Lockdown.find_one(Lockdown.guild == ctx.guild.id, Lockdown.active is True)
|
exists = await Lockdown.find_one(Lockdown.guild == ctx.guild.id, Lockdown.active == True)
|
||||||
if exists:
|
if exists:
|
||||||
await ctx.send("Server already in lockdown", ephemeral=True)
|
await ctx.send("Server already in lockdown", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
@ -156,7 +156,7 @@ class LockdownCog(Extension):
|
||||||
) -> None:
|
) -> None:
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
|
||||||
lockdown = await Lockdown.find_one(Lockdown.guild == ctx.guild.id, Lockdown.active is True)
|
lockdown = await Lockdown.find_one(Lockdown.guild == ctx.guild.id, Lockdown.active == True)
|
||||||
if not lockdown:
|
if not lockdown:
|
||||||
await ctx.send("Server not in lockdown", ephemeral=True)
|
await ctx.send("Server not in lockdown", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
|
@ -131,7 +131,7 @@ class CaseCog(Extension):
|
||||||
embed.set_author(name=username, icon_url=icon_url)
|
embed.set_author(name=username, icon_url=icon_url)
|
||||||
embed.set_footer(text=str(mod_case.user))
|
embed.set_footer(text=str(mod_case.user))
|
||||||
|
|
||||||
await mod_case.commit()
|
await mod_case.save()
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
async def get_action_embeds(self, mod_case: Modlog, guild: "Guild") -> List[Embed]:
|
async def get_action_embeds(self, mod_case: Modlog, guild: "Guild") -> List[Embed]:
|
||||||
|
@ -176,7 +176,7 @@ class CaseCog(Extension):
|
||||||
embed.set_author(name=username, icon_url=avatar_url)
|
embed.set_author(name=username, icon_url=avatar_url)
|
||||||
embeds.append(embed)
|
embeds.append(embed)
|
||||||
|
|
||||||
await mod_case.commit()
|
await mod_case.save()
|
||||||
return embeds
|
return embeds
|
||||||
|
|
||||||
cases = SlashCommand(name="cases", description="Manage moderation cases")
|
cases = SlashCommand(name="cases", description="Manage moderation cases")
|
||||||
|
@ -198,10 +198,9 @@ class CaseCog(Extension):
|
||||||
async def _cases_list(self, ctx: InteractionContext, user: Optional[Member] = None, closed: bool = False) -> None:
|
async def _cases_list(self, ctx: InteractionContext, user: Optional[Member] = None, closed: bool = False) -> None:
|
||||||
query = [Modlog.guild == ctx.guild.id]
|
query = [Modlog.guild == ctx.guild.id]
|
||||||
if not closed:
|
if not closed:
|
||||||
query.append(Modlog.open is True)
|
query.append(Modlog.open == True)
|
||||||
if user:
|
if user:
|
||||||
query.append(Modlog.user == user.id)
|
query.append(Modlog.user == user.id)
|
||||||
|
|
||||||
cases = await Modlog.find(*query).sort(+Modlog.created_at).to_list()
|
cases = await Modlog.find(*query).sort(+Modlog.created_at).to_list()
|
||||||
|
|
||||||
if len(cases) == 0:
|
if len(cases) == 0:
|
||||||
|
@ -301,7 +300,7 @@ class CaseCog(Extension):
|
||||||
@slash_option(name="note", description="Note to add", opt_type=OptionType.STRING, required=True)
|
@slash_option(name="note", description="Note to add", opt_type=OptionType.STRING, required=True)
|
||||||
@check(admin_or_permissions(Permissions.BAN_MEMBERS))
|
@check(admin_or_permissions(Permissions.BAN_MEMBERS))
|
||||||
async def _case_new(self, ctx: InteractionContext, user: Member, note: str) -> None:
|
async def _case_new(self, ctx: InteractionContext, user: Member, note: str) -> None:
|
||||||
case = await Modlog.find_one(Modlog.guild == ctx.guild.id, Modlog.user == user.id, Modlog.open is True)
|
case = await Modlog.find_one(Modlog.guild == ctx.guild.id, Modlog.user == user.id, Modlog.open == True)
|
||||||
if case:
|
if case:
|
||||||
await ctx.send(f"Case already open with ID `{case.nanoid}`", ephemeral=True)
|
await ctx.send(f"Case already open with ID `{case.nanoid}`", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
|
@ -43,7 +43,7 @@ class PurgeCog(Extension):
|
||||||
channel=ctx.channel.id,
|
channel=ctx.channel.id,
|
||||||
guild=ctx.guild.id,
|
guild=ctx.guild.id,
|
||||||
admin=ctx.author.id,
|
admin=ctx.author.id,
|
||||||
count=amount,
|
count_=amount,
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
@slash_command(name="autopurge", sub_cmd_name="add", sub_cmd_description="Automatically purge messages")
|
@slash_command(name="autopurge", sub_cmd_name="add", sub_cmd_description="Automatically purge messages")
|
||||||
|
|
|
@ -138,7 +138,7 @@ class RemindmeCog(Extension):
|
||||||
active=True,
|
active=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await r.commit()
|
await r.save()
|
||||||
|
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="Reminder Set",
|
title="Reminder Set",
|
||||||
|
@ -204,7 +204,7 @@ class RemindmeCog(Extension):
|
||||||
|
|
||||||
@reminders.subcommand(sub_cmd_name="list", sub_cmd_description="List reminders")
|
@reminders.subcommand(sub_cmd_name="list", sub_cmd_description="List reminders")
|
||||||
async def _list(self, ctx: InteractionContext) -> None:
|
async def _list(self, ctx: InteractionContext) -> None:
|
||||||
reminders = await Reminder.find(Reminder.user == ctx.author.id, Reminder.active is True).to_list()
|
reminders = await Reminder.find(Reminder.user == ctx.author.id, Reminder.active == True).to_list()
|
||||||
if not reminders:
|
if not reminders:
|
||||||
await ctx.send("You have no reminders set.", ephemeral=True)
|
await ctx.send("You have no reminders set.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,7 +4,13 @@ import re
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from interactions import AutocompleteContext, Client, Extension, InteractionContext
|
from interactions import (
|
||||||
|
AutocompleteContext,
|
||||||
|
Client,
|
||||||
|
Extension,
|
||||||
|
InteractionContext,
|
||||||
|
SlashContext,
|
||||||
|
)
|
||||||
from interactions.models.discord.components import Button
|
from interactions.models.discord.components import Button
|
||||||
from interactions.models.discord.embed import EmbedField
|
from interactions.models.discord.embed import EmbedField
|
||||||
from interactions.models.discord.enums import ButtonStyle, Permissions
|
from interactions.models.discord.enums import ButtonStyle, Permissions
|
||||||
|
@ -50,7 +56,7 @@ class TagCog(Extension):
|
||||||
await ctx.send(tag.content)
|
await ctx.send(tag.content)
|
||||||
|
|
||||||
@tag.subcommand(sub_cmd_name="create", sub_cmd_description="Create a tag")
|
@tag.subcommand(sub_cmd_name="create", sub_cmd_description="Create a tag")
|
||||||
async def _create(self, ctx: InteractionContext) -> None:
|
async def _create(self, ctx: SlashContext) -> None:
|
||||||
modal = Modal(
|
modal = Modal(
|
||||||
title="Create a new tag!",
|
title="Create a new tag!",
|
||||||
components=[
|
components=[
|
||||||
|
@ -316,11 +322,11 @@ class TagCog(Extension):
|
||||||
@_edit.autocomplete("name")
|
@_edit.autocomplete("name")
|
||||||
@_delete.autocomplete("name")
|
@_delete.autocomplete("name")
|
||||||
@_info.autocomplete("name")
|
@_info.autocomplete("name")
|
||||||
async def _autocomplete(self, ctx: AutocompleteContext, name: str) -> None:
|
async def _autocomplete(self, ctx: AutocompleteContext) -> None:
|
||||||
if not self.cache.get(ctx.guild.id):
|
if not self.cache.get(ctx.guild.id):
|
||||||
tags = await Tag.find(Tag.guild == ctx.guild.id).to_list()
|
tags = await Tag.find(Tag.guild == ctx.guild.id).to_list()
|
||||||
self.cache[ctx.guild.id] = [tag.name for tag in tags]
|
self.cache[ctx.guild.id] = [tag.name for tag in tags]
|
||||||
results = process.extract(name, self.cache.get(ctx.guild.id), limit=25)
|
results = process.extract(ctx.input_text, self.cache.get(ctx.guild.id), limit=25)
|
||||||
choices = [{"name": r[0], "value": r[0]} for r in results]
|
choices = [{"name": r[0], "value": r[0]} for r in results]
|
||||||
await ctx.send(choices=choices)
|
await ctx.send(choices=choices)
|
||||||
|
|
||||||
|
|
|
@ -436,6 +436,8 @@ class GitlabCog(Extension):
|
||||||
|
|
||||||
def setup(bot: Client) -> None:
|
def setup(bot: Client) -> None:
|
||||||
"""Add GitlabCog to JARVIS if Gitlab token exists."""
|
"""Add GitlabCog to JARVIS if Gitlab token exists."""
|
||||||
|
bot.logger.warn("GitlabCog is deprecated")
|
||||||
|
return
|
||||||
if load_config().gitlab_token:
|
if load_config().gitlab_token:
|
||||||
GitlabCog(bot)
|
GitlabCog(bot)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -68,14 +68,14 @@ class ModcaseCog(Extension):
|
||||||
return
|
return
|
||||||
|
|
||||||
action = await coll.find_one(
|
action = await coll.find_one(
|
||||||
coll.user == user.id, coll.guild == ctx.guild.id, coll.active is True, sort=[("_id", -1)]
|
coll.user == user.id, coll.guild == ctx.guild.id, coll.active == True, sort=[("_id", -1)]
|
||||||
)
|
)
|
||||||
if not action:
|
if not action:
|
||||||
self.logger.warning("Missing action %s, exiting", name)
|
self.logger.warning("Missing action %s, exiting", name)
|
||||||
return
|
return
|
||||||
|
|
||||||
notify = await Setting.find_one(
|
notify = await Setting.find_one(
|
||||||
Setting.guild == ctx.guild.id, Setting.setting == "notify", Setting.value is True
|
Setting.guild == ctx.guild.id, Setting.setting == "notify", Setting.value == True
|
||||||
)
|
)
|
||||||
if notify and name not in ("Kick", "Ban"): # Ignore Kick and Ban, as these are unique
|
if notify and name not in ("Kick", "Ban"): # Ignore Kick and Ban, as these are unique
|
||||||
fields = (
|
fields = (
|
||||||
|
@ -98,7 +98,7 @@ class ModcaseCog(Extension):
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.debug("User not warned of action due to closed DMs")
|
self.logger.debug("User not warned of action due to closed DMs")
|
||||||
|
|
||||||
modlog = await Modlog.find_one(Modlog.user == user.id, Modlog.guild == ctx.guild.id, Modlog.open is True)
|
modlog = await Modlog.find_one(Modlog.user == user.id, Modlog.guild == ctx.guild.id, Modlog.open == True)
|
||||||
|
|
||||||
if modlog:
|
if modlog:
|
||||||
m_action = Action(action_type=name.lower(), parent=action.id)
|
m_action = Action(action_type=name.lower(), parent=action.id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue