2025-02-13 14:51:35 -05:00
|
|
|
#!/usr/bin/env python3.12
|
|
|
|
# pylint: disable=bare-except, invalid-name, import-outside-toplevel
|
|
|
|
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import importlib
|
2025-02-13 15:48:39 -05:00
|
|
|
from typing import Optional
|
2025-02-13 14:51:35 -05:00
|
|
|
import discord
|
|
|
|
import setproctitle
|
|
|
|
import hypercorn
|
|
|
|
import hypercorn.asyncio
|
|
|
|
from dotenv import load_dotenv
|
2025-02-15 08:36:45 -05:00
|
|
|
from asyncio import Task
|
2025-02-13 14:51:35 -05:00
|
|
|
from discord.ext import bridge, commands
|
|
|
|
from termcolor import colored
|
2025-02-13 15:48:39 -05:00
|
|
|
from constants import OWNERS, BOT_CHANIDS
|
2025-02-13 14:51:35 -05:00
|
|
|
import api
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO,
|
|
|
|
format='%(asctime)s %(message)s',
|
|
|
|
encoding='utf-8')
|
|
|
|
setproctitle.setproctitle('disc-havoc')
|
|
|
|
|
2025-02-13 15:48:39 -05:00
|
|
|
"""Auto Load Cogs"""
|
|
|
|
cogs_list: list[str] = [
|
2025-02-13 14:51:35 -05:00
|
|
|
'misc',
|
|
|
|
'owner',
|
|
|
|
'sing',
|
|
|
|
'meme',
|
|
|
|
'karma',
|
|
|
|
'lovehate',
|
|
|
|
'quote',
|
|
|
|
'radio',
|
|
|
|
]
|
|
|
|
|
|
|
|
bot_activity = discord.CustomActivity(name="I made cookies!")
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
intents = discord.Intents.all()
|
|
|
|
intents.message_content = True
|
|
|
|
|
2025-02-15 08:36:45 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2025-02-13 14:51:35 -05:00
|
|
|
|
2025-02-15 08:36:45 -05:00
|
|
|
for cog in cogs_list:
|
|
|
|
logging.info("Loading: %s", cog)
|
|
|
|
load_method(f'cogs.{cog}')
|
2025-02-13 14:51:35 -05:00
|
|
|
|
2025-02-15 08:36:45 -05:00
|
|
|
importlib.reload(api)
|
|
|
|
from api import API # pylint: disable=unused-import
|
|
|
|
api_config = hypercorn.config.Config()
|
|
|
|
api_config.bind = ["10.10.10.100: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")
|
2025-02-13 14:51:35 -05:00
|
|
|
|
2025-02-15 08:36:45 -05:00
|
|
|
self.fapi_task: Task = self.loop.create_task(hypercorn.asyncio.serve(api_instance.api_app,
|
|
|
|
api_config))
|
2025-02-13 14:51:35 -05:00
|
|
|
|
|
|
|
|
2025-02-15 08:36:45 -05:00
|
|
|
@commands.Cog.listener()
|
|
|
|
async def on_ready(self) -> None:
|
|
|
|
"""Run on Bot Ready"""
|
|
|
|
logging.info("%s online!", self.user)
|
|
|
|
|
|
|
|
|
2025-02-13 14:51:35 -05:00
|
|
|
|
2025-02-13 15:48:39 -05:00
|
|
|
def __init__() -> None:
|
|
|
|
logging.info(colored(f"Log level: {logging.getLevelName(logging.root.level)}",
|
|
|
|
"red", attrs=['reverse']))
|
2025-02-15 08:36:45 -05:00
|
|
|
bot = Havoc()
|
2025-02-13 14:51:35 -05:00
|
|
|
bot.run(os.getenv('TOKEN'))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
__init__()
|