From ab1cd302cc30d57f3c16f54b4d50288b8e27f5c6 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Mar 2022 23:59:46 -0600 Subject: [PATCH] Add comments --- commands/booru.py | 2 ++ config.py | 7 +++++++ run.py | 1 + tools/components.py | 2 ++ tools/scraper.py | 1 + 5 files changed, 13 insertions(+) diff --git a/commands/booru.py b/commands/booru.py index f66f107..6facdac 100644 --- a/commands/booru.py +++ b/commands/booru.py @@ -57,6 +57,7 @@ async def reverse(context): await _reverse(context, urls, selector=selector) +# Listener for reverse exceptions @reverse.set_error_handler() async def on_reverse_error(event): error = None @@ -84,6 +85,7 @@ async def on_reverse_error(event): return True +# Reverse images and respond async def _reverse(context, urls, *, selector=None): if not selector: await context.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE) diff --git a/config.py b/config.py index 269b97a..c352201 100644 --- a/config.py +++ b/config.py @@ -2,8 +2,12 @@ import toml import hikari +# Hikari activity type +# https://www.hikari-py.dev/hikari/presences.html#hikari.presences.ActivityType ACTIVITY = hikari.ActivityType.LISTENING +# Global command error response ERROR = "```❗ An internal error has occurred. This has been reported to my master 🐺```" +# Local bot configuration CONFIG = """\ guilds = [] # guild IDs to register commands, empty for global master = 0 # guild ID to register owner commands @@ -12,9 +16,11 @@ token = "" # bot token activity = "" # bot status saucenao = "" # saucenao token e621 = "" # e621 token + """ +# Load or create config.toml try: config = toml.load("config.toml") except FileNotFoundError: @@ -24,6 +30,7 @@ except FileNotFoundError: exit() +# Global command error response for owner def error(event): exception = event.exception.__cause__ or event.exception diff --git a/run.py b/run.py index 92168dc..e484f8f 100644 --- a/run.py +++ b/run.py @@ -21,6 +21,7 @@ bot = lightbulb.BotApp( ) +# Listener for global command exceptions @bot.listen(lightbulb.CommandErrorEvent) async def on_error(event): await bot.application.owner.send(c.error(event)) diff --git a/tools/components.py b/tools/components.py index 9fdbd85..8f8fac7 100644 --- a/tools/components.py +++ b/tools/components.py @@ -49,6 +49,7 @@ class Select(nav.NavButton): else: self._button(selected=True) + # Flip button state def _button(self, *, selected=False): self.style = hikari.ButtonStyle.SUCCESS if selected else hikari.ButtonStyle.DANGER self.label = "✔" if selected else "✗" @@ -77,6 +78,7 @@ class Selector(nav.NavigatorView): self.timed_out = True + # Resend new navigator as edit of previous async def send_edit(self, interaction): self._inter = interaction diff --git a/tools/scraper.py b/tools/scraper.py index 4ea675d..07e25c0 100644 --- a/tools/scraper.py +++ b/tools/scraper.py @@ -10,6 +10,7 @@ plugin = lightbulb.Plugin("scraper") sauce = pysaucenao.SauceNao(api_key=c.config["saucenao"], priority=(29, 40, 41)) # e621 > Fur Affinity > Twitter +# Return list of matches async def reverse(urls): return [await _saucenao(url) or await _kheina(url) for url in urls]