def generate_compfession_embed(compfession):
    embed = discord.Embed(color=0xf71e1e)
    embed.add_field(name=f"Confession #{compfession.approved_id}",
                    value=compfession.confession)

    created_at = ut.get_uk_time(compfession.created_at).strftime(
        "%Y-%m-%d %H:%M:%S")
    updated_at = ut.get_uk_time(compfession.updated_at).strftime(
        "%Y-%m-%d %H:%M:%S")
    embed.set_footer(text=f"Created {created_at}\n"
                          f"Approved {updated_at}")

    return embed
Esempio n. 2
0
    async def server_info(self, ctx):
        guild = ctx.guild
        guild_roles = " ".join(role.mention if role.name != "@everyone" else ""
                               for role in guild.roles)

        created_at = ut.get_uk_time(
            guild.created_at).strftime("%Y-%m-%d %H:%M:%S")

        embed = (discord.Embed(title=f"{guild.name}",
                               color=discord.Color.blurple()).set_thumbnail(
                                   url=str(guild.icon_url)).add_field(
                                       name="Owner",
                                       value=guild.owner.mention).
                 add_field(name="Created at", value=created_at).add_field(
                     name="Region", value=guild.region).add_field(
                         name="Member Count",
                         value=guild.member_count).add_field(
                             name="Text Channel Count",
                             value=len(guild.text_channels)).add_field(
                                 name="Voice Channel Count",
                                 value=len(guild.voice_channels)).add_field(
                                     name="Available Roles",
                                     value=guild_roles,
                                     inline=False).set_footer(
                                         text=f"Guild ID: {guild.id}"))

        for name, value_getter, inline in self._server_info:
            embed.add_field(name=name,
                            value=value_getter(guild),
                            inline=inline)

        await ctx.send(embed=embed)
Esempio n. 3
0
    async def who_is(self, ctx):
        if not ctx.message.mentions:
            raise commands.errors.UserInputError(message="Please tag a user")

        user = ctx.message.mentions[0]

        join_date = ut.get_uk_time(
            user.joined_at).strftime("%Y-%m-%d %H:%M:%S")

        user_roles = " ".join(role.mention if role.name != "@everyone" else ""
                              for role in user.roles)

        embed = (discord.Embed(
            title=f"{user}",
            description=f"{user.mention}",
            color=discord.Color.blurple()).set_thumbnail(
                url=user.avatar_url).add_field(
                    name="Joined At", value=join_date).add_field(
                        name="Assigned Roles", value=user_roles,
                        inline=False).set_footer(text=f"User ID: {user.id}"))

        for name, value_getter, inline in self._user_info:
            embed.add_field(name=name, value=value_getter(user), inline=inline)

        await ctx.send(embed=embed)
Esempio n. 4
0
    async def who_is(self, ctx):
        if not ctx.message.mentions:
            raise commands.errors.UserInputError(message="Please tag a user")

        discord_user = ctx.message.mentions[0]

        if discord_user.bot:
            return await ctx.send("I can't help you with information "
                                  "about bots.")

        user = User.find(discord_user.id)

        if user is None:
            return await ctx.send("I couldn't find that user in my database, "
                                  "that's not supposed to happen...")

        join_date = ut.get_uk_time(
            discord_user.joined_at).strftime("%Y-%m-%d %H:%M:%S")

        user_roles = " ".join(role.mention if role.name != "@everyone" else ""
                              for role in discord_user.roles)

        user = User.find(discord_user.id)

        message_count = user.messages.count()

        embed = (discord.Embed(
            title=f"{discord_user}",
            description=f"{discord_user.mention}",
            color=discord.Color.blurple()).set_thumbnail(
                url=discord_user.avatar_url).add_field(
                    name="Joined At", value=join_date).add_field(
                        name="Assigned Roles", value=user_roles,
                        inline=False).add_field(
                            name="Message Count",
                            value=message_count).set_footer(
                                text=f"User ID: {discord_user.id}"))

        for name, value_getter, inline in self._user_info:
            embed.add_field(name=name,
                            value=value_getter(discord_user),
                            inline=inline)

        await ctx.send(embed=embed)
Esempio n. 5
0
    async def create_poll_embed(self, title, end_date: datetime.datetime,
                                ended, choices=[]):
        if ended:
            description = (
                "Poll has now ended\n"
                f"React with {DELETE_POLL_EMOJI} to delete the poll")
        else:
            description = ut.get_uk_time(end_date).strftime(
                "Poll ends: %d/%m/%Y %H:%M:%S %Z\n") + (
                f"React with {ADD_CHOICE_EMOJI} to add a choice\n"
                f"React with {DELETE_POLL_EMOJI} to delete the poll\n"
                f"React with {END_POLL_EMOJI} to end the poll, "
                "and finalise the results\n"
                "React with the emoji shown below to vote for that option")

        embed = discord.Embed(title=title, description=description,
                              color=POLL_COLOR)

        return embed
Esempio n. 6
0
 def now(self):
     return ut.get_uk_time()
Esempio n. 7
0
    async def display_poll_search(self,
                                  query_getter,
                                  user: discord.User,
                                  channel,
                                  *,
                                  desc,
                                  page=1):
        def check(reaction, check_user):
            return (str(reaction.emoji) in SHOW_POLLS_EMOJI
                    and check_user == user
                    and reaction.message.id == message.id)

        description = (desc + " on this server\n"
                       f"React with:\n"
                       f"{FIRST_PAGE_EMOJI} to go to the first page\n"
                       f"{PREVIOUS_PAGE_EMOJI} to go to the previous page\n"
                       f"{CLEAR_POLLS_EMOJI} to clear these results\n"
                       f"{NEXT_PAGE_EMOJI} to go to the next page\n"
                       f"{LAST_PAGE_EMOJI} to go to the last page")

        embed = discord.Embed(title="Polls",
                              color=POLL_COLOR,
                              description=description)

        showing = True
        message = None
        while showing:
            query = await query_getter(user)
            polls = query.paginate(POLLS_PER_PAGE, page)

            if not polls.total:
                await channel.send("No polls were found!")
                return False

            for poll in polls:
                field_value = (f"by <@!{poll.creator_id}> - "
                               if ut.is_admin(user) else "")
                field_value += ("Poll has ended" if poll.ended else
                                ut.get_uk_time(poll.end_date).strftime(
                                    "Poll ends: %d/%m/%Y %H:%M:%S %Z"))
                field_value += f"\nPoll ID: {poll.id}"

                embed.add_field(name=f"{poll.title}",
                                value=field_value,
                                inline=False)

            first_poll = polls.per_page * (page - 1) + 1
            last_poll = first_poll + polls.count() - 1
            total = polls.total

            embed.set_footer(
                text=f"Showing polls {first_poll} - {last_poll} of {total}\n"
                f"Page {page} of {polls.last_page}")

            if message is None:
                message = await channel.send(embed=embed)
                for emoji in SHOW_POLLS_EMOJI:
                    await message.add_reaction(emoji)
            else:
                await message.edit(embed=embed)

            try:
                reaction, _ = await self.bot.wait_for('reaction_add',
                                                      check=check,
                                                      timeout=60.0)
            except asyncio.TimeoutError:
                await message.delete()
                break

            emoji = reaction.emoji
            if emoji == CLEAR_POLLS_EMOJI:
                await message.delete()
                break

            if emoji == FIRST_PAGE_EMOJI:
                page = 1
            elif emoji == PREVIOUS_PAGE_EMOJI:
                page = (page - 2) % polls.last_page + 1
            elif emoji == NEXT_PAGE_EMOJI:
                page = page % polls.last_page + 1
            elif emoji == LAST_PAGE_EMOJI:
                page = polls.last_page

            await reaction.remove(user)

        return True