messy marvin

 avatar
hisoka
python
2 years ago
3.5 kB
12
Indexable
import asyncio
import sqlite3
import contextlib
import json
import logging
import os
import platform
import random
import string
import time
import traceback
from pathlib import Path
import pathlib

import discord
from colorama import Back, Fore, Style
from discord import app_commands, ui
from discord.ext import commands

import settings

logger = settings.logging.getLogger("bot")


def run():
    class PersistentViewBot(commands.Bot):
        def __init__(self):
            super().__init__(
                command_prefix="-",
                intents=discord.Intents().all(),
                activity=discord.Activity(
                    type=discord.ActivityType.listening, name="xxx"
                ),
                status=discord.Status.do_not_disturb,
            )

        # VERIFY BUTTON WILL ALWAYS BE ACTIVE
        async def setup_hook(self) -> None:
            self.add_view(VerifyButton())

    bot = PersistentViewBot()

    @bot.event
    async def on_ready():
        global verify_config
        global verify_channel
        global verify_role
        global verify_guild
        prfx = (
            Fore.BLUE
            + time.strftime("%H:%M:%S PST", time.localtime())
            + Back.RESET
            + Fore.WHITE
            + Style.BRIGHT
        )
        print(f"{Fore.WHITE} --------------------------------------------------- ")
        print(f"{prfx} Loading config... ")

        # db = sqlite3.connect("blank.sqlite")
        # cursor = db.cursor()
        # cursor.execute("CREATE TABLE IF NOT EXISTS")

        # LOAD COGS
        # for cog_file in settings.COGS_DIR.glob("*.py"):
        #     if cog_file != "__init__.py":
        #         await bot.load_extension(f"cogs.{cog_file.name[:-3]}")

        for filepath in Path("./cogs").glob("**/*.py"):
            cog_name = Path(filepath).stem
            try:
                await bot.load_extension(f"cogs.{cog_name}")
            except:
                print(f"Error loading cog {cog_name}")

        # LOAD COMMANDS
        for cmd_file in settings.CMDS_DIR.glob("*.py"):
            if cmd_file.name != "__init__.py":
                await bot.load_extension(f"cmds.{cmd_file.name[:-3]}")

        synced = await bot.tree.sync()

        try:
            verify_config = json.loads(open("verify_config.json", "r").read())
        except Exception:
            print(f"{prfx} No config found! Run -setup in your server!")
        else:
            verify_guild = bot.get_guild(verify_config["guild"])
            verify_channel = bot.get_channel(verify_config["channel"])
            verify_role = verify_guild.get_role(verify_config["role"])
            print(f"{prfx} Config loaded! ")

        print(f"{prfx} Discord Version {Fore.LIGHTYELLOW_EX}{discord.__version__}")
        print(
            f"{prfx} Python Version {Fore.LIGHTYELLOW_EX}{str(platform.python_version())}"
        )
        print(f"{prfx} Synced {Fore.LIGHTYELLOW_EX}{len(synced)} Slash Command(s)")
        print(
            f"{prfx} Logged in as {Fore.LIGHTMAGENTA_EX}{bot.user}{Fore.WHITE} | {Fore.LIGHTRED_EX}(ID: #{bot.user.id})"
        )
        print(f"{prfx}{Fore.GREEN} Bot is ready to go!")
        print(f"{Fore.WHITE} --------------------------------------------------- ")

    bot.run(settings.DISCORD_TOKEN, root_logger=True)


if __name__ == "__main__":
    run()
Editor is loading...