-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.py
62 lines (46 loc) · 1.57 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import asyncio
import logging
import sys
from time import sleep
import asyncpg
from queuebot.bot import Queuebot
from queuebot.config import config_from_file
try:
import uvloop
except ImportError:
pass
else:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
logging.getLogger('discord').setLevel(logging.INFO)
logging.getLogger('queuebot').setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')
handler = logging.FileHandler(filename='queuebot.log', encoding='utf-8', mode='a')
handler.setFormatter(formatter)
stream = logging.StreamHandler(stream=sys.stdout)
stream.setFormatter(formatter)
logging.getLogger().addHandler(handler) # Log everything to queuebot.log.
logging.getLogger().addHandler(stream) # Log everything to stdout.
async def main():
config = config_from_file("config.yaml")
while True:
try:
db = await asyncpg.create_pool(**config.pg_credentials)
except (ConnectionRefusedError, asyncpg.CannotConnectNowError):
logging.getLogger('run').exception('Cannot connect to Postgres, stalling:')
await asyncio.sleep(2)
else:
break
bot = Queuebot(
command_prefix='q!',
fetch_offline_members=False,
guild_subscriptions=False,
max_messages=None,
config=config,
db=db,
)
bot.discover_exts('queuebot/cogs')
bot.load_extension('jishaku')
await bot.start(config.token)
sleep(2) # wait for postgres to start
loop = asyncio.get_event_loop()
loop.run_until_complete(main())