Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (36 loc) · 1.37 KB
/
Copy pathmain.py
File metadata and controls
43 lines (36 loc) · 1.37 KB
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
# Trigger point for the entire program
import os
import discord
from discord.ext import commands, tasks
from dotenv import load_dotenv
from dbs import purge_expired_sessions
from utility import session_scope
# Load environment variables from .env file
load_dotenv()
# Access the value of API_KEY
token = os.environ.get("token")
# intents allows bots to subscribe only to specific events they are interested in receiving.
class MyBot(commands.Bot):
def __init__(self, prefix):
intents = (
discord.Intents.default()
) #this disables message_content so we have to enable it again
intents.message_content = True
super().__init__(command_prefix=prefix, intents=intents)
async def setup_hook(self):
await self.load_extension("challenge")
await self.load_extension("view")
await self.load_extension("tactics")
await self.tree.sync(guild=None)
self.purge_sessions.start()
@tasks.loop(hours=1)
async def purge_sessions(self):
# Puzzles and game reviews that were opened and abandoned would otherwise
# sit in the database forever.
with session_scope() as session:
removed = purge_expired_sessions(session)
if removed:
print(f"Purged {removed} expired session row(s)")
if __name__ == "__main__":
client = MyBot(prefix="")
client.run(token)