-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
65 lines (53 loc) · 2.29 KB
/
Copy pathbot.py
File metadata and controls
65 lines (53 loc) · 2.29 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
import database
load_dotenv()
DB_PATH = os.environ.get("HOMEBASE_DB_PATH", "homebase.db")
intents = discord.Intents.default()
class HomeBaseBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!", intents=intents)
# sqlite3 connections are bound to the thread that created them; this is
# only safe because cogs call self.bot.db synchronously from the same
# event loop thread bot.run() drives. Don't offload db calls via
# asyncio.to_thread without switching to a thread-safe connection.
self.db = database.connect(DB_PATH)
database.init_db(self.db)
async def setup_hook(self):
await self.load_extension("cogs.channels")
await self.load_extension("cogs.birthdays")
await self.load_extension("cogs.vacation")
await self.load_extension("cogs.settings")
await self.load_extension("cogs.core")
await self.load_extension("cogs.expenses")
await self.load_extension("cogs.chores")
await self.load_extension("cogs.finance")
await self.load_extension("cogs.groceries")
await self.load_extension("cogs.leaderboard")
await self.load_extension("cogs.meals")
await self.load_extension("cogs.subscriptions")
await self.load_extension("cogs.wiki")
await self.load_extension("cogs.suggestions")
await self.load_extension("cogs.quotes")
await self.load_extension("cogs.milestones")
await self.load_extension("cogs.events")
await self.load_extension("cogs.homebase")
await self.load_extension("cogs.dictionary")
await self.load_extension("cogs.scheduler")
# GUILD_ID set -> instant sync to that one server (use during development).
# Unset -> global sync, which can take up to ~an hour to appear in Discord.
guild_id = os.environ.get("GUILD_ID")
if guild_id:
guild = discord.Object(id=int(guild_id))
self.tree.copy_global_to(guild=guild)
await self.tree.sync(guild=guild)
else:
await self.tree.sync()
def main():
token = os.environ["DISCORD_TOKEN"]
bot = HomeBaseBot()
bot.run(token)
if __name__ == "__main__":
main()