forked from cheran-senthil/TLE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
75 lines (56 loc) · 1.88 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
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
import logging
import os
from os import environ
from pathlib import Path
import seaborn as sns
from discord.ext import commands
from matplotlib import pyplot as plt
from tle import constants
from tle.util import codeforces_common as cf_common
from tle.util import discord_common
def setup():
# logging
logging.basicConfig(format='{asctime}:{levelname}:{name}:{message}', style='{',
datefmt='%d-%m-%Y %H:%M:%S', level=logging.INFO)
# matplotlib and seaborn
plt.rcParams['figure.figsize'] = 7.0, 3.5
sns.set()
options = {
'axes.edgecolor': '#A0A0C5',
'axes.spines.top': False,
'axes.spines.right': False,
}
sns.set_style('darkgrid', options)
# Make dirs
os.makedirs(constants.FILEDIR, exist_ok=True)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--nodb', action='store_true')
args = parser.parse_args()
token = environ.get('BOT_TOKEN')
if not token:
logging.error('Token required')
return
setup()
bot = commands.Bot(command_prefix=commands.when_mentioned_or(';'))
cogs = [file.stem for file in Path('tle', 'cogs').glob('*.py')]
for extension in cogs:
try:
bot.load_extension(f'tle.cogs.{extension}')
except Exception as e:
logging.error(f'Failed to load extension {extension}: {e})')
logging.info(f'Cogs loaded...')
def no_dm_check(ctx):
if ctx.guild is None:
raise commands.NoPrivateMessage('Private messages not permitted.')
return True
# Restrict bot usage to inside guild channels only.
bot.add_check(no_dm_check)
@bot.event
async def on_ready():
await cf_common.initialize(args.nodb)
bot.add_listener(discord_common.bot_error_handler, name='on_command_error')
bot.run(token)
if __name__ == '__main__':
main()