-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
66 lines (51 loc) · 2.08 KB
/
bot.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
import logging
import sys
import pyfiglet
import pytz
from discord.ext import commands
import constants
LOG_FORMAT = '%(levelname)s [%(asctime)s]: %(message)s'
logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)
logging.info('[RSVP Bot] Starting WoW RSVP Bot')
# Startup checks
logging.debug('[RSVP Bot] Running pre-flight')
if not constants.DISCORD_TOKEN or constants.DISCORD_TOKEN == 'inserttokenhere':
# Token unset or blank
logging.fatal('[RSVP Bot] Token is invalid')
logging.fatal('Edit your token in constants.py and run again')
sys.exit(1)
elif not constants.DISCORD_PREFIX:
# No prefix is present
logging.fatal('[RSVP Bot] No prefix is provided')
logging.fatal('Edit your prefix in constants.py and run again')
sys.exit(1)
for x, y in constants.TIMEZONE_ALIASES.items():
if y not in pytz.all_timezones:
# TZ data does not appear to exist
logging.fatal('[RSVP Bot] Timezone alias settings are invalid!')
logging.fatal(f'Bad alias "{x}" for unknown timezone "{y}"')
logging.fatal('Ensure this TZ data is correct. Timezones are case-sensitive')
sys.exit(1)
BOT = commands.Bot(command_prefix=constants.DISCORD_PREFIX)
class RSVPBot(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.ready = False # Prevent ready calling twice
@commands.Cog.listener()
async def on_ready(self):
if not self.ready:
logging.info('[RSVP Bot] Now Ready')
print(pyfiglet.color_to_ansi('CYAN', False) + pyfiglet.figlet_format('RSVP Bot') + '\nCopyright (C) Matthew Cohen 2020' + pyfiglet.color_to_ansi('RESET', False))
self.bot.load_extension('modules.main')
self.ready = True
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.errors.CommandNotFound):
pass # Ignore
else:
raise error
try:
BOT.add_cog(RSVPBot(BOT))
BOT.run(constants.DISCORD_TOKEN)
except KeyboardInterrupt:
logging.info(['[RSVP Bot] Keyboard interrupt detected, shutting down'])