Beispiel #1
0
Datei: bot.py Projekt: Zedd7/ZBot
 def get_versions_data():
     versions_data = {}
     major, minor, patch = 1, 0, 0
     while not Bot.is_out_of_version_range(major, minor, patch):
         version = '.'.join(str(value) for value in (major, minor, patch))
         if changelog := Bot.get_changelog(version):
             date_iso, description, _ = changelog
             versions_data[version] = {
                 'date': converter.to_datetime(date_iso),
                 'description': description
             }
             patch += 1
         elif patch > 0:
             minor += 1
             patch = 0
Beispiel #2
0
    async def check_recruitments(
            self,
            context,
            after: converter.to_datetime = converter.to_datetime('1970-01-01'),
            limit: int = 100):
        if limit < 1:
            raise exceptions.UndersizedArgument(limit, 1)
        if (utils.get_current_time() - after).total_seconds() <= 0:
            argument_size = converter.humanize_datetime(after)
            max_argument_size = converter.humanize_datetime(
                utils.get_current_time())
            raise exceptions.OversizedArgument(argument_size,
                                               max_argument_size)

        await context.message.add_reaction(self.WORK_IN_PROGRESS_EMOJI)

        recruitment_channel = context.guild.get_channel(
            self.RECRUITMENT_CHANNEL_ID)
        recruitment_announces = await recruitment_channel.history(
            after=after.replace(tzinfo=None),
            limit=limit,
            oldest_first=
            False  # Search in reverse in case the filters limit the results
        ).flatten()
        recruitment_announces.reverse()  # Put back oldest match in first place
        recruitment_announces = list(
            filter(
                lambda a: not checker.
                has_any_mod_role(context, a.author, print_error=False
                                 )  # Ignore moderation messages
                and not a.pinned  # Ignore pinned messages
                and not a.type.name == 'pins_add',  # Ignore pin notifications
                recruitment_announces))

        await self.check_authors_clan_contact_role(context,
                                                   recruitment_announces)
        await self.check_recruitment_announces_uniqueness(
            context, recruitment_announces)
        await self.check_recruitment_announces_length(context,
                                                      recruitment_announces)
        await self.check_recruitment_announces_embeds(context,
                                                      recruitment_announces)
        await self.check_recruitment_announces_timespan(
            context, recruitment_announces)

        await context.message.remove_reaction(self.WORK_IN_PROGRESS_EMOJI,
                                              self.user)
        await context.message.add_reaction(self.WORK_DONE_EMOJI)
Beispiel #3
0
    async def check_recruitments(
            self,
            context,
            after: converter.to_past_datetime = converter.to_datetime(
                '1970-01-01'),
            limit: converter.to_positive_int = 100,
            add_reaction=True):
        add_reaction and await context.message.add_reaction(
            self.WORK_IN_PROGRESS_EMOJI)

        recruitment_channel = self.guild.get_channel(
            self.RECRUITMENT_CHANNEL_ID)
        recruitment_announces = await recruitment_channel.history(
            after=after.replace(tzinfo=None),
            limit=limit,
            oldest_first=
            False  # Search in reverse in case the filters limit the results
        ).flatten()
        recruitment_announces.reverse(
        )  # Reverse again to have oldest match in first place
        recruitment_announces = list(
            filter(
                lambda a: not checker.
                has_any_mod_role(context, a.author, print_error=False
                                 )  # Ignore moderation messages
                and not a.pinned  # Ignore pinned messages
                and not a.type.name == 'pins_add',  # Ignore pin notifications
                recruitment_announces))

        await self.check_authors_clan_contact_role(context,
                                                   recruitment_announces)
        await self.check_recruitment_announces_uniqueness(
            context, recruitment_announces)
        await self.check_recruitment_announces_length(context,
                                                      recruitment_announces)
        await self.check_recruitment_announces_embeds(context,
                                                      recruitment_announces)
        await self.check_recruitment_announces_timespan(
            context, recruitment_channel, recruitment_announces)

        add_reaction and await context.message.remove_reaction(
            self.WORK_IN_PROGRESS_EMOJI, self.user)
        add_reaction and await context.message.add_reaction(
            self.WORK_DONE_EMOJI)
Beispiel #4
0
Datei: bot.py Projekt: Zedd7/ZBot
    async def changelog(self, context, version: str = None):
        current_version = zbot.__version__
        if not version:
            version = current_version
        else:
            result = re.match(r'(\d+)\.(\d+)\.(\d+)', version)
            if not result:
                raise exceptions.MisformattedArgument(
                    version, 'a.b.c (a, b et c valeurs entières)')
            major, minor, patch = (int(value) for value in result.groups()
                                   )  # Cast as int to remove leading zeros
            if self.is_out_of_version_range(major, minor, patch):
                raise exceptions.OversizedArgument(version, current_version)
            version = '.'.join(str(value) for value in (major, minor, patch))

        changelog = self.get_changelog(version)
        bot_display_name = self.get_bot_display_name(self.user, self.guild)
        if not changelog:
            await context.send(
                f"Aucune note de version trouvée pour @{bot_display_name} v{version}"
            )
        else:  # This is only executed if there is a match and if both the date and changes are present
            date_iso, description, raw_changes = changelog
            changes = [
                raw_change.removeprefix('- ')
                for raw_change in raw_changes.split('\n') if raw_change
            ]
            embed = discord.Embed(
                title=f"Notes de version de @{bot_display_name} v{version}",
                description="",
                color=self.EMBED_COLOR)
            embed.add_field(name="Date",
                            value=converter.to_human_format(
                                converter.to_datetime(date_iso)),
                            inline=False)
            description and embed.add_field(
                name="Description", value=description, inline=False)
            embed.add_field(name="Changements",
                            value='\n'.join(
                                [f"• {change}" for change in changes]),
                            inline=False)
            await context.send(embed=embed)
Beispiel #5
0
Datei: bot.py Projekt: Zedd7/ZBot
 async def version(self, context, *, options=''):
     bot_display_name = self.get_bot_display_name(self.user, self.guild)
     if not utils.is_option_enabled(options,
                                    'all'):  # Display current version
         current_version = zbot.__version__
         embed = discord.Embed(
             title=f"Version actuelle de @{bot_display_name}",
             color=self.EMBED_COLOR)
         embed.add_field(name="Numéro", value=f"**{current_version}**")
         if changelog := self.get_changelog(current_version):
             date_iso, description, _ = changelog
             embed.add_field(name="Date",
                             value=converter.to_human_format(
                                 converter.to_datetime(date_iso)))
             embed.add_field(name="Description",
                             value=description,
                             inline=False)
         embed.set_footer(
             text="Utilisez +changelog <version> pour plus d'informations")
         await context.send(embed=embed)