1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 22:23:13 +00:00
Lumi/Racu.py

72 lines
2 KiB
Python
Raw Normal View History

2023-06-19 14:20:17 +00:00
import os
import discord
2024-04-05 12:05:36 +00:00
import services.Client
import services.GuildConfig
import services.Help
import services.logging_service
2024-04-05 12:14:31 +00:00
import config.parser
2023-06-19 14:20:17 +00:00
2024-04-05 12:05:36 +00:00
_logs = services.logging_service.setup_logger()
2024-02-27 17:23:59 +00:00
2024-03-16 14:05:40 +00:00
2024-04-05 12:05:36 +00:00
async def get_prefix(bot, message):
2024-03-19 07:34:29 +00:00
try:
2024-04-05 12:05:36 +00:00
return services.GuildConfig.GuildConfig.get_prefix(message.guild.id)
2024-03-19 07:34:29 +00:00
except AttributeError:
return "."
2024-03-16 14:05:40 +00:00
2024-04-05 12:05:36 +00:00
client = services.Client.RacuBot(
2024-04-26 10:12:06 +00:00
owner_id=int(os.environ.get('RACU_OWNER_ID')),
command_prefix=get_prefix,
2023-07-02 13:50:21 +00:00
intents=discord.Intents.all(),
2024-03-16 20:08:48 +00:00
status=discord.Status.online,
2024-04-05 12:05:36 +00:00
help_command=services.Help.RacuHelp()
2023-07-02 13:50:21 +00:00
)
2024-04-05 12:05:36 +00:00
def load_modules():
loaded = set()
2023-07-02 13:50:21 +00:00
2024-04-05 12:05:36 +00:00
# Load event listeners (handlers) and command cogs (modules)
for directory in ["handlers", "modules"]:
directory_path = os.path.join(os.getcwd(), directory)
if not os.path.isdir(directory_path):
continue
2023-07-02 13:50:21 +00:00
2024-04-05 12:05:36 +00:00
items = [d for d in os.listdir(directory_path) if os.path.isdir(os.path.join(directory_path, d))] \
if directory == "modules" else [f[:-3] for f in os.listdir(directory_path) if f.endswith('.py')]
2024-03-17 14:18:24 +00:00
2024-04-05 12:05:36 +00:00
for item in items:
if item in loaded:
continue
2024-04-05 12:05:36 +00:00
try:
client.load_extension(f"{directory}.{item}")
loaded.add(item)
2024-04-05 12:14:59 +00:00
_logs.info(f'[{directory.capitalize()}] {item.upper()} loaded.')
2024-04-05 12:05:36 +00:00
except Exception as e:
2024-04-05 12:14:59 +00:00
_logs.error(f'[{directory.capitalize()}] Failed to load {item.upper()}: {e}')
2024-03-17 14:18:24 +00:00
2023-07-02 13:50:21 +00:00
if __name__ == '__main__':
"""
2024-04-06 10:23:40 +00:00
This code is only ran when Racu.py is the primary module,
so NOT when main is imported from a cog. (sys.modules)
2023-07-02 13:50:21 +00:00
"""
2024-04-05 12:05:36 +00:00
_logs.info("RACU IS BOOTING")
_logs.info("\n")
2024-02-27 14:09:59 +00:00
2024-04-05 12:14:31 +00:00
# cache all JSON
[config.parser.JsonCache.read_json(file[:-5]) for file in os.listdir("config/JSON") if file.endswith(".json")]
# load command and listener cogs
2024-03-17 14:18:24 +00:00
load_modules()
2024-02-27 14:09:59 +00:00
# empty line to separate modules from system info in logs
2024-04-05 12:05:36 +00:00
_logs.info("\n")
2024-02-27 17:23:59 +00:00
client.run(os.environ.get('RACU_TOKEN'))