2023-06-19 14:20:17 +00:00
|
|
|
""" .ENV TEMPLATE
|
|
|
|
TOKEN=
|
|
|
|
OWNER_ID=
|
|
|
|
XP_GAIN=
|
|
|
|
COOLDOWN=
|
|
|
|
CASH_BALANCE_NAME=
|
|
|
|
SPECIAL_BALANCE_NAME=
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
import discord
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
import db.tables
|
|
|
|
import sb_tools.resources
|
2023-06-21 10:19:02 +00:00
|
|
|
from config import json_loader
|
2023-06-22 18:11:48 +00:00
|
|
|
from data.Item import Item
|
2023-06-29 11:35:12 +00:00
|
|
|
from handlers.ReactionHandler import ReactionHandler
|
2023-06-29 11:21:17 +00:00
|
|
|
from handlers.XPHandler import XPHandler
|
2023-06-19 14:20:17 +00:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
load_dotenv('.env')
|
|
|
|
|
2023-06-22 09:52:34 +00:00
|
|
|
# load all json
|
2023-06-21 10:19:02 +00:00
|
|
|
strings = json_loader.load_strings()
|
2023-06-22 09:52:34 +00:00
|
|
|
economy_config = json_loader.load_economy_config()
|
2023-06-21 10:19:02 +00:00
|
|
|
|
2023-06-19 14:20:17 +00:00
|
|
|
sbbot = discord.Bot(
|
|
|
|
owner_id=os.getenv('OWNER_ID'),
|
|
|
|
intents=discord.Intents.all(),
|
|
|
|
activity=discord.Game(f"v{sb_tools.resources.__version__}"),
|
|
|
|
status=discord.Status.do_not_disturb
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-06-29 09:33:00 +00:00
|
|
|
def load_cogs(reload=False):
|
|
|
|
for filename in os.listdir('./modules'):
|
|
|
|
if filename.endswith('.py'):
|
|
|
|
if not reload:
|
|
|
|
sbbot.load_extension(f'modules.{filename[:-3]}')
|
|
|
|
else:
|
|
|
|
sbbot.reload_extension(f'modules.{filename[:-3]}')
|
|
|
|
print(f"Module '{filename}' ready.")
|
|
|
|
|
|
|
|
|
2023-06-19 14:20:17 +00:00
|
|
|
@sbbot.event
|
|
|
|
async def on_ready():
|
|
|
|
# wait until the bot is ready
|
|
|
|
# then sync the sqlite3 database
|
|
|
|
db.tables.sync_database()
|
2023-06-22 18:11:48 +00:00
|
|
|
Item.insert_items()
|
2023-06-19 14:20:17 +00:00
|
|
|
|
2023-06-29 09:33:00 +00:00
|
|
|
# reload all cogs to sync db parameters
|
|
|
|
load_cogs(reload=True)
|
|
|
|
|
2023-06-19 14:20:17 +00:00
|
|
|
"""
|
|
|
|
https://docs.pycord.dev/en/stable/api/events.html#discord.on_ready
|
|
|
|
This function isn't guaranteed to only be called once.
|
|
|
|
Event is called when RESUME request fails.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2023-06-29 11:21:17 +00:00
|
|
|
@sbbot.event
|
|
|
|
async def on_message(message):
|
|
|
|
if message.author.bot:
|
|
|
|
return
|
|
|
|
|
|
|
|
xp_handler = XPHandler()
|
|
|
|
await xp_handler.process_xp(message)
|
|
|
|
|
2023-06-29 11:35:12 +00:00
|
|
|
reaction_handler = ReactionHandler()
|
|
|
|
await reaction_handler.handle_message(message)
|
|
|
|
|
2023-06-29 11:21:17 +00:00
|
|
|
|
2023-06-29 09:33:00 +00:00
|
|
|
load_cogs()
|
2023-06-19 14:20:17 +00:00
|
|
|
sbbot.run(os.getenv('TOKEN'))
|