-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
47 lines (40 loc) · 1.44 KB
/
bot.py
File metadata and controls
47 lines (40 loc) · 1.44 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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
import asqlite
import discord
import logging
import os
import sys
from discord import app_commands
token = os.environ.get("DISCORD_TOKEN") or ""
publish_channel_id = int(os.environ.get("DISCORD_PUBLISH_CHANNEL") or "0")
bot_owner_id = int(os.environ.get("DISCORD_BOT_OWNER") or "-1")
try:
import config
token = getattr(config, "token", token)
publish_channel_id = getattr(config, "publish_channel_id", publish_channel_id)
bot_owner_id = getattr(config, "bot_owner_id", bot_owner_id)
except ImportError:
pass
def check_config():
log = logging.getLogger()
if not token:
log.exception("DISCORD_TOKEN is not set!")
sys.exit(1)
database: asqlite.Connection | None = None
# I don't think I need any intent for this bot, so let's keep it default
client = discord.Client(intents=discord.Intents.default())
tree = app_commands.CommandTree(client)
def database_required(func):
async def wrapper():
if not database:
raise RuntimeError("Database is not yet initialized!")
await func()
return wrapper
def is_me():
def predicate(interaction: discord.Interaction) -> bool:
return interaction.user.id == bot_owner_id
return app_commands.check(predicate)