2022-02-21 07:10:57 +00:00
|
|
|
import toml
|
2022-02-21 19:39:31 +00:00
|
|
|
import hikari
|
2022-02-21 07:10:57 +00:00
|
|
|
|
2022-02-21 20:53:53 +00:00
|
|
|
|
2022-03-04 05:59:46 +00:00
|
|
|
# Hikari activity type
|
|
|
|
# https://www.hikari-py.dev/hikari/presences.html#hikari.presences.ActivityType
|
2022-02-21 19:39:31 +00:00
|
|
|
ACTIVITY = hikari.ActivityType.LISTENING
|
2022-03-04 05:59:46 +00:00
|
|
|
# Global command error response
|
2022-03-04 05:57:35 +00:00
|
|
|
ERROR = "```❗ An internal error has occurred. This has been reported to my master 🐺```"
|
2022-03-04 05:59:46 +00:00
|
|
|
# Local bot configuration
|
2022-02-21 20:53:53 +00:00
|
|
|
CONFIG = """\
|
2022-02-21 07:10:57 +00:00
|
|
|
guilds = [] # guild IDs to register commands, empty for global
|
2022-03-04 05:54:38 +00:00
|
|
|
master = 0 # guild ID to register owner commands
|
2022-02-21 07:10:57 +00:00
|
|
|
client = 0 # bot application ID
|
|
|
|
token = "" # bot token
|
|
|
|
activity = "" # bot status
|
|
|
|
saucenao = "" # saucenao token
|
|
|
|
e621 = "" # e621 token
|
2022-03-04 05:59:46 +00:00
|
|
|
|
2022-02-21 20:53:53 +00:00
|
|
|
"""
|
2022-02-21 07:10:57 +00:00
|
|
|
|
|
|
|
|
2022-03-04 05:59:46 +00:00
|
|
|
# Load or create config.toml
|
2022-02-21 07:10:57 +00:00
|
|
|
try:
|
2022-02-21 20:53:53 +00:00
|
|
|
config = toml.load("config.toml")
|
2022-02-21 07:10:57 +00:00
|
|
|
except FileNotFoundError:
|
2022-02-21 20:53:53 +00:00
|
|
|
with open("config.toml", "w") as f:
|
2022-02-21 07:10:57 +00:00
|
|
|
f.write(CONFIG)
|
2022-03-04 05:57:35 +00:00
|
|
|
print("config.toml created with default values. Restart when modified")
|
2022-02-21 07:10:57 +00:00
|
|
|
exit()
|
|
|
|
|
|
|
|
|
2022-03-04 05:59:46 +00:00
|
|
|
# Global command error response for owner
|
2022-02-21 07:10:57 +00:00
|
|
|
def error(event):
|
|
|
|
exception = event.exception.__cause__ or event.exception
|
|
|
|
|
2022-02-21 20:53:53 +00:00
|
|
|
return (
|
2022-02-22 23:30:25 +00:00
|
|
|
f"**`{event.context.command.name}` in {event.context.get_channel().mention if event.context.guild_id else 'DMs'}"
|
2022-02-21 20:53:53 +00:00
|
|
|
f"```❗ {type(exception).__name__}: {exception}```**"
|
|
|
|
)
|
2022-03-04 06:06:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Write config to file
|
|
|
|
def dump():
|
|
|
|
with open("config.toml", "w") as file:
|
|
|
|
toml.dump(config, file)
|