104 lines
2.4 KiB
Python
104 lines
2.4 KiB
Python
import os
|
|
import logging
|
|
import importlib
|
|
from typing import Optional
|
|
import discord
|
|
import setproctitle
|
|
import hypercorn
|
|
import hypercorn.asyncio
|
|
from dotenv import load_dotenv
|
|
from asyncio import Task
|
|
from discord.ext import bridge, commands
|
|
from termcolor import colored
|
|
from constants import OWNERS, BOT_CHANIDS
|
|
import api
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO, format="%(asctime)s %(message)s", encoding="utf-8"
|
|
)
|
|
setproctitle.setproctitle("disc-havoc")
|
|
|
|
"""Auto Load Cogs"""
|
|
cogs_list: list[str] = [
|
|
"misc",
|
|
"owner",
|
|
"sing",
|
|
"meme",
|
|
"karma",
|
|
"lovehate",
|
|
"radio",
|
|
]
|
|
|
|
bot_activity = discord.CustomActivity(name="I made cookies!")
|
|
|
|
load_dotenv()
|
|
|
|
intents = discord.Intents.all()
|
|
intents.message_content = True
|
|
|
|
|
|
class Havoc(bridge.Bot):
|
|
def __init__(self) -> None:
|
|
super().__init__(
|
|
command_prefix=".",
|
|
intents=intents,
|
|
owner_ids=OWNERS,
|
|
activity=bot_activity,
|
|
help_command=commands.MinimalHelpCommand(),
|
|
)
|
|
self.BOT_CHANIDS = BOT_CHANIDS
|
|
self.load_exts()
|
|
|
|
def load_exts(self, initialRun: Optional[bool] = True) -> None:
|
|
"""
|
|
Load Cogs/Extensions
|
|
|
|
Args:
|
|
initialRun (Optional[bool]) default: True
|
|
Returns:
|
|
None
|
|
"""
|
|
load_method = self.load_extension if initialRun else self.reload_extension
|
|
|
|
for cog in cogs_list:
|
|
logging.info("Loading: %s", cog)
|
|
load_method(f"cogs.{cog}")
|
|
|
|
importlib.reload(api)
|
|
from api import API
|
|
|
|
api_config = hypercorn.config.Config()
|
|
api_config.bind = ["127.0.0.1:5992"]
|
|
api_instance = api.API(self)
|
|
try:
|
|
self.fapi_task.cancel()
|
|
except Exception as e:
|
|
logging.debug("Failed to cancel fapi_task: %s", str(e))
|
|
|
|
logging.info("Starting FAPI Task")
|
|
|
|
self.fapi_task: Task = self.loop.create_task(
|
|
hypercorn.asyncio.serve(api_instance.api_app, api_config)
|
|
)
|
|
|
|
@commands.Cog.listener()
|
|
async def on_ready(self) -> None:
|
|
"""Run on Bot Ready"""
|
|
logging.info("%s online!", self.user)
|
|
|
|
|
|
def __init__() -> None:
|
|
logging.info(
|
|
colored(
|
|
f"Log level: {logging.getLevelName(logging.root.level)}",
|
|
"red",
|
|
attrs=["reverse"],
|
|
)
|
|
)
|
|
bot = Havoc()
|
|
bot.run(os.getenv("TOKEN"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
__init__()
|