コード例 #1
0
 async def display_profile(self, context,
                           player: typing.Union[discord.Member,
                                                str], player_details):
     embed = discord.Embed(color=self.EMBED_COLOR)
     embed.set_author(
         name=player_details['name'] + (f" [{player_details['clan_tag']}]"
                                        if player_details['clan'] else ""),
         url=
         f"https://worldoftanks.eu/fr/community/accounts/{player_details['id']}/",
         icon_url=player.avatar_url
         if isinstance(player, discord.Member) else '')
     embed.add_field(name="Identifiant", value=player_details['id'])
     embed.add_field(name="Création du compte",
                     value=converter.humanize_datetime(
                         datetime.datetime.fromtimestamp(
                             player_details['creation_timestamp'])))
     embed.add_field(name="Dernière bataille",
                     value=converter.humanize_datetime(
                         datetime.datetime.fromtimestamp(
                             player_details['last_battle_timestamp'])))
     embed.add_field(name="Dernière connexion",
                     value=converter.humanize_datetime(
                         datetime.datetime.fromtimestamp(
                             player_details['logout_timestamp'])))
     if player_details['clan']:
         embed.add_field(
             name="Clan",
             value=
             f"[{player_details['clan_name']}](https://eu.wargaming.net/clans/wot/{player_details['clan_id']}/)",
             inline=False)
         embed.add_field(name="Position",
                         value=player_details['clan_position'],
                         inline=False)
         embed.set_thumbnail(url=player_details['clan_emblem_url'])
     await context.send(embed=embed)
コード例 #2
0
ファイル: lottery.py プロジェクト: ingramali/ZBot-1
    async def time(self, context: commands.Context, lottery_id: int,
                   time: converter.to_datetime):
        message, channel, emoji, nb_winners, _, organizer = \
            await self.get_message_env(lottery_id, raise_if_not_found=True)

        if context.author != organizer:
            checker.has_any_mod_role(context, print_error=True)
        if (time - utils.get_current_time()).total_seconds() <= 0:
            argument_size = converter.humanize_datetime(time)
            min_argument_size = converter.humanize_datetime(
                utils.get_current_time())
            raise exceptions.UndersizedArgument(argument_size,
                                                min_argument_size)

        embed = self.build_announce_embed(emoji, nb_winners, organizer, time,
                                          self.guild.roles)
        await message.edit(embed=embed)

        job_id = self.pending_lotteries[message.id]['_id']
        scheduler.reschedule_stored_job(
            job_id, time)  # Also updates the next_run_time in db
        lottery_data = {'next_run_time': converter.to_timestamp(time)}
        self.pending_lotteries[message.id].update(lottery_data)
        await context.send(
            f"Date et heure du tirage au sort d'identifiant `{lottery_id}` changées pour le "
            f"`{converter.humanize_datetime(time)}` : <{message.jump_url}>")
コード例 #3
0
    async def time(
            self, context: commands.Context,
            poll_id: int,
            time: converter.to_datetime
    ):
        message, channel, emoji_list, is_exclusive, required_role_name, _, organizer = \
            await self.get_message_env(poll_id, raise_if_not_found=True)

        if context.author != organizer:
            checker.has_any_mod_role(context, print_error=True)
        if not context.author.permissions_in(channel).send_messages:
            raise exceptions.ForbiddenChannel(channel)
        if (time - utils.get_current_time()).total_seconds() <= 0:
            argument_size = converter.humanize_datetime(time)
            min_argument_size = converter.humanize_datetime(utils.get_current_time())
            raise exceptions.UndersizedArgument(argument_size, min_argument_size)

        embed = self.build_announce_embed(
            message.embeds[0].description, is_exclusive, required_role_name, organizer, time,
            self.guild.roles
        )
        await message.edit(embed=embed)

        job_id = self.pending_polls[message.id]['_id']
        scheduler.reschedule_stored_job(job_id, time)  # Also updates the next_run_time in db
        poll_data = {'next_run_time': converter.to_timestamp(time)}
        self.pending_polls[message.id].update(poll_data)
        await context.send(
            f"Date et heure du sondage d'identifiant `{poll_id}` changées pour le "
            f"`{converter.humanize_datetime(time)}` : <{message.jump_url}>"
        )
コード例 #4
0
ファイル: lottery.py プロジェクト: ingramali/ZBot-1
    async def setup(self,
                    context: commands.Context,
                    announce: str,
                    dest_channel: discord.TextChannel,
                    emoji: typing.Union[discord.Emoji, str],
                    nb_winners: int,
                    time: converter.to_datetime,
                    *,
                    options=""):
        # Check arguments
        if not context.author.permissions_in(dest_channel).send_messages:
            raise exceptions.ForbiddenChannel(dest_channel)
        if isinstance(emoji, str) and emojis.emojis.count(emoji) != 1:
            raise exceptions.ForbiddenEmoji(emoji)
        if nb_winners < 1:
            raise exceptions.UndersizedArgument(nb_winners, 1)
        if (time - utils.get_current_time()).total_seconds() <= 0:
            argument_size = converter.humanize_datetime(time)
            min_argument_size = converter.humanize_datetime(
                utils.get_current_time())
            raise exceptions.UndersizedArgument(argument_size,
                                                min_argument_size)

        # Run command
        organizer = context.author
        do_announce = not utils.is_option_enabled(options, 'no-announce')
        prefixed_announce = utils.make_announce(
            context.guild, announce, do_announce and self.ANNOUNCE_ROLE_NAME)
        embed = self.build_announce_embed(emoji, nb_winners, organizer, time,
                                          self.guild.roles)
        message = await dest_channel.send(prefixed_announce, embed=embed)
        await message.add_reaction(emoji)

        # Register data
        job_id = scheduler.schedule_stored_job(self.JOBSTORE, time,
                                               self.run_lottery, message.id).id
        lottery_data = {
            'lottery_id': self.get_next_lottery_id(),
            'message_id': message.id,
            'channel_id': dest_channel.id,
            'emoji_code': emoji if isinstance(emoji, str) else emoji.id,
            'nb_winners': nb_winners,
            'organizer_id': organizer.id,
        }
        zbot.db.update_job_data(self.JOBSTORE, job_id, lottery_data)
        # Add data managed by scheduler later to avoid updating the database with them
        lottery_data.update({
            '_id': job_id,
            'next_run_time': converter.to_timestamp(time)
        })
        self.pending_lotteries[message.id] = lottery_data

        # Confirm command
        await context.send(
            f"Tirage au sort d'identifiant `{lottery_data['lottery_id']}` programmé : <{message.jump_url}>."
        )
コード例 #5
0
ファイル: admin.py プロジェクト: Itstrike20/ZBot
    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)
コード例 #6
0
 async def display_clan(self, context, clan_details):
     embed = discord.Embed(color=clan_details['color']
                           if clan_details['color'] else self.EMBED_COLOR)
     embed.set_author(
         name=f"[{clan_details['tag']}] {clan_details['name']}",
         url=f"https://eu.wargaming.net/clans/wot/{clan_details['id']}/",
         icon_url=clan_details['emblem_url']
         if clan_details['emblem_url'] else None)
     embed.add_field(name="Identifiant", value=clan_details['id'])
     embed.add_field(
         name="Commandant",
         value=
         f"[{clan_details['leader_name']}](https://worldoftanks.eu/fr/community/accounts/{clan_details['leader_id']}/)"
     )
     embed.add_field(name="Création du clan",
                     value=converter.humanize_datetime(
                         datetime.datetime.fromtimestamp(
                             clan_details['creation_timestamp'])))
     embed.add_field(name="Personnel",
                     value=f"{clan_details['members_count']} membres")
     embed.add_field(
         name="Postulations",
         value="Autorisées" if clan_details['recruiting'] else "Refusées")
     embed.add_field(name="Contact de clan",
                     value=clan_details['contact'].mention
                     if clan_details['contact'] else "Aucun")
     embed.set_thumbnail(url=clan_details['emblem_url'])
     await context.send(embed=embed)
コード例 #7
0
    async def start(
            self, context: commands.Context,
            announce: str,
            description: str,
            dest_channel: discord.TextChannel,
            emoji_list: converter.to_emoji_list,
            time: converter.to_datetime,
            *, options=""
    ):
        # Check arguments
        if not context.author.permissions_in(dest_channel).send_messages:
            raise exceptions.ForbiddenChannel(dest_channel)
        if not emoji_list:
            raise commands.MissingRequiredArgument(context.command.params['emoji_list'])
        for emoji in emoji_list:
            if isinstance(emoji, str) and emojis.emojis.count(emoji) != 1:
                raise exceptions.ForbiddenEmoji(emoji)
        if (time - utils.get_current_time()).total_seconds() <= 0:
            argument_size = converter.humanize_datetime(time)
            min_argument_size = converter.humanize_datetime(utils.get_current_time())
            raise exceptions.UndersizedArgument(argument_size, min_argument_size)
        do_announce = utils.is_option_enabled(options, 'do-announce')
        do_pin = utils.is_option_enabled(options, 'pin')
        if do_announce or do_pin:
            checker.has_any_mod_role(context, print_error=True)
        required_role_name = utils.get_option_value(options, 'role')
        if required_role_name:
            utils.try_get(  # Raise if role does not exist
                self.guild.roles, error=exceptions.UnknownRole(required_role_name),
                name=required_role_name
            )

        # Run command
        is_exclusive = utils.is_option_enabled(options, 'exclusive')
        organizer = context.author
        prefixed_announce = utils.make_announce(
            context.guild, announce, do_announce and self.ANNOUNCE_ROLE_NAME)
        embed = self.build_announce_embed(
            description, is_exclusive, required_role_name, organizer, time, self.guild.roles)
        message = await dest_channel.send(prefixed_announce, embed=embed)
        for emoji in emoji_list:
            await message.add_reaction(emoji)
        if do_pin:
            await message.pin()

        # Register data
        job_id = scheduler.schedule_stored_job(self.JOBSTORE, time, self.close_poll, message.id).id
        poll_data = {
            'poll_id': self.get_next_poll_id(),
            'message_id': message.id,
            'channel_id': dest_channel.id,
            'emoji_codes': list(map(lambda e: e if isinstance(e, str) else e.id, emoji_list)),
            'organizer_id': organizer.id,
            'is_exclusive': is_exclusive,
            'required_role_name': required_role_name,
        }
        zbot.db.update_job_data(self.JOBSTORE, job_id, poll_data)
        # Add data managed by scheduler later to avoid updating the database with them
        poll_data.update({'_id': job_id, 'next_run_time': converter.to_timestamp(time)})
        self.pending_polls[message.id] = poll_data

        # Confirm command
        await context.send(f"Sondage d'identifiant `{poll_data['poll_id']}` programmé : <{message.jump_url}>.")
        await context.send(f"Sondage démarré.")