-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
63 lines (48 loc) · 1.56 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
import glob
import logging
import os
import sys
import discord
import discord.state
from dotenv import load_dotenv
# Allow util folder to be visible
sys.path.append('..')
# Load environment variables from .env file
load_dotenv(verbose=True)
# Allow logging info
logging.basicConfig(level=logging.INFO)
from bot import bot
from riddle import build_riddles
@bot.event
async def on_ready():
'''Procedures upon bot initialization.'''
logging.info('> Bot up and running!')
def _get_activity():
'''Get optional custom status message from env variable.'''
if custom_status := os.getenv('DISCORD_CUSTOM_STATUS'):
return discord.Activity(
type=discord.ActivityType.custom,
name='Custom Status',
state=custom_status,
)
return None
await bot.change_presence(
status=discord.Status.invisible,
activity=_get_activity()
)
# Build riddles dict
await build_riddles()
# Iterate through command modules and automatically load extensions
commands_dir = os.getcwd() + '/commands'
os.chdir(commands_dir)
for path in glob.glob('**/*.py', recursive=True):
if path.endswith('.py'):
name = path.removesuffix('.py').replace('/', '.')
name = f"commands.{name}"
logging.info('Loading extension %s…', name)
await bot.load_extension(name)
logging.info('> All clear.')
if __name__ == '__main__':
# Start bot with secret token
token = os.getenv('DISCORD_TOKEN')
bot.run(token)