Пример #1
0
    async def send_header(self, msg: Message) -> None:
        """Sends a header embed with information about the relayed messages to the watch channel."""
        if self.disable_header:
            return

        user_id = msg.author.id

        guild = self.bot.get_guild(GuildConfig.id)
        actor = await get_or_fetch_member(guild,
                                          self.watched_users[user_id]['actor'])
        actor = actor.display_name if actor else self.watched_users[user_id][
            'actor']

        inserted_at = self.watched_users[user_id]['inserted_at']
        time_delta = get_time_delta(inserted_at)

        reason = self.watched_users[user_id]['reason']

        if isinstance(msg.channel, DMChannel):
            # If a watched user DMs the bot there won't be a channel name or jump URL
            # This could technically include a GroupChannel but bot's can't be in those
            message_jump = "via DM"
        else:
            message_jump = f"in [#{msg.channel.name}]({msg.jump_url})"

        footer = f"Added {time_delta} by {actor} | Reason: {reason}"
        embed = Embed(
            description=f"{msg.author.mention} {message_jump}\n\n{footer}")

        await self.webhook_send(embed=embed,
                                username=msg.author.display_name,
                                avatar_url=msg.author.display_avatar.url)
Пример #2
0
    async def _infractions_review(self, member: Member) -> str:
        """
        Formats the review of the nominee's infractions, if any.

        The infractions are listed by type and amount, and it is stated how long ago the last one was issued.
        """
        log.trace(f"Fetching the infraction data for {member.id}'s review")
        infraction_list = await self.bot.api_client.get(
            'bot/infractions/expanded',
            params={
                'user__id': str(member.id),
                'ordering': '-inserted_at'
            })

        log.trace(
            f"{len(infraction_list)} infractions found for {member.id}, formatting review."
        )
        if not infraction_list:
            return "They have no infractions."

        # Count the amount of each type of infraction.
        infr_stats = list(
            Counter(infr["type"] for infr in infraction_list).items())

        # Format into a sentence.
        if len(infr_stats) == 1:
            infr_type, count = infr_stats[0]
            infractions = f"{count} {self._format_infr_name(infr_type, count)}"
        else:  # We already made sure they have infractions.
            infractions = ", ".join(
                f"{count} {self._format_infr_name(infr_type, count)}"
                for infr_type, count in infr_stats[:-1])
            last_infr, last_count = infr_stats[-1]
            infractions += f", and {last_count} {self._format_infr_name(last_infr, last_count)}"

        infractions = f"**{infractions}**"

        # Show when the last one was issued.
        if len(infraction_list) == 1:
            infractions += ", issued "
        else:
            infractions += ", with the last infraction issued "

        # Infractions were ordered by time since insertion descending.
        infractions += get_time_delta(infraction_list[0]['inserted_at'])

        return f"They have {infractions}."