-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
81 lines (66 loc) · 2.6 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import discord
from discord.ext import commands
import os
import asyncio
from initializers.tracing_setup import tracer
from helpers.starfire import Starfire
from db.db import setup_db_connection
from cogs.text_commands import TextCommands
from cogs.voice_events import VoiceEvents
from cogs.steam_commands import SteamCommands
from cogs.settings import Settings
from cogs.music import Music
from cogs.xp_system import XpSystem
from cogs.poke_quiz import PokeQuiz
from cogs.ai import AI
from initializers.tracing_setup import tracer
from jobs.cache_event_handler import BatchCacheEventHandler
import logging
logging.basicConfig(level=logging.INFO)
from dotenv import load_dotenv
load_dotenv()
bot = commands.Bot(command_prefix='*', intents=discord.Intents.all())
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
if DISCORD_TOKEN is None:
raise ValueError("No DISCORD_TOKEN found in environment variables")
cache_event_handler = BatchCacheEventHandler()
# Local Development
if os.getenv('LOCAL_ENV') == 'true':
if not discord.opus.is_loaded():
discord.opus.load_opus('/opt/homebrew/Cellar/opus/1.4/lib/libopus.dylib')
@bot.event
async def on_ready():
with tracer.start_as_current_span("initial_boot_time", {"type": "boot_time"}):
# Boot up the database connection
session = setup_db_connection()
# Initiate cog objects
await bot.add_cog(TextCommands(bot))
await bot.add_cog(SteamCommands(bot, session, cache_event_handler))
await bot.add_cog(VoiceEvents(bot, session, cache_event_handler))
await bot.add_cog(Settings(bot, bot.get_cog("VoiceEvents"), session))
await bot.add_cog(Music(bot))
await bot.add_cog(XpSystem(bot, session))
await bot.add_cog(PokeQuiz(bot, session, cache_event_handler))
await bot.add_cog(AI(bot))
await bot.tree.sync()
# Start the cache event handler
asyncio.create_task(cache_event_handler.aggregation_scheduler())
print("KT is online")
@bot.event
async def on_command_error(ctx, error):
error_data = {
"data": {
"type": "error",
"environment": os.getenv("ENVIRONMENT"),
"description": str(error),
"command": ctx.command.name if ctx.command else "None",
"guild_id": str(ctx.guild.id) if ctx.guild else "DM",
"user_id": str(ctx.author.id)
}
}
Starfire.log(error_data)
await ctx.send(f"An error occurred: {str(error)}")
@bot.tree.command(name="ping")
async def ping(interaction: discord.Interaction):
await interaction.response.send_message("Pong!")
bot.run(DISCORD_TOKEN)