mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 22:27:28 +00:00
Add comments
This commit is contained in:
parent
41b3577bd8
commit
ab1cd302cc
5 changed files with 13 additions and 0 deletions
|
@ -57,6 +57,7 @@ async def reverse(context):
|
||||||
await _reverse(context, urls, selector=selector)
|
await _reverse(context, urls, selector=selector)
|
||||||
|
|
||||||
|
|
||||||
|
# Listener for reverse exceptions
|
||||||
@reverse.set_error_handler()
|
@reverse.set_error_handler()
|
||||||
async def on_reverse_error(event):
|
async def on_reverse_error(event):
|
||||||
error = None
|
error = None
|
||||||
|
@ -84,6 +85,7 @@ async def on_reverse_error(event):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# Reverse images and respond
|
||||||
async def _reverse(context, urls, *, selector=None):
|
async def _reverse(context, urls, *, selector=None):
|
||||||
if not selector:
|
if not selector:
|
||||||
await context.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE)
|
await context.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE)
|
||||||
|
|
|
@ -2,8 +2,12 @@ import toml
|
||||||
import hikari
|
import hikari
|
||||||
|
|
||||||
|
|
||||||
|
# Hikari activity type
|
||||||
|
# https://www.hikari-py.dev/hikari/presences.html#hikari.presences.ActivityType
|
||||||
ACTIVITY = hikari.ActivityType.LISTENING
|
ACTIVITY = hikari.ActivityType.LISTENING
|
||||||
|
# Global command error response
|
||||||
ERROR = "```❗ An internal error has occurred. This has been reported to my master 🐺```"
|
ERROR = "```❗ An internal error has occurred. This has been reported to my master 🐺```"
|
||||||
|
# Local bot configuration
|
||||||
CONFIG = """\
|
CONFIG = """\
|
||||||
guilds = [] # guild IDs to register commands, empty for global
|
guilds = [] # guild IDs to register commands, empty for global
|
||||||
master = 0 # guild ID to register owner commands
|
master = 0 # guild ID to register owner commands
|
||||||
|
@ -12,9 +16,11 @@ token = "" # bot token
|
||||||
activity = "" # bot status
|
activity = "" # bot status
|
||||||
saucenao = "" # saucenao token
|
saucenao = "" # saucenao token
|
||||||
e621 = "" # e621 token
|
e621 = "" # e621 token
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# Load or create config.toml
|
||||||
try:
|
try:
|
||||||
config = toml.load("config.toml")
|
config = toml.load("config.toml")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -24,6 +30,7 @@ except FileNotFoundError:
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
# Global command error response for owner
|
||||||
def error(event):
|
def error(event):
|
||||||
exception = event.exception.__cause__ or event.exception
|
exception = event.exception.__cause__ or event.exception
|
||||||
|
|
||||||
|
|
1
run.py
1
run.py
|
@ -21,6 +21,7 @@ bot = lightbulb.BotApp(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Listener for global command exceptions
|
||||||
@bot.listen(lightbulb.CommandErrorEvent)
|
@bot.listen(lightbulb.CommandErrorEvent)
|
||||||
async def on_error(event):
|
async def on_error(event):
|
||||||
await bot.application.owner.send(c.error(event))
|
await bot.application.owner.send(c.error(event))
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Select(nav.NavButton):
|
||||||
else:
|
else:
|
||||||
self._button(selected=True)
|
self._button(selected=True)
|
||||||
|
|
||||||
|
# Flip button state
|
||||||
def _button(self, *, selected=False):
|
def _button(self, *, selected=False):
|
||||||
self.style = hikari.ButtonStyle.SUCCESS if selected else hikari.ButtonStyle.DANGER
|
self.style = hikari.ButtonStyle.SUCCESS if selected else hikari.ButtonStyle.DANGER
|
||||||
self.label = "✔" if selected else "✗"
|
self.label = "✔" if selected else "✗"
|
||||||
|
@ -77,6 +78,7 @@ class Selector(nav.NavigatorView):
|
||||||
|
|
||||||
self.timed_out = True
|
self.timed_out = True
|
||||||
|
|
||||||
|
# Resend new navigator as edit of previous
|
||||||
async def send_edit(self, interaction):
|
async def send_edit(self, interaction):
|
||||||
self._inter = interaction
|
self._inter = interaction
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ plugin = lightbulb.Plugin("scraper")
|
||||||
sauce = pysaucenao.SauceNao(api_key=c.config["saucenao"], priority=(29, 40, 41)) # e621 > Fur Affinity > Twitter
|
sauce = pysaucenao.SauceNao(api_key=c.config["saucenao"], priority=(29, 40, 41)) # e621 > Fur Affinity > Twitter
|
||||||
|
|
||||||
|
|
||||||
|
# Return list of matches
|
||||||
async def reverse(urls):
|
async def reverse(urls):
|
||||||
return [await _saucenao(url) or await _kheina(url) for url in urls]
|
return [await _saucenao(url) or await _kheina(url) for url in urls]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue