From ac71dbd5fd3ae11c995d4bff75fd7e3e6e2fd89e Mon Sep 17 00:00:00 2001 From: zevaryx Date: Fri, 24 Mar 2023 13:45:33 -0600 Subject: [PATCH] Fix some breakages related to beanie --- .flake8 | 2 +- jarvis/client/__init__.py | 1 - jarvis/client/events/__init__.py | 5 +- jarvis/client/events/components.py | 21 ++++---- jarvis/client/events/member.py | 9 ++-- jarvis/client/events/message.py | 83 +++++++++++++----------------- jarvis/cogs/core/admin/ban.py | 2 +- jarvis/cogs/core/admin/lock.py | 2 +- jarvis/cogs/core/admin/lockdown.py | 8 +-- jarvis/cogs/core/admin/modcase.py | 9 ++-- jarvis/cogs/core/admin/purge.py | 2 +- jarvis/cogs/core/remindme.py | 4 +- jarvis/cogs/extra/tags.py | 14 +++-- jarvis/cogs/unique/gl.py | 2 + jarvis/utils/cogs.py | 6 +-- 15 files changed, 83 insertions(+), 87 deletions(-) diff --git a/.flake8 b/.flake8 index 54f1937..f06b647 100644 --- a/.flake8 +++ b/.flake8 @@ -9,7 +9,7 @@ extend-ignore = D401, # First line should be in imperative mood; try rephrasing D400, # First line should end with a period D101, # Missing docstring in public class - + E712, # is bool, beanie requires == bool # Plugins we don't currently include: flake8-return 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. diff --git a/jarvis/client/__init__.py b/jarvis/client/__init__.py index 980877f..56853a1 100644 --- a/jarvis/client/__init__.py +++ b/jarvis/client/__init__.py @@ -2,7 +2,6 @@ import logging from typing import TYPE_CHECKING -from interactions import Client from interactions.ext.prefixed_commands.context import PrefixedContext from interactions.models.internal.context import BaseContext, InteractionContext from jarvis_core.util.ansi import Fore, Format, fmt diff --git a/jarvis/client/events/__init__.py b/jarvis/client/events/__init__.py index e84ffae..752d0f3 100644 --- a/jarvis/client/events/__init__.py +++ b/jarvis/client/events/__init__.py @@ -9,7 +9,6 @@ from interactions.models.discord.channel import DMChannel from interactions.models.discord.embed import EmbedField from interactions.models.internal.application_commands import ContextMenu 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.util.ansi import RESET, Fore, Format, fmt from statipy.db import StaticStat @@ -114,8 +113,8 @@ class EventMixin(MemberEventMixin, MessageEventMixin, ComponentEventMixin): """NAFF on_command override.""" name = ctx.invoke_target if not isinstance(ctx.channel, DMChannel) and name not in ["pw"]: - modlog = await Setting.find_one(q(guild=ctx.guild.id, setting="activitylog")) - ignore = await Setting.find_one(q(guild=ctx.guild.id, setting="log_ignore")) + modlog = await Setting.find_one(Setting.guild == ctx.guild.id, Setting.setting == "activitylog") + 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): channel = await ctx.guild.fetch_channel(modlog.value) args = [] diff --git a/jarvis/client/events/components.py b/jarvis/client/events/components.py index 4f68a3e..2390e9c 100644 --- a/jarvis/client/events/components.py +++ b/jarvis/client/events/components.py @@ -3,8 +3,7 @@ from interactions import listen from interactions.api.events.internal import ButtonPressed from interactions.models.discord.embed import EmbedField from interactions.models.discord.enums import Permissions -from jarvis_core.db import q -from jarvis_core.db.models import Action, Modlog, Note, Phishlist, Reminder, Star +from jarvis_core.db.models import Action, Modlog, Note, Phishlist, Pin, Reminder from jarvis.utils import build_embed @@ -34,7 +33,9 @@ class ComponentEventMixin: name, parent = action_data.split("|")[:2] action = Action(action_type=name, parent=parent) 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: self.logger.debug("User already has active case in guild") await context.send(f"User already has open case: {modlog.nanoid}", ephemeral=True) @@ -46,7 +47,7 @@ class ComponentEventMixin: actions=[action], notes=[note], ) - await modlog.commit() + await modlog.save() fields = ( 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) return True # User does not have perms to delete - if star := await Star.find_one(q(star=context.message.id, guild=context.guild.id)): - await star.delete() + if pin := await Pin.find_one(Pin.pin == context.message.id, Pin.guild == context.guild.id): + await pin.delete() await context.message.delete() await context.send("Message deleted", ephemeral=True) @@ -118,7 +119,7 @@ class ComponentEventMixin: what, rid = context.custom_id.split("|")[1:] if what == "rme": - reminder = await Reminder.find_one(q(_id=rid)) + reminder = await Reminder.find_one(Reminder.id == rid) if reminder: new_reminder = Reminder( user=context.author.id, @@ -129,7 +130,7 @@ class ComponentEventMixin: private=reminder.private, active=reminder.active, ) - await new_reminder.commit() + await new_reminder.save() await context.send("Reminder copied!", ephemeral=True) @@ -145,7 +146,7 @@ class ComponentEventMixin: _, valid, id_ = context.custom_id.split("|") valid = valid == "valid" - pl = await Phishlist.find_one(q(_id=id_)) + pl = await Phishlist.find_one(Phishlist.id == id_) if not pl: self.logger.warn(f"Phishlist {id_} does not exist!") return False @@ -153,7 +154,7 @@ class ComponentEventMixin: pl.valid = valid pl.confirmed = True - await pl.commit() + await pl.save() for row in context.message.components: for component in row.components: diff --git a/jarvis/client/events/member.py b/jarvis/client/events/member.py index 8762077..9e996ac 100644 --- a/jarvis/client/events/member.py +++ b/jarvis/client/events/member.py @@ -7,7 +7,6 @@ from interactions.client.utils.misc_utils import get from interactions.models.discord.embed import Embed, EmbedField from interactions.models.discord.enums import AuditLogEventType from interactions.models.discord.user import Member -from jarvis_core.db import q from jarvis_core.db.models import Setting from jarvis.utils import build_embed @@ -21,7 +20,7 @@ class MemberEventMixin: """Handle on_member_add event.""" user = event.member 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: self.logger.debug(f"Applying unverified role to {user.id} in {guild.id}") role = await guild.fetch_role(unverified.value) @@ -33,7 +32,7 @@ class MemberEventMixin: """Handle on_member_remove event.""" user = event.member 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: self.logger.debug(f"User {user.id} left {guild.id}") 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): 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: channel = await before.guild.fetch_channel(log.value) await asyncio.sleep(0.5) # Wait for audit log embed = None 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 if verified: v_role = await before.guild.fetch_role(verified.value) diff --git a/jarvis/client/events/message.py b/jarvis/client/events/message.py index 5b1cf7c..e12e3bc 100644 --- a/jarvis/client/events/message.py +++ b/jarvis/client/events/message.py @@ -3,7 +3,6 @@ import re from datetime import datetime, timedelta, timezone from aiohttp import ClientSession -from beanie.operators import Inc, Set from interactions import listen from interactions.api.events.discord import MessageCreate, MessageDelete, MessageUpdate 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.message import Message from interactions.models.discord.user import Member -from jarvis_core.db import q from jarvis_core.db.models import ( Autopurge, Autoreact, @@ -37,7 +35,9 @@ class MessageEventMixin: # Message async def autopurge(self, message: Message) -> None: """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 not message.author.has_permission(Permissions.ADMINISTRATOR): 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: """Handle autoreact events.""" autoreact = await Autoreact.find_one( - q( - guild=message.guild.id, - channel=message.channel.id, - ) + Autoreact.guild == message.guild.id, + Autoreact.channel == message.channel.id, ) if autoreact: 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) 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: setting = Setting(guild=message.guild.id, setting="noinvite", value=True) - await setting.commit() + await setting.save() if match: guild_invites = [x.code for x in await message.guild.fetch_invites()] if message.guild.vanity_url_code: @@ -100,17 +98,16 @@ class MessageEventMixin: guild=message.guild.id, reason="Sent an invite link", user=message.author.id, - ).commit() + ).save() md = WarningMetadata( client_id=self.user.id, client_name=self.client_name, - name="warning", type="invite", guild_id=message.guild.id, guild_name=message.guild.name, 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) try: await message.channel.send(embeds=embed) @@ -119,8 +116,8 @@ class MessageEventMixin: async def filters(self, message: Message) -> None: """Handle filter evennts.""" - filters = await Filter.find(q(guild=message.guild.id)).to_list(None) - for item in filters: + filters = Filter.find(Filter.guild == message.guild.id) + async for item in filters: for f in item.filters: if re.search(f, message.content, re.IGNORECASE): expires_at = datetime.now(tz=timezone.utc) + timedelta(hours=24) @@ -132,17 +129,16 @@ class MessageEventMixin: guild=message.guild.id, reason="Sent a message with a filtered word", user=message.author.id, - ).commit() + ).save() md = WarningMetadata( client_id=self.user.id, client_name=self.client_name, - name="warning", type="filter", guild_id=message.guild.id, guild_name=message.guild.name, 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) try: await message.reply(embeds=embed) @@ -158,10 +154,8 @@ class MessageEventMixin: async def massmention(self, message: Message) -> None: """Handle massmention events.""" massmention = await Setting.find_one( - q( - guild=message.guild.id, - setting="massmention", - ) + Setting.guild == message.guild.id, + Setting.setting == "massmention", ) is_mod = message.author.has_permission(Permissions.MANAGE_GUILD) or message.author.has_permission( @@ -186,17 +180,16 @@ class MessageEventMixin: guild=message.guild.id, reason="Mass Mention", user=message.author.id, - ).commit() + ).save() md = WarningMetadata( client_id=self.user.id, client_name=self.client_name, - name="warning", type="massmention", guild_id=message.guild.id, guild_name=message.guild.name, value=1, ) - await Stat(meta=md).insert() + await Stat(meta=md, name="warning").insert() embed = warning_embed(message.author, "Mass Mention", self.user) try: await message.channel.send(embeds=embed) @@ -210,9 +203,10 @@ class MessageEventMixin: return except Exception as 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 - 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 roles = [x.id async for x in message.mention_roles] @@ -236,11 +230,11 @@ class MessageEventMixin: # Check if user in a bypass list 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 for roleping in rolepings: - if message.author.id in roleping.bypass["users"]: + if message.author.id in roleping.bypass.users: user_has_bypass = True break if check_has_role(roleping): @@ -258,17 +252,16 @@ class MessageEventMixin: guild=message.guild.id, reason="Pinged a blocked role/user with a blocked role", user=message.author.id, - ).commit() + ).save() md = WarningMetadata( client_id=self.user.id, client_name=self.client_name, - name="warning", type="roleping", guild_id=message.guild.id, guild_name=message.guild.name, 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) try: await message.channel.send(embeds=embed) @@ -279,7 +272,7 @@ class MessageEventMixin: """Check if the message contains any known phishing domains.""" for match in url.finditer(message.content): 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: return False self.logger.debug( @@ -294,17 +287,16 @@ class MessageEventMixin: guild=message.guild.id, reason="Phishing URL", user=message.author.id, - ).commit() + ).save() md = WarningMetadata( client_id=self.user.id, client_name=self.client_name, name="warning", - type="phishing", guild_id=message.guild.id, guild_name=message.guild.name, value=1, ) - await Stat(meta=md).insert() + await Stat(meta=md, name="warning").insert() embed = warning_embed(message.author, "Phishing URL", self.user) try: await message.channel.send(embeds=embed) @@ -318,7 +310,7 @@ class MessageEventMixin: if not pl or not pl.confirmed: if not pl: pl = Phishlist(url=m) - await pl.commit() + await pl.save() embed = build_embed( title="Phishing URL detected", @@ -342,7 +334,7 @@ class MessageEventMixin: """Check if the message contains any known phishing domains.""" for match in url.finditer(message.content): 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: return False async with ClientSession() as session: @@ -370,17 +362,16 @@ class MessageEventMixin: guild=message.guild.id, reason="Unsafe URL", user=message.author.id, - ).commit() + ).save() md = WarningMetadata( client_id=self.user.id, client_name=self.client_name, - name="warning", type="malicious", guild_id=message.guild.id, guild_name=message.guild.name, 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"]) embed = warning_embed(message.author, reasons, self.user) try: @@ -395,7 +386,7 @@ class MessageEventMixin: if not pl or not pl.confirmed: if not pl: pl = Phishlist(url=m) - await pl.commit() + await pl.save() embed = build_embed( title="Malicious URL detected", @@ -427,7 +418,7 @@ class MessageEventMixin: guild=user.guild.id, duration=30, active=True, - ).commit() + ).save() ts = int(expires_at.timestamp()) embed = build_embed( title="User Muted", @@ -468,8 +459,8 @@ class MessageEventMixin: before = event.before after = event.after if not after.author.bot: - modlog = await Setting.find_one(q(guild=after.guild.id, setting="activitylog")) - ignore = await Setting.find_one(q(guild=after.guild.id, setting="log_ignore")) + modlog = await Setting.find_one(Setting.guild == after.guild.id, Setting.setting == "activitylog") + 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 not before or before.content == after.content or before.content is None: return @@ -521,8 +512,8 @@ class MessageEventMixin: async def on_message_delete(self, event: MessageDelete) -> None: """Process on_message_delete events.""" message = event.message - modlog = await Setting.find_one(q(guild=message.guild.id, setting="activitylog")) - ignore = await Setting.find_one(q(guild=message.guild.id, setting="log_ignore")) + modlog = await Setting.find_one(Setting.guild == message.guild.id, Setting.setting == "activitylog") + 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)): try: content = message.content or "N/A" diff --git a/jarvis/cogs/core/admin/ban.py b/jarvis/cogs/core/admin/ban.py index 84152c0..e6e06ad 100644 --- a/jarvis/cogs/core/admin/ban.py +++ b/jarvis/cogs/core/admin/ban.py @@ -248,7 +248,7 @@ class BanCog(ModcaseCog): if not discord_ban_info: if isinstance(user, User): 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: search = { diff --git a/jarvis/cogs/core/admin/lock.py b/jarvis/cogs/core/admin/lock.py index c89e226..a6f4ebb 100644 --- a/jarvis/cogs/core/admin/lock.py +++ b/jarvis/cogs/core/admin/lock.py @@ -99,7 +99,7 @@ class LockCog(Extension): ) -> None: if not 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: await ctx.send(f"{channel.mention} not locked.", ephemeral=True) return diff --git a/jarvis/cogs/core/admin/lockdown.py b/jarvis/cogs/core/admin/lockdown.py index 0de3690..c001d75 100644 --- a/jarvis/cogs/core/admin/lockdown.py +++ b/jarvis/cogs/core/admin/lockdown.py @@ -72,7 +72,7 @@ async def unlock_all(bot: Client, guild: Guild, admin: Member) -> None: target: Target channel 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: target = await guild.fetch_channel(lock.channel) 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") lock.active = False 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: lockdown.active = False await lockdown.save() @@ -129,7 +129,7 @@ class LockdownCog(Extension): await ctx.send("Duration must be <= 7 days", ephemeral=True) 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: await ctx.send("Server already in lockdown", ephemeral=True) return @@ -156,7 +156,7 @@ class LockdownCog(Extension): ) -> None: 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: await ctx.send("Server not in lockdown", ephemeral=True) return diff --git a/jarvis/cogs/core/admin/modcase.py b/jarvis/cogs/core/admin/modcase.py index 4b8eb75..d9cebcd 100644 --- a/jarvis/cogs/core/admin/modcase.py +++ b/jarvis/cogs/core/admin/modcase.py @@ -131,7 +131,7 @@ class CaseCog(Extension): embed.set_author(name=username, icon_url=icon_url) embed.set_footer(text=str(mod_case.user)) - await mod_case.commit() + await mod_case.save() return 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) embeds.append(embed) - await mod_case.commit() + await mod_case.save() return embeds 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: query = [Modlog.guild == ctx.guild.id] if not closed: - query.append(Modlog.open is True) + query.append(Modlog.open == True) if user: query.append(Modlog.user == user.id) - cases = await Modlog.find(*query).sort(+Modlog.created_at).to_list() 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) @check(admin_or_permissions(Permissions.BAN_MEMBERS)) 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: await ctx.send(f"Case already open with ID `{case.nanoid}`", ephemeral=True) return diff --git a/jarvis/cogs/core/admin/purge.py b/jarvis/cogs/core/admin/purge.py index 793152e..2c2930d 100644 --- a/jarvis/cogs/core/admin/purge.py +++ b/jarvis/cogs/core/admin/purge.py @@ -43,7 +43,7 @@ class PurgeCog(Extension): channel=ctx.channel.id, guild=ctx.guild.id, admin=ctx.author.id, - count=amount, + count_=amount, ).save() @slash_command(name="autopurge", sub_cmd_name="add", sub_cmd_description="Automatically purge messages") diff --git a/jarvis/cogs/core/remindme.py b/jarvis/cogs/core/remindme.py index e52534d..2d43eba 100644 --- a/jarvis/cogs/core/remindme.py +++ b/jarvis/cogs/core/remindme.py @@ -138,7 +138,7 @@ class RemindmeCog(Extension): active=True, ) - await r.commit() + await r.save() embed = build_embed( title="Reminder Set", @@ -204,7 +204,7 @@ class RemindmeCog(Extension): @reminders.subcommand(sub_cmd_name="list", sub_cmd_description="List reminders") 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: await ctx.send("You have no reminders set.", ephemeral=True) return diff --git a/jarvis/cogs/extra/tags.py b/jarvis/cogs/extra/tags.py index 516f9fa..3d23660 100644 --- a/jarvis/cogs/extra/tags.py +++ b/jarvis/cogs/extra/tags.py @@ -4,7 +4,13 @@ import re from datetime import datetime, timezone 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.embed import EmbedField from interactions.models.discord.enums import ButtonStyle, Permissions @@ -50,7 +56,7 @@ class TagCog(Extension): await ctx.send(tag.content) @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( title="Create a new tag!", components=[ @@ -316,11 +322,11 @@ class TagCog(Extension): @_edit.autocomplete("name") @_delete.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): tags = await Tag.find(Tag.guild == ctx.guild.id).to_list() 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] await ctx.send(choices=choices) diff --git a/jarvis/cogs/unique/gl.py b/jarvis/cogs/unique/gl.py index 3f832af..1595fa8 100644 --- a/jarvis/cogs/unique/gl.py +++ b/jarvis/cogs/unique/gl.py @@ -436,6 +436,8 @@ class GitlabCog(Extension): def setup(bot: Client) -> None: """Add GitlabCog to JARVIS if Gitlab token exists.""" + bot.logger.warn("GitlabCog is deprecated") + return if load_config().gitlab_token: GitlabCog(bot) else: diff --git a/jarvis/utils/cogs.py b/jarvis/utils/cogs.py index 6c66b55..5a527cb 100644 --- a/jarvis/utils/cogs.py +++ b/jarvis/utils/cogs.py @@ -68,14 +68,14 @@ class ModcaseCog(Extension): return 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: self.logger.warning("Missing action %s, exiting", name) return 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 fields = ( @@ -98,7 +98,7 @@ class ModcaseCog(Extension): except Exception: 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: m_action = Action(action_type=name.lower(), parent=action.id)