From 1cf5bcca1a3eb538d2011d535594e1b8ad24379c Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 7 Jun 2022 16:36:38 -0500 Subject: [PATCH 1/6] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 274c823..b8f5dc1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "modufur" version = "0.1.0" description = "Modufur Discord Bot" -authors = ["Myned "] +authors = ["Myned "] license = "MIT" [tool.poetry.dependencies] From 5eac25bf1af3e7f1c888dd18e369fa438818a833 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 6 Mar 2023 20:35:58 -0600 Subject: [PATCH 2/6] Add systemd user service file --- modufur.service | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 modufur.service 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 From 693d780fb213fcb8b9431d6dc5591ee46f058991 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 6 Mar 2023 20:36:21 -0600 Subject: [PATCH 3/6] Update dependencies --- README.md | 1 + pyproject.toml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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/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] From 6a0420f8923a64e4eb8111c3eeb9c7495a3d5ed7 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 6 Mar 2023 20:36:53 -0600 Subject: [PATCH 4/6] Fix deprecations --- run.py | 2 +- tools/components.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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): From e6ee4f6da22d4cb2062832ec9af67f3c5a297046 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 6 Mar 2023 20:38:21 -0600 Subject: [PATCH 5/6] Add attachment and ephemeral options --- commands/booru.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/commands/booru.py b/commands/booru.py index d5ac7aa..3c904fd 100644 --- a/commands/booru.py +++ b/commands/booru.py @@ -11,26 +11,36 @@ 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 @@ -86,9 +96,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 +109,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 +143,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): From 1b972ec85651d42942b07816b9f19aa19e916b0d Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 6 Mar 2023 20:39:11 -0600 Subject: [PATCH 6/6] Change symantics --- commands/booru.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/commands/booru.py b/commands/booru.py index 3c904fd..2ca60d8 100644 --- a/commands/booru.py +++ b/commands/booru.py @@ -47,10 +47,7 @@ async def reverse(context): 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, )