-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
63 lines (48 loc) · 1.36 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import asyncio
import logging
import os
from pathlib import Path
import discord
from aiomysql import Pool
import aiofiles
from discord.ext import commands
from dotenv import load_dotenv
from database import get_pool
load_dotenv()
log = logging.getLogger('BOT-MAIN')
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(
command_prefix=commands.when_mentioned_or(),
intents=intents,
activity=discord.Activity(type=discord.ActivityType.playing, name='Hello World!'),
status=discord.Status.online,
sync_commands=True,
delete_not_existing_commands=True
)
async def init_db():
pool: Pool = await get_pool()
async with aiofiles.open('database/structure.sql') as f:
sql = await f.read()
async with pool.acquire() as connection:
async with connection.cursor() as cursor:
for statement in sql.split(';'):
try:
await cursor.execute(statement)
except Exception as e:
log.warning(e)
continue
pool.close()
await pool.wait_closed()
if __name__ == '__main__':
print('Starting bot...')
print('Loading database...')
asyncio.run(init_db())
print('Loading cogs...')
cogs = [file.stem for file in Path('cogs').glob('**/*.py') if not file.name.startswith('__')]
print(f'Loading {len(cogs)} cogs...')
for cog in cogs:
bot.load_extension(f'cogs.{cog}')
print(f'Loaded cog {cog}')
token = os.getenv('BOT_TOKEN')
bot.run(token)