mirror of
https://github.com/insertapp/mmolbbot.git
synced 2025-07-01 14:27:03 +00:00
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
import nextcord
|
|
from nextcord.ext import application_checks, commands
|
|
from nextcord import SlashOption
|
|
from dotenv import load_dotenv
|
|
from random import randint
|
|
import aiohttp
|
|
import aiosqlite as sqlite3
|
|
import traceback
|
|
from urllib.parse import urlparse
|
|
import os
|
|
import logging
|
|
import sys
|
|
|
|
load_dotenv()
|
|
bot = commands.Bot()
|
|
|
|
|
|
|
|
@bot.event
|
|
async def on_ready():
|
|
global db
|
|
global cur
|
|
db = await sqlite3.connect("/data/mmolb.db")
|
|
cur = await db.cursor()
|
|
res = await cur.execute("SELECT name FROM sqlite_master WHERE name='liveupdate'")
|
|
if await res.fetchone() is None:
|
|
await cur.execute("CREATE TABLE liveupdate(serverid INTEGER, userid INTEGER, channelid INTEGER, messageid INTEGER, gameid TEXT, offset INTEGER)")
|
|
await db.commit()
|
|
bot.db = db
|
|
bot.cur = cur
|
|
bot.load_extension('cogs.liveupdate')
|
|
bot.load_extension('cogs.team')
|
|
bot.add_all_application_commands()
|
|
#await bot.sync_all_application_commands()
|
|
|
|
@bot.slash_command(
|
|
name="managecog",
|
|
description="manage cogs",
|
|
guild_ids=[int(os.getenv("OWNER_GUILD"))],
|
|
)
|
|
@application_checks.is_owner()
|
|
async def managecog(interaction: nextcord.Interaction,
|
|
action: str = SlashOption(choices=["load", "unload", "reload","sync"]),
|
|
cog: str = SlashOption(required=False)
|
|
):
|
|
errors = ""
|
|
try:
|
|
if action == "load":
|
|
bot.load_extension(cog)
|
|
elif action == "unload":
|
|
bot.unload_extension(cog)
|
|
elif action == "reload":
|
|
bot.reload_extension(cog)
|
|
elif action == "sync":
|
|
bot.add_all_application_commands()
|
|
await bot.sync_all_application_commands()
|
|
await interaction.response.send_message(f"Done!" + (f"\n{errors}" if errors != "" else ""), ephemeral=True)
|
|
|
|
except Exception as e:
|
|
await interaction.response.send_message(e, ephemeral=True)
|
|
|
|
bot.run(os.getenv("TOKEN")) |