forked from ddnet/ddnet-discordbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
42 lines (31 loc) · 1.09 KB
/
run.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import asyncio
import logging
from configparser import ConfigParser
import aiohttp
import asyncpg
import uvloop
from bot import DDNet
uvloop.install()
loop = asyncio.get_event_loop()
logging.getLogger('discord').setLevel(logging.INFO)
logging.getLogger('discord.http').setLevel(logging.WARNING)
log = logging.getLogger()
log.setLevel(logging.INFO)
handler = logging.FileHandler('logs/bot.log', 'a', encoding='utf-8')
fmt = logging.Formatter('[%(asctime)s][%(levelname)s][%(name)s]: %(message)s', '%Y-%m-%d %H:%M:%S')
handler.setFormatter(fmt)
log.addHandler(handler)
async def main():
config = ConfigParser()
config.read('config.ini')
try:
pool = await asyncpg.create_pool()
except (ConnectionRefusedError, asyncpg.CannotConnectNowError):
return log.exception('Failed to connect to PostgreSQL, exiting')
session = aiohttp.ClientSession(loop=loop)
bot = DDNet(config=config, pool=pool, session=session)
await bot.start(config.get('AUTH', 'DISCORD'))
if __name__ == '__main__':
loop.run_until_complete(main())