示例#1
0
    async def init_cog(self) -> None:
        """Initialise the help channel system."""
        log.trace(
            "Waiting for the guild to be available before initialisation.")
        await self.bot.wait_until_guild_available()

        log.trace("Initialising the cog.")
        await self.init_categories()
        await _cooldown.check_cooldowns(self.scheduler)

        self.channel_queue = self.create_channel_queue()
        self.name_queue = _name.create_name_queue(
            self.available_category,
            self.in_use_category,
            self.dormant_category,
        )

        log.trace("Moving or rescheduling in-use channels.")
        for channel in _channel.get_category_channels(self.in_use_category):
            await self.move_idle_channel(channel, has_task=False)

        # Prevent the command from being used until ready.
        # The ready event wasn't used because channels could change categories between the time
        # the command is invoked and the cog is ready (e.g. if move_idle_channel wasn't called yet).
        # This may confuse users. So would potentially long delays for the cog to become ready.
        self.close_command.enabled = True

        await self.init_available()
        _stats.report_counts()

        log.info("Cog is ready!")
示例#2
0
文件: _cog.py 项目: Kronifer/bot
    async def move_to_available(self) -> None:
        """Make a channel available."""
        log.trace("Making a channel available.")

        channel = await self.get_available_candidate()
        log.info(f"Making #{channel} ({channel.id}) available.")

        await _message.send_available_message(channel)

        log.trace(
            f"Moving #{channel} ({channel.id}) to the Available category.")

        # Unpin any previously stuck pins
        log.trace(f"Looking for pins stuck in #{channel} ({channel.id}).")
        for message in await channel.pins():
            await _message.pin_wrapper(message.id, channel, pin=False)
            log.debug(
                f"Removed a stuck pin from #{channel} ({channel.id}). ID: {message.id}"
            )

        await _channel.move_to_bottom(
            channel=channel,
            category_id=constants.Categories.help_available,
        )

        # Adding the help channel to the dynamic message, and editing/sending that message.
        self.available_help_channels.add(channel)
        await self.update_available_help_channels()

        _stats.report_counts()
示例#3
0
文件: _cog.py 项目: dolphingarlic/bot
    async def move_to_in_use(self, channel: discord.TextChannel) -> None:
        """Make a channel in-use and schedule it to be made dormant."""
        log.info(f"Moving #{channel} ({channel.id}) to the In Use category.")

        await _channel.move_to_bottom(
            channel=channel,
            category_id=constants.Categories.help_in_use,
        )

        timeout = constants.HelpChannels.idle_minutes_claimant * 60

        log.trace(f"Scheduling #{channel} ({channel.id}) to become dormant in {timeout} sec.")
        self.scheduler.schedule_later(timeout, channel.id, self.move_idle_channel(channel))
        _stats.report_counts()
示例#4
0
    async def move_to_dormant(self, channel: discord.TextChannel) -> None:
        """Make the `channel` dormant."""
        log.info(f"Moving #{channel} ({channel.id}) to the Dormant category.")
        await _channel.move_to_bottom(
            channel=channel,
            category_id=constants.Categories.help_dormant,
        )

        log.trace(f"Sending dormant message for #{channel} ({channel.id}).")
        embed = discord.Embed(description=_message.DORMANT_MSG)
        await channel.send(embed=embed)

        log.trace(f"Pushing #{channel} ({channel.id}) into the channel queue.")
        self.channel_queue.put_nowait(channel)

        _stats.report_counts()
示例#5
0
    async def move_to_available(self) -> None:
        """Make a channel available."""
        log.trace("Making a channel available.")

        channel = await self.get_available_candidate()
        log.info(f"Making #{channel} ({channel.id}) available.")

        await _message.send_available_message(channel)

        log.trace(
            f"Moving #{channel} ({channel.id}) to the Available category.")

        await _channel.move_to_bottom(
            channel=channel,
            category_id=constants.Categories.help_available,
        )

        _stats.report_counts()
示例#6
0
文件: _cog.py 项目: dolphingarlic/bot
    async def move_to_available(self) -> None:
        """Make a channel available."""
        log.trace("Making a channel available.")

        channel = await self.get_available_candidate()
        log.info(f"Making #{channel} ({channel.id}) available.")

        await _message.send_available_message(channel)

        log.trace(f"Moving #{channel} ({channel.id}) to the Available category.")

        await _channel.move_to_bottom(
            channel=channel,
            category_id=constants.Categories.help_available,
        )

        # Adding the help channel to the dynamic message, and editing/sending that message.
        self.available_help_channels.add(channel)
        await self.update_available_help_channels()

        _stats.report_counts()
示例#7
0
文件: _cog.py 项目: Kronifer/bot
    async def init_cog(self) -> None:
        """Initialise the help channel system."""
        log.trace(
            "Waiting for the guild to be available before initialisation.")
        await self.bot.wait_until_guild_available()

        log.trace("Initialising the cog.")
        self.guild = self.bot.get_guild(constants.Guild.id)
        self.cooldown_role = self.guild.get_role(constants.Roles.help_cooldown)

        await self.init_categories()

        self.channel_queue = self.create_channel_queue()
        self.name_queue = _name.create_name_queue(
            self.available_category,
            self.in_use_category,
            self.dormant_category,
        )

        log.trace("Moving or rescheduling in-use channels.")
        for channel in _channel.get_category_channels(self.in_use_category):
            await self.move_idle_channel(channel, has_task=False)

        # Prevent the command from being used until ready.
        # The ready event wasn't used because channels could change categories between the time
        # the command is invoked and the cog is ready (e.g. if move_idle_channel wasn't called yet).
        # This may confuse users. So would potentially long delays for the cog to become ready.
        self.close_command.enabled = True

        # Acquiring the dynamic message ID, if it exists within the cache.
        log.trace("Attempting to fetch How-to-get-help dynamic message ID.")
        self.dynamic_message = await _caches.dynamic_message.get("message_id")

        await self.init_available()
        _stats.report_counts()

        log.info("Cog is ready!")