mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 13:02:38 +00:00
Merge branch 'dev'
This commit is contained in:
commit
4053698d2a
6 changed files with 44 additions and 20 deletions
|
@ -87,4 +87,5 @@ You can send links uploaded elsewhere instead.
|
||||||
[hikari](https://github.com/hikari-py/hikari)\
|
[hikari](https://github.com/hikari-py/hikari)\
|
||||||
[hikari-lightbulb](https://github.com/tandemdude/hikari-lightbulb)\
|
[hikari-lightbulb](https://github.com/tandemdude/hikari-lightbulb)\
|
||||||
[hikari-miru](https://github.com/HyperGH/hikari-miru)\
|
[hikari-miru](https://github.com/HyperGH/hikari-miru)\
|
||||||
|
[songbird-py](https://github.com/magpie-dev/Songbird-Py)\
|
||||||
[pysaucenao](https://github.com/FujiMakoto/pysaucenao)
|
[pysaucenao](https://github.com/FujiMakoto/pysaucenao)
|
||||||
|
|
|
@ -11,36 +11,43 @@ extractor = urlextract.URLExtract()
|
||||||
|
|
||||||
|
|
||||||
@plugin.command
|
@plugin.command
|
||||||
# @lightbulb.option('attachment', 'Attachment(s) to reverse')
|
@lightbulb.option(
|
||||||
@lightbulb.option("url", "URL(s) to reverse, separated by space")
|
"ephemeral",
|
||||||
@lightbulb.command("reverse", "Reverse image search using SauceNAO & Kheina", ephemeral=True)
|
"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)
|
@lightbulb.implements(lightbulb.SlashCommand, lightbulb.MessageCommand)
|
||||||
async def reverse(context):
|
async def reverse(context):
|
||||||
match context:
|
match context:
|
||||||
case lightbulb.SlashContext():
|
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:
|
if not urls:
|
||||||
await context.respond("***Invalid URL(s)***")
|
await context.respond("***Invalid URL(s)***", flags=hikari.MessageFlag.EPHEMERAL)
|
||||||
return
|
return
|
||||||
|
|
||||||
await _reverse(context, urls)
|
await _reverse(context, urls, ephemeral=context.options.ephemeral)
|
||||||
case lightbulb.MessageContext():
|
case lightbulb.MessageContext():
|
||||||
urls = extractor.find_urls(context.options.target.content or "", only_unique=True, with_schema_only=True)
|
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]
|
urls += [attachment.url for attachment in context.options.target.attachments if attachment.url not in urls]
|
||||||
|
|
||||||
if not urls:
|
if not urls:
|
||||||
await context.respond("***No images found***")
|
await context.respond("***No images found***", flags=hikari.MessageFlag.EPHEMERAL)
|
||||||
return
|
return
|
||||||
|
|
||||||
selector = None
|
selector = None
|
||||||
|
|
||||||
if len(urls) > 1:
|
if len(urls) > 1:
|
||||||
selector = components.Selector(
|
selector = components.Selector(
|
||||||
pages=[
|
pages=[f"**Select images to search: `{urls.index(url) + 1}/{len(urls)}`**\n{url}" for url in urls],
|
||||||
f"**Select potential images to search: `{urls.index(url) + 1}/{len(urls)}`**\n{url}"
|
|
||||||
for url in urls
|
|
||||||
],
|
|
||||||
buttons=[components.Back(), components.Forward(), components.Select(), components.Confirm()],
|
buttons=[components.Back(), components.Forward(), components.Select(), components.Confirm()],
|
||||||
urls=urls,
|
urls=urls,
|
||||||
)
|
)
|
||||||
|
@ -86,9 +93,12 @@ async def on_reverse_error(event):
|
||||||
|
|
||||||
|
|
||||||
# Reverse images and respond
|
# Reverse images and respond
|
||||||
async def _reverse(context, urls, *, selector=None):
|
async def _reverse(context, urls, *, selector=None, ephemeral=True):
|
||||||
if not selector:
|
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)
|
matches = await scraper.reverse(urls)
|
||||||
|
|
||||||
|
@ -96,7 +106,7 @@ async def _reverse(context, urls, *, selector=None):
|
||||||
if selector:
|
if selector:
|
||||||
await context.interaction.edit_initial_response("***No matches found***", components=None)
|
await context.interaction.edit_initial_response("***No matches found***", components=None)
|
||||||
else:
|
else:
|
||||||
await context.respond("***No matches found***")
|
await context.respond("***No matches found***", flags=hikari.MessageFlag.EPHEMERAL)
|
||||||
return
|
return
|
||||||
|
|
||||||
pages = [
|
pages = [
|
||||||
|
@ -130,7 +140,9 @@ async def _reverse(context, urls, *, selector=None):
|
||||||
else:
|
else:
|
||||||
await context.interaction.edit_initial_response(pages[0], components=None)
|
await context.interaction.edit_initial_response(pages[0], components=None)
|
||||||
else:
|
else:
|
||||||
await context.respond(pages[0])
|
await context.respond(
|
||||||
|
pages[0], flags=hikari.MessageFlag.EPHEMERAL if ephemeral else hikari.MessageFlag.NONE
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load(bot):
|
def load(bot):
|
||||||
|
|
11
modufur.service
Normal file
11
modufur.service
Normal file
|
@ -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
|
|
@ -6,20 +6,20 @@ authors = ["Myned <dev@myned.dev>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "~3.10"
|
python = ">=3.10,<3.12"
|
||||||
toml = "*"
|
toml = "*"
|
||||||
uvloop = "*"
|
uvloop = "*"
|
||||||
aiohttp = "*"
|
aiohttp = "*"
|
||||||
urlextract = "*"
|
urlextract = "*"
|
||||||
tldextract = "*"
|
tldextract = "*"
|
||||||
hikari = {extras = ["speedups"], version = "*"}
|
hikari = {extras = ["speedups"], version = "*"}
|
||||||
hikari-lightbulb = {git = "https://github.com/tandemdude/hikari-lightbulb.git", rev = "development"}
|
hikari-lightbulb = "*"
|
||||||
hikari-miru = "*"
|
hikari-miru = "*"
|
||||||
songbird-py = "*"
|
songbird-py = "*"
|
||||||
youtube-search-python = "*"
|
youtube-search-python = "*"
|
||||||
pysaucenao = {git = "https://github.com/FujiMakoto/pysaucenao.git"}
|
pysaucenao = {git = "https://github.com/FujiMakoto/pysaucenao.git"}
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
black = "*"
|
black = "*"
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
|
|
2
run.py
2
run.py
|
@ -44,6 +44,6 @@ async def on_error(event):
|
||||||
raise event.exception
|
raise event.exception
|
||||||
|
|
||||||
|
|
||||||
miru.load(bot)
|
miru.install(bot)
|
||||||
bot.load_extensions_from("tools", "commands")
|
bot.load_extensions_from("tools", "commands")
|
||||||
bot.run(activity=hikari.Activity(name=c.config["activity"], type=c.ACTIVITY) if c.config["activity"] else None)
|
bot.run(activity=hikari.Activity(name=c.config["activity"], type=c.ACTIVITY) if c.config["activity"] else None)
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Selector(nav.NavigatorView):
|
||||||
|
|
||||||
await interaction.edit_initial_response(**payload)
|
await interaction.edit_initial_response(**payload)
|
||||||
|
|
||||||
self.start(await interaction.fetch_initial_response())
|
await self.start(await interaction.fetch_initial_response())
|
||||||
|
|
||||||
|
|
||||||
def load(bot):
|
def load(bot):
|
||||||
|
|
Loading…
Reference in a new issue