2022-02-21 01:10:57 -06:00
|
|
|
import os
|
2022-02-21 14:53:53 -06:00
|
|
|
|
2022-02-21 01:10:57 -06:00
|
|
|
import hikari
|
|
|
|
import lightbulb
|
|
|
|
import miru
|
|
|
|
|
|
|
|
import config as c
|
|
|
|
|
|
|
|
|
|
|
|
# Unix optimizations
|
|
|
|
# https://github.com/hikari-py/hikari#uvloop
|
2022-02-21 14:53:53 -06:00
|
|
|
if os.name != "nt":
|
2022-02-21 01:10:57 -06:00
|
|
|
import uvloop
|
2022-02-21 14:53:53 -06:00
|
|
|
|
2022-02-21 01:10:57 -06:00
|
|
|
uvloop.install()
|
|
|
|
|
2022-02-22 22:16:02 -06:00
|
|
|
bot = lightbulb.BotApp(
|
|
|
|
token=c.config["token"],
|
|
|
|
default_enabled_guilds=c.config["guilds"],
|
2022-03-04 00:56:12 -06:00
|
|
|
help_slash_command=False,
|
2022-02-22 22:16:02 -06:00
|
|
|
)
|
2022-02-21 01:10:57 -06:00
|
|
|
|
|
|
|
|
2022-03-03 23:59:46 -06:00
|
|
|
# Listener for global command exceptions
|
2022-02-21 01:10:57 -06:00
|
|
|
@bot.listen(lightbulb.CommandErrorEvent)
|
|
|
|
async def on_error(event):
|
2022-03-04 13:18:16 -06:00
|
|
|
error = c.ERROR
|
|
|
|
|
2022-03-04 00:02:32 -06:00
|
|
|
match event.exception.__cause__ or event.exception:
|
2022-03-04 13:18:16 -06:00
|
|
|
case lightbulb.BotMissingRequiredPermission():
|
|
|
|
error = f"***Missing required permissions: `{event.exception.missing_perms}`***"
|
|
|
|
case lightbulb.MissingRequiredPermission():
|
|
|
|
error = f"***You are missing required permissions: `{event.exception.missing_perms}`***"
|
2022-03-04 00:02:32 -06:00
|
|
|
case hikari.ForbiddenError():
|
2022-03-04 13:18:16 -06:00
|
|
|
raise event.exception
|
2022-03-04 00:02:32 -06:00
|
|
|
case _:
|
|
|
|
await bot.application.owner.send(c.error(event))
|
|
|
|
|
2022-03-04 13:18:16 -06:00
|
|
|
try:
|
|
|
|
await event.context.respond(error, flags=hikari.MessageFlag.EPHEMERAL)
|
|
|
|
except:
|
|
|
|
await event.context.interaction.edit_initial_response(error, components=None)
|
2022-03-04 00:02:32 -06:00
|
|
|
|
2022-03-04 13:18:16 -06:00
|
|
|
raise event.exception
|
2022-02-21 01:10:57 -06:00
|
|
|
|
|
|
|
|
2023-03-06 20:36:53 -06:00
|
|
|
miru.install(bot)
|
2022-02-21 14:53:53 -06:00
|
|
|
bot.load_extensions_from("tools", "commands")
|
2022-02-23 00:18:54 -06:00
|
|
|
bot.run(activity=hikari.Activity(name=c.config["activity"], type=c.ACTIVITY) if c.config["activity"] else None)
|