Пример #1
0
async def start():
    ext_list = utils.get_all_extensions(os.environ.get("DIRECTORY_OF_BOT"))
    for ext in ext_list:
        try:
            bot.load_extension(ext)
        except naff.errors.ExtensionLoadException:
            raise

    await bot.astart(os.environ.get("MAIN_TOKEN"))
Пример #2
0
    async def refresh_extensions(self, ctx):
        def ext_str(list_files):
            exten_list = [f"`{k}`" for k in list_files]
            return ", ".join(exten_list)

        unloaded_files = []
        reloaded_files = []
        loaded_files = []
        not_loaded = []

        ext_files = utils.get_all_extensions(
            os.environ.get("DIRECTORY_OF_FILE"))

        to_unload = [
            e for e in self.bot.extensions.keys()
            if e not in ext_files and e != "cogs.db_handler"
        ]
        for ext in to_unload:
            self.bot.unload_extension(ext)
            unloaded_files.append(ext)

        for ext in ext_files:
            try:
                self.bot.reload_extension(ext)
                reloaded_files.append(ext)
            except commands.ExtensionNotLoaded:
                try:
                    self.bot.load_extension(ext)
                    loaded_files.append(ext)
                except commands.ExtensionNotFound as e:
                    await utils.error_handle(self.bot, e)
                except commands.NoEntryPointError:
                    not_loaded.append(ext)
                except commands.ExtensionFailed as e:
                    await utils.error_handle(self.bot, e)
            except commands.ExtensionNotFound as e:
                await utils.error_handle(self.bot, e)
            except commands.NoEntryPointError:
                not_loaded.append(ext)
            except commands.ExtensionFailed as e:
                await utils.error_handle(self.bot, e)

        msg_content = collections.deque()

        if unloaded_files != []:
            msg_content.append(f"Unloaded: {ext_str(unloaded_files)}")
        if loaded_files != []:
            msg_content.append(f"Loaded: {ext_str(loaded_files)}")
        if reloaded_files != []:
            msg_content.append(f"Reloaded: {ext_str(reloaded_files)}")
        if not_loaded != []:
            msg_content.append(f"Didn't load: {ext_str(not_loaded)}")

        await self.msg_handler(ctx, "\n".join(msg_content))
Пример #3
0
    async def on_ready(self):
        if self.init_load == True:
            self.starboard = {}
            self.config = {}

            self.snipes = {"deletes": {}, "edits": {}}

            self.star_queue = {}
            self.star_lock = False

            image_endings = ("jpg", "jpeg", "png", "gif", "webp")
            self.image_extensions = tuple(
                image_endings)  # no idea why I have to do this

            application = await self.application_info()
            self.owner = application.owner

            self.load_extension("cogs.db_handler")
            while self.config == {}:
                await asyncio.sleep(0.1)

            cogs_list = utils.get_all_extensions(
                os.environ.get("DIRECTORY_OF_FILE"))

            for cog in cogs_list:
                if cog != "cogs.db_handler":
                    try:
                        self.load_extension(cog)
                    except commands.NoEntryPointError:
                        pass

        utcnow = datetime.utcnow()
        time_format = utcnow.strftime("%x %X UTC")

        connect_msg = f"Logged in at `{time_format}`!" if self.init_load == True else f"Reconnected at `{time_format}`!"
        await self.owner.send(connect_msg)

        self.init_load = False

        activity = discord.Activity(name='over a couple of servers',
                                    type=discord.ActivityType.watching)

        try:
            await self.change_presence(activity=activity)
        except websockets.ConnectionClosedOK:
            await utils.msg_to_owner(self, "Reconnecting...")
Пример #4
0
    def custom_setup(self):
        settings_cmd = None

        for cmd in self.get_commands():
            if cmd.name == "settings":
                settings_cmd = cmd

        if settings_cmd is None:
            raise commands.CommandNotFound("Can't find settings command!")

        settings_ext = utils.get_all_extensions(
            os.environ.get("DIRECTORY_OF_FILE"), "cogs/core/settings")
        for setting in settings_ext:
            if setting == "cogs.core.settings.settings":
                continue

            lib = importlib.import_module(setting)
            importlib.reload(lib)
            main = getattr(lib, "main_cmd")

            settings_cmd.add_command(main)