Beispiel #1
0
 async def send_welcome_banner(self,
                               guild,
                               member,
                               channel: discord.TextChannel = None):
     banner_format = guild.welcome_banner_url.split(".")[-1]
     if banner_format.lower() == "gif" and not guild.is_prime:
         raise exceptions.GuildNotPrime(
             "Click here to get prime to continue using GIF banners.")
     channel = channel or guild.welcome_banner_channel
     options = dict()
     if guild.theme.color:
         options["border_color"] = options["font_color"] = options[
             "avatar_border_color"] = str(guild.theme.color)
     banner_bytes = await self.bot.image_processor.discord.get_welcome_banner(
         guild.welcome_banner_url, str(member.avatar_url), member.name,
         member.discriminator, guild.welcome_banner_text, **options)
     file = discord.File(
         BytesIO(banner_bytes),
         filename=f"{guild.plugin.data.settings.banner_name}.{banner_format}"
     )
     if guild.welcome_message:
         await channel.send(guild.welcome_message.format(
             **MessageTemplateMember(member).__dict__),
                            file=file)
     else:
         await channel.send(file=file)
Beispiel #2
0
    async def set_welcome_banner(
            self,
            ctx,
            banner_url,
            channel: typing.Optional[discord.TextChannel] = None,
            *,
            text):
        """Configure and set server welcome banner.
        You should specify direct URL of the banner template which can be either JPEG or PNG. Prime servers can use
        GIF banner templates. It uses current channel to send welcome banners or any other if specified with custom
        required text.

        """
        channel = channel or ctx.channel
        banner_format = banner_url.split(".")[-1]
        if banner_format not in self.plugin.data.settings.banner_formats:
            return await ctx.send_line(
                "❌    Please use supported image format.")
        if banner_format == "gif" and not ctx.guild_profile.is_prime:
            raise exceptions.GuildNotPrime(
                "Click here to get prime to set GIF banners with all other features."
            )
        banner_size = round(
            (await self.bot.image_processor.utils.fetch_size(banner_url)) /
            1048576, 2)
        banner_max_size = self.plugin.data.settings.banner_max_size
        if banner_size > banner_max_size:
            return await ctx.send_line(
                f"❌    Banner should be less than {banner_max_size} MB in size however size of "
                f"provided banner seems to be of {banner_size} MB.")
        await ctx.guild_profile.set_welcome_banner(banner_url, text,
                                                   channel.id)
        # TODO: Actually try generating test welcome banner.
        await ctx.send_line(f"Welcome banners set for {ctx.guild.name}.",
                            ctx.guild.icon_url)
Beispiel #3
0
    async def add_roles(self,
                        ctx,
                        message: typing.Union[discord.Message, str] = None,
                        stack: typing.Optional[bool] = True,
                        permanent: typing.Optional[bool] = False,
                        *,
                        roles: converters.RoleConvertor):
        """Setup reaction roles over any custom message you wish or you may skip this parameter to let bot post
        a embed displaying list of provided roles.

        The stack parameter determines if these roles can be stacked over member or not. Defaults to True or Yes,
        meaning members can have more than one of these roles. Pass 'no' to restrict and let them have only one
        of these roles.

        The permanent parameter determines if these roles once added, can be auto removed by members or not.
        Defaults to False or No. Meaning, members can remove this role anytime by clicking on the corresponding
        reaction if they already have this role. Specify no if you want to refrain them from automatically
        removing it.

        To use custom message, you can pass its shareable URL which can be obtained by right clicking over your custom
        message and click `Copy Message Link` from the floating menu. If you're using this command in same channel your
        message is present, you can simply pass its message ID.

        """
        # Lookup by “{channel ID}-{message ID}” (retrieved by shift-clicking on “Copy ID”).
        # Lookup by message ID (the message must be in the context channel).
        # Lookup by message URL.
        if len(roles) >= self.plugin.data.reactions.max_roles:
            return await ctx.send_line(f"❌    You can't include anymore roles."
                                       )
        if len(
                ctx.guild_profile.reactions.roles
        ) >= self.plugin.data.reactions.max_messages and not ctx.guild_profile.is_prime:
            raise exceptions.GuildNotPrime(
                "Click to get prime to create more reaction roles with all other features."
            )
        if not await ctx.confirm():
            return
        roles_emotes = list(zip(roles, self.emotes))
        if not isinstance(message, discord.Message):
            message = message or "Reaction Roles"
            embed = ctx.embeds.primary()
            embed.set_author(name=message,
                             icon_url=self.bot.theme.images.diabetes)
            # embed.description = "```css\nReact to the emote corresponding to the role you wish to have.```\n"
            for role, emote in roles_emotes:
                embed.add_field(name=f"{emote}    {role.name}",
                                value=f"`COLOR:` {role.mention}")
            # embed.description += "\n".join([f"{emote} {role.mention}" for role, emote in roles_emotes]) + "\n​"
            embed.set_footer(text=ctx.guild.name, icon_url=ctx.guild.icon_url)
            message = await ctx.send(embed=embed)
        if len(message.reactions) < len(roles):
            try:
                await message.clear_reactions()
            except discord.Forbidden:
                return await ctx.send_line(
                    f"❌    The reactions on messages is less than roles you want to use."
                )
            else:
                for _, emote in roles_emotes:
                    await message.add_reaction(emote)
        else:
            for _, reaction in zip(roles, message.reactions):
                await message.add_reaction(reaction.emoji)
        await ctx.guild_profile.reactions.add_roles(message.id, roles, stack,
                                                    permanent)
        await ctx.send_line(
            f"✅    Provided roles has been set as reaction roles.")