コード例 #1
0
    async def on_role_update(self, before, after: discord.Role):
        log.info('Role:{before} {after} updated in guild: {guild}',
                 before=serializers.log_role(before),
                 after=serializers.log_role(after),
                 guild=serializers.log_guild(after.guild))

        await self.bot.role_route.edit_role(after.id, after.name, after.permissions.administrator, raise_on_error=True)
コード例 #2
0
    async def on_user_removed(self, user) -> None:
        log.info('"{user}" has left guild "{guild}"',
                 user=serializers.log_user(user),
                 guild=serializers.log_guild(user.guild))

        await self.bot.user_route.remove_user_guild(user.id, user.guild.id)

        await self.notify_user_remove(user)
コード例 #3
0
    async def log_invoked_commands(self, ctx: commands.Context):

        log.info('Command "{command}" invoked in guild:{guild} by user:{user}',
                 command=ctx.command.name,
                 guild=serializers.log_guild(ctx.guild),
                 user=serializers.log_user(ctx.author))

        await self.bot.commands_route.add_command_invocation(
            ctx.command.name, ctx.guild.id, ctx.channel.id, ctx.author.id)
コード例 #4
0
    async def on_guild_leave(self, guild) -> None:
        log.info('Bot removed from {guild}',
                 guild=serializers.log_guild(guild))

        await self.bot.messenger.publish(
            Events.on_broadcast_designated_channel,
            OwnerDesignatedChannels.server_join_log,
            f'Bot removed from {guild.name}: {guild.id}')

        await self.bot.guild_route.leave_guild(guild.id)
コード例 #5
0
ファイル: tag_service.py プロジェクト: Exper1mental/ClemBot
    async def on_guild_message_received(self,
                                        message: discord.Message) -> None:

        tags_content = []
        tag_found = False
        pattern = re.compile(f'(^|\\s)[{TAG_PREFIX}](\\w+)')
        for match in set(i[1] for i in pattern.findall(message.content)):
            tag = await self.bot.tag_route.get_tag(message.guild.id, match)

            if not tag:
                continue

            tag_found = True

            tags_content.append(tag.content)

            await self.bot.tag_route.add_tag_use(message.guild.id, match,
                                                 message.channel.id,
                                                 message.author.id)

            log.info('Tag "{match}" invoked in guild: {guild} by: {author}',
                     match=match,
                     guild=serializers.log_guild(message.author.guild),
                     author=serializers.log_user(message.author))

        if not tag_found:
            return

        tag_str = '\n-------\n'.join(tags_content)
        pages = []

        # If length of all tags is greater than the threshold, sends it to the paginate service, otherwise sends as a normal message
        if len(tags_content) > 1:
            for chunk in self.chunk_iterable(tag_str, TAG_PAGINATE_THRESHOLD):
                pages.append(chunk)

        if len(pages) > 1:
            await self.bot.messenger.publish(Events.on_set_pageable_text,
                                             embed_name='Tags Contents',
                                             field_title='Contents',
                                             pages=pages,
                                             author=message.author,
                                             channel=message.channel)

        msg = await message.channel.send(tag_str)
        await self.bot.messenger.publish(Events.on_set_deletable,
                                         msg=msg,
                                         author=message.author,
                                         timeout=60)
コード例 #6
0
    async def on_user_joined(self, user: discord.Member) -> None:
        log.info('"{member}" has joined guild "{guild}"',
                 member=serializers.log_user(user),
                 guild=serializers.log_guild(user.guild))

        db_user = await self.bot.user_route.get_user(user.id)
        if not db_user:
            await self.bot.user_route.create_user(user.id, user.name)

        await self.bot.user_route.add_user_guild(user.id,
                                                 user.guild.id,
                                                 raise_on_error=True)

        await self.bot.user_route.update_roles(user.id,
                                               [r.id for r in user.roles])

        await self.notify_user_join(user)
コード例 #7
0
    async def thread_join(self, thread: discord.Thread):

        # This event fires whenever the bot joins a thread and when a thread is created
        # Check if the thread already exists in the db and if it does do nothing else
        if await self.bot.thread_route.get_thread(thread.id):
            return

        log.info(
            'New thread joined {thread_name}:{thread_id} in guild: {guild}',
            thread_name=thread.name,
            thread_id=thread.id,
            guild=serializers.log_guild(thread.guild))

        await self.bot.thread_route.create_thread(thread.id,
                                                  thread.name,
                                                  thread.guild.id,
                                                  thread.parent_id,
                                                  raise_on_error=True)
コード例 #8
0
    async def on_guild_message_received(self,
                                        message: discord.Message) -> None:

        log.info(
            'Message from {author}: "{content}" Guild {guild} Channel: {channel}',
            author=serializers.log_user(message.author),
            content=message.content,
            guild=serializers.log_guild(message.guild),
            channel=serializers.log_channel(message.channel))

        # Check if the message is a discord message link and check if this server has
        # Enabled embed message links
        await self.handle_message_links(message)

        # Primary entry point for handling commands
        await self.bot.process_commands(message)

        if not message.content:
            return

        await self.batch_send_message(message)
コード例 #9
0
    async def channel_delete(self, channel):
        log.info('Channel deleted {channel} in guild: {guild}',
                 channel=serializers.log_channel(channel),
                 guild=serializers.log_guild(channel.guild))

        await self.bot.channel_route.remove_channel(channel.id, raise_on_error=True)
コード例 #10
0
    async def channel_create(self, channel):
        log.info('Channel created {channel} in guild: {guild}',
                 channel=serializers.log_channel(channel),
                 guild=serializers.log_guild(channel.guild))

        await self.bot.channel_route.create_channel(channel.id, channel.name, channel.guild.id, raise_on_error=True)
コード例 #11
0
    async def on_role_delete(self, role):
        log.info('Role: {role} deleted in guild: {guild}',
                 role=serializers.log_role(role),
                 guild=serializers.log_guild(role.guild))

        await self.bot.role_route.remove_role(role.id, raise_on_error=True)