diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c180e5b..e102ae9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,10 +21,11 @@ repos: - id: black args: [--line-length=120] - - repo: https://github.com/asottile/reorder_python_imports - rev: v2.6.0 + - repo: https://github.com/pre-commit/mirrors-isort + rev: V5.9.3 hooks: - - id: reorder-python-imports + - id: isort + args: ["--profile", "black"] - repo: https://github.com/pycqa/flake8 rev: 3.9.2 diff --git a/jarvis/cogs/starboard.py b/jarvis/cogs/starboard.py index 12e3063..2d9d0d9 100644 --- a/jarvis/cogs/starboard.py +++ b/jarvis/cogs/starboard.py @@ -2,16 +2,18 @@ from discord import TextChannel from discord.ext import commands from discord.utils import find -from discord_slash import cog_ext -from discord_slash import SlashContext +from discord_slash import SlashContext, cog_ext +from discord_slash.context import MenuContext +from discord_slash.model import ContextMenuType, SlashMessage from discord_slash.utils.manage_commands import create_option -from discord_slash.utils.manage_components import create_actionrow -from discord_slash.utils.manage_components import create_select -from discord_slash.utils.manage_components import create_select_option -from discord_slash.utils.manage_components import wait_for_component +from discord_slash.utils.manage_components import ( + create_actionrow, + create_select, + create_select_option, + wait_for_component, +) -from jarvis.db.models import Star -from jarvis.db.models import Starboard +from jarvis.db.models import Star, Starboard from jarvis.utils import build_embed from jarvis.utils.permissions import admin_or_permissions @@ -110,6 +112,10 @@ class StarboardCog(commands.Cog): else: await ctx.send(f"Starboard not found in {channel.mention}.", hidden=True) + @cog_ext.cog_context_menu(name="Star Message", target=ContextMenuType.MESSAGE) + async def _star_message(self, ctx: MenuContext) -> None: + await self._star_add.invoke(ctx, ctx.target_message) + @cog_ext.cog_subcommand( base="star", name="add", @@ -169,10 +175,10 @@ class StarboardCog(commands.Cog): starboard = channel_list[int(com_ctx.selected_options[0])] - if message.startswith("https://"): - message = message.split("/")[-1] - - message = await channel.fetch_message(int(message)) + if not isinstance(message, SlashMessage): + if message.startswith("https://"): + message = message.split("/")[-1] + message = await channel.fetch_message(message.id) exists = Star.objects( message=message.id, diff --git a/requirements.txt b/requirements.txt index 063efbf..bcc7f22 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -ButtonPaginator>=0.0.3 discord-py>=1.7, <2 -discord-py-slash-command>=2.3.2, <3 +discord-py-slash-command>=3.0.1, <4 +dpy-slash-button-paginator>=1.0.0, <2 GitPython>=3.1, <4 mongoengine>=0.23, <1 opencv-python>=4.5, <5