-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.py
41 lines (30 loc) · 1.15 KB
/
launcher.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
import os
import asyncio
import aiosqlite
from dotenv import load_dotenv
from utils.bot import Brains, BotDB
load_dotenv()
DEV = os.getenv('DEV_STATE')
TOKEN = os.getenv('TEST_BOT_TOKEN') if DEV else os.getenv('BOT_TOKEN')
async def run_sql_commands(db: aiosqlite.Cursor, db_conn: aiosqlite.Connection):
with open('database/schema.sql', 'r') as schema:
content = schema.read()
sql_commands = content.split(';')
for sql_command in sql_commands:
if sql_command.strip():
await db.execute(sql_command)
await db_conn.commit()
print(f'{len(sql_commands)-1} SQL commands were executed')
async def run_bot():
async with aiosqlite.connect('database/database.db') as db_connection:
async with Brains() as bot:
cursor = await db_connection.cursor()
await run_sql_commands(cursor, db_connection)
bot.dev = DEV
bot.db = BotDB(cursor, db_connection)
bot.remove_command('help')
await bot.start(TOKEN)
def main():
asyncio.run(run_bot())
if __name__ == '__main__':
main()