diff --git a/README.md b/README.md index 54f5259..bbab389 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,5 @@ You can send links uploaded elsewhere instead. [hikari](https://github.com/hikari-py/hikari)\ [hikari-lightbulb](https://github.com/tandemdude/hikari-lightbulb)\ [hikari-miru](https://github.com/HyperGH/hikari-miru)\ +[songbird-py](https://github.com/magpie-dev/Songbird-Py)\ [pysaucenao](https://github.com/FujiMakoto/pysaucenao) diff --git a/commands/booru.py b/commands/booru.py index d5ac7aa..2ca60d8 100644 --- a/commands/booru.py +++ b/commands/booru.py @@ -11,36 +11,43 @@ extractor = urlextract.URLExtract() @plugin.command -# @lightbulb.option('attachment', 'Attachment(s) to reverse') -@lightbulb.option("url", "URL(s) to reverse, separated by space") -@lightbulb.command("reverse", "Reverse image search using SauceNAO & Kheina", ephemeral=True) +@lightbulb.option( + "ephemeral", + "Respond ephemerally (only visible to invoker) or in current channel", + type=hikari.OptionType.BOOLEAN, + default=True, +) +@lightbulb.option("attachment", "Attachment to reverse", type=hikari.OptionType.ATTACHMENT, default=None) +@lightbulb.option("url", "URL(s) to reverse, separated by space", default=None) +@lightbulb.command("reverse", "Reverse image search using SauceNAO & Kheina") @lightbulb.implements(lightbulb.SlashCommand, lightbulb.MessageCommand) async def reverse(context): match context: case lightbulb.SlashContext(): - urls = extractor.find_urls(context.options.url or "", only_unique=True, with_schema_only=True) + urls = extractor.find_urls( + f"{context.options.url} {context.options.attachment.url if context.options.attachment else None}", + only_unique=True, + with_schema_only=True, + ) if not urls: - await context.respond("***Invalid URL(s)***") + await context.respond("***Invalid URL(s)***", flags=hikari.MessageFlag.EPHEMERAL) return - await _reverse(context, urls) + await _reverse(context, urls, ephemeral=context.options.ephemeral) case lightbulb.MessageContext(): urls = extractor.find_urls(context.options.target.content or "", only_unique=True, with_schema_only=True) urls += [attachment.url for attachment in context.options.target.attachments if attachment.url not in urls] if not urls: - await context.respond("***No images found***") + await context.respond("***No images found***", flags=hikari.MessageFlag.EPHEMERAL) return selector = None if len(urls) > 1: selector = components.Selector( - pages=[ - f"**Select potential images to search: `{urls.index(url) + 1}/{len(urls)}`**\n{url}" - for url in urls - ], + pages=[f"**Select images to search: `{urls.index(url) + 1}/{len(urls)}`**\n{url}" for url in urls], buttons=[components.Back(), components.Forward(), components.Select(), components.Confirm()], urls=urls, ) @@ -86,9 +93,12 @@ async def on_reverse_error(event): # Reverse images and respond -async def _reverse(context, urls, *, selector=None): +async def _reverse(context, urls, *, selector=None, ephemeral=True): if not selector: - await context.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE) + await context.respond( + hikari.ResponseType.DEFERRED_MESSAGE_CREATE, + flags=hikari.MessageFlag.EPHEMERAL if ephemeral else hikari.MessageFlag.NONE, + ) matches = await scraper.reverse(urls) @@ -96,7 +106,7 @@ async def _reverse(context, urls, *, selector=None): if selector: await context.interaction.edit_initial_response("***No matches found***", components=None) else: - await context.respond("***No matches found***") + await context.respond("***No matches found***", flags=hikari.MessageFlag.EPHEMERAL) return pages = [ @@ -130,7 +140,9 @@ async def _reverse(context, urls, *, selector=None): else: await context.interaction.edit_initial_response(pages[0], components=None) else: - await context.respond(pages[0]) + await context.respond( + pages[0], flags=hikari.MessageFlag.EPHEMERAL if ephemeral else hikari.MessageFlag.NONE + ) def load(bot): diff --git a/modufur.service b/modufur.service new file mode 100644 index 0000000..80ed6c3 --- /dev/null +++ b/modufur.service @@ -0,0 +1,11 @@ +[Unit] +Description=Modufur +Requires=default.target +After=default.target + +[Service] +WorkingDirectory=~/.git/Modufur +ExecStart=poetry run python -OO run.py >&2 + +[Install] +WantedBy=default.target diff --git a/pyproject.toml b/pyproject.toml index b8f5dc1..441a03b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,20 +6,20 @@ authors = ["Myned "] license = "MIT" [tool.poetry.dependencies] -python = "~3.10" +python = ">=3.10,<3.12" toml = "*" uvloop = "*" aiohttp = "*" urlextract = "*" tldextract = "*" hikari = {extras = ["speedups"], version = "*"} -hikari-lightbulb = {git = "https://github.com/tandemdude/hikari-lightbulb.git", rev = "development"} +hikari-lightbulb = "*" hikari-miru = "*" songbird-py = "*" youtube-search-python = "*" pysaucenao = {git = "https://github.com/FujiMakoto/pysaucenao.git"} -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] black = "*" [tool.black] diff --git a/run.py b/run.py index 2ee1ffa..522318c 100644 --- a/run.py +++ b/run.py @@ -44,6 +44,6 @@ async def on_error(event): raise event.exception -miru.load(bot) +miru.install(bot) bot.load_extensions_from("tools", "commands") bot.run(activity=hikari.Activity(name=c.config["activity"], type=c.ACTIVITY) if c.config["activity"] else None) diff --git a/tools/components.py b/tools/components.py index 8f8fac7..0069c6d 100644 --- a/tools/components.py +++ b/tools/components.py @@ -90,7 +90,7 @@ class Selector(nav.NavigatorView): await interaction.edit_initial_response(**payload) - self.start(await interaction.fetch_initial_response()) + await self.start(await interaction.fetch_initial_response()) def load(bot):