Ejemplo n.º 1
0
    async def config_mute_admins(self, ctx, *, new_status: str):
        """(Able to mute server's admins)
        
        Only the Bot Owner can execute this command.
        
        Example:
        config muteadmin [on | off]
        """

        await ctx.message.channel.trigger_typing()
        if new_status.lower() == "on":
            new_status = "Y"
            color = discord.Color.green()
            msg = "Admins can now be muted: `ON`"
        elif new_status.lower() == "off":
            new_status = "N"
            color = discord.Color.red()
            msg = "Admins can no longer be muted: `OFF`"
        else:
            raise commands.BadArgument(message="BadArgument")

        embed = discord.Embed(description=msg, color=color)
        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if rs[0]["mute_admins"] != str(new_status):
            await serverConfigsSql.update_mute_admins(ctx.guild.id,
                                                      str(new_status))

        await BotUtils.send_embed(self, ctx, embed, False, msg)
Ejemplo n.º 2
0
    async def config_bot_word_reactions(self, ctx, *, new_status: str):
        """(Bot will react to member words)
         
        Example:
        config botreactions [on | off]
        """

        await ctx.message.channel.trigger_typing()
        if new_status.lower() == "on":
            new_status = "Y"
            color = discord.Color.green()
            msg = "Bot Reactions: `ON`"
        elif new_status.lower() == "off":
            new_status = "N"
            color = discord.Color.red()
            msg = "Bot Reactions: `OFF`"
        else:
            raise commands.BadArgument(message="BadArgument")

        embed = discord.Embed(description=msg, color=color)
        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if rs[0]["bot_word_reactions"] != str(new_status):
            await serverConfigsSql.update_bot_word_reactions(
                ctx.guild.id, str(new_status))

        await BotUtils.send_embed(self, ctx, embed, False, msg)
Ejemplo n.º 3
0
        async def on_member_remove(member):
            if bot.user.id == member.id:
                return

            usersSql = UsersSql(self.bot)
            await usersSql.delete_user(member)

            serverConfigsSql = ServerConfigsSql(self.bot)
            rs = await serverConfigsSql.get_server_configs(member.guild.id)
            if len(rs) > 0 and rs[0]["msg_on_leave"] == "Y":
                now = dt.datetime.now()
                embed = discord.Embed(color=discord.Color.red(),
                                      description=str(member))
                embed.set_thumbnail(url=member.avatar_url)
                embed.set_author(name="Left the Server")
                embed.set_footer(text=f"{now.strftime('%c')}")
                channel_to_send_msg = await BotUtils.channel_to_send_msg(
                    bot, member.guild)
                if channel_to_send_msg is not None:
                    try:
                        await channel_to_send_msg.send(embed=embed)
                    except discord.HTTPException:
                        await channel_to_send_msg.send(
                            f"{member.name} Left the Server\n{now.strftime('%c')}"
                        )
Ejemplo n.º 4
0
    async def config_anonymous_pool(self, ctx, *, new_status: str):
        """(Hide the author's name from the pool command)
         
        Example:
        config anonymouspool [on | off]
        """

        await ctx.message.channel.trigger_typing()
        if new_status.lower() == "on":
            new_status = "Y"
            color = discord.Color.green()
            msg = "Anonymous pools: `ON`"
        elif new_status.lower() == "off":
            new_status = "N"
            color = discord.Color.red()
            msg = "Anonymous pools: `OFF`"
        else:
            raise commands.BadArgument(message="BadArgument")

        embed = discord.Embed(description=msg, color=color)
        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if rs[0]["anonymous_pool"] != str(new_status):
            await serverConfigsSql.update_anonymous_pool(
                ctx.guild.id, str(new_status))

        await BotUtils.send_embed(self, ctx, embed, False, msg)
Ejemplo n.º 5
0
    async def config_mention_everyone_pool_cmd(self, ctx, *, new_status: str):
        """(Mention everyone when the pool command is used)
         
        Example:
        config mentionpool [on | off]
        """

        await ctx.message.channel.trigger_typing()
        if new_status.lower() == "on":
            new_status = "Y"
            color = discord.Color.green()
            msg = "Mention everyone when the pool command is used is now: `ON`"
        elif new_status.lower() == "off":
            new_status = "N"
            color = discord.Color.red()
            msg = "Mention everyone when the pool command is used is now: `OFF`"
        else:
            raise commands.BadArgument(message="BadArgument")

        embed = discord.Embed(description=msg, color=color)
        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if rs[0]["mention_everyone_pool_cmd"] != str(new_status):
            await serverConfigsSql.update_mention_everyone_pool_cmd(
                ctx.guild.id, str(new_status))

        await BotUtils.send_embed(self, ctx, embed, False, msg)
Ejemplo n.º 6
0
    async def config_member_message(self, ctx, *, new_status: str):
        """(Show message when a member make changes on his/her profile)
         
        Example:
        config membermessage [on | off]
        """

        await ctx.message.channel.trigger_typing()
        if new_status.lower() == "on":
            new_status = "Y"
            color = discord.Color.green()
            msg = "Display a message when someone changes profile is now: `ON`"
        elif new_status.lower() == "off":
            new_status = "N"
            color = discord.Color.red()
            msg = "Display a message when someone changes profile is now: `OFF`"
        else:
            raise commands.BadArgument(message="BadArgument")

        embed = discord.Embed(description=msg, color=color)
        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if rs[0]["msg_on_member_update"] != str(new_status):
            await serverConfigsSql.update_msg_on_member_update(
                ctx.guild.id, str(new_status))

        await BotUtils.send_embed(self, ctx, embed, False, msg)
Ejemplo n.º 7
0
        async def on_user_update(before, after):
            if str(before.name) != str(after.name) \
            or str(before.avatar_url) != str(after.avatar_url) \
            or str(before.discriminator) != str(after.discriminator):
                # update user in database
                usersSql = UsersSql(self.bot)
                await usersSql.update_user_changes(after)

                msg = "Profile Changes:\n\n"
                now = dt.datetime.now()
                color = self.bot.settings["EmbedColor"]
                embed = discord.Embed(color=color)
                embed.set_author(name=after.display_name,
                                 icon_url=after.avatar_url)
                embed.set_footer(text=f"{now.strftime('%c')}")

                if str(before.avatar_url) != str(after.avatar_url):
                    embed.set_thumbnail(url=after.avatar_url)
                    embed.add_field(name="New Avatar",
                                    value="-->",
                                    inline=True)
                    msg += f"New Avatar: \n{after.avatar_url}\n"

                if str(before.name) != str(after.name):
                    if before.name is not None:
                        embed.add_field(name="Previous Name",
                                        value=str(before.name))
                    embed.add_field(name="New Name", value=str(after.name))
                    msg += f"New Name: `{after.name}`\n"

                if str(before.discriminator) != str(after.discriminator):
                    if before.name is not None:
                        embed.add_field(name="Previous Discriminator",
                                        value=str(before.discriminator))
                    embed.add_field(name="New Discriminator",
                                    value=str(after.discriminator))
                    msg += f"New Discriminator: `{after.discriminator}`\n"

                serverConfigsSql = ServerConfigsSql(self.bot)
                for guild in after._state.guilds:
                    if after in guild.members:
                        rs_sc = await serverConfigsSql.get_server_configs(
                            guild.id)
                        if len(rs_sc) > 0 and rs_sc[0][
                                "msg_on_member_update"] == "Y":
                            if len(embed.fields) > 0:
                                channel_to_send_msg = await BotUtils.channel_to_send_msg(
                                    bot, guild)
                                if channel_to_send_msg is not None:
                                    try:
                                        await channel_to_send_msg.send(
                                            embed=embed)
                                    except discord.HTTPException:
                                        await channel_to_send_msg.send(msg)
Ejemplo n.º 8
0
    async def blacklist_add(self, ctx, member: discord.Member, *, reason=None):
        """(Add user to blacklist)

        Example:
        blacklist add member#1234 reason
        """

        if member.id == self.bot.owner.id:
            await BotUtils.send_error_msg(
                self, ctx, "The Bot Owner cannot be blacklisted.")
            return
        if member.id == self.bot.user.id:
            await BotUtils.send_error_msg(
                self, ctx, "The Bot itself cannot be blacklisted.")
            return
        if member.id == ctx.message.author.id:
            await BotUtils.send_error_msg(self, ctx,
                                          "You cannot blacklist yourself.")
            return
        if BotUtils.is_server_owner(ctx, member):
            await BotUtils.send_error_msg(
                self, ctx, "You cannot blacklist the Server's Owner.")
            return

        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if BotUtils.is_member_admin(
                member) and rs[0]["blacklist_admins"] == 'N':
            await BotUtils.send_error_msg(
                self, ctx, "You cannot blacklist a Server's Admin.")
            return

        if reason is not None and len(reason) > 29:
            await BotUtils.send_error_msg(self, ctx,
                                          "Reason has too many characters.")
            return

        blacklistsSql = BlacklistsSql(self.bot)
        rs = await blacklistsSql.get_server_blacklisted_user(member)
        if len(rs) == 0:
            await blacklistsSql.insert_blacklisted_user(
                member, ctx.message.author, reason)
            msg = f"Successfully added {member} to the blacklist.\n" \
                  "Cannot execute any Bot commands anymore."
            if reason is not None:
                msg += f"\nReason: {reason}"
            color = self.bot.settings["EmbedColor"]
            await BotUtils.send_msg(self, ctx, color, Formatting.inline(msg))
        else:
            msg = f"{member} is already blacklisted."
            if rs[0]["reason"] is not None:
                msg += f"\nReason: {reason}"
            await BotUtils.send_error_msg(self, ctx, msg)
Ejemplo n.º 9
0
async def channel_to_send_msg(bot, server: discord.Guild):
    serverConfigsSql = ServerConfigsSql(bot)
    rs = await serverConfigsSql.get_server_configs(server.id)
    default_text_channel = rs[0]["default_text_channel"]
    sorted_channels = sorted(server.text_channels, key=attrgetter('position'))
    if default_text_channel is None or default_text_channel == "" or len(default_text_channel) == 0:
        return get_server_first_public_text_channel(server)
    if default_text_channel in str(sorted_channels):
        for channel in sorted_channels:
            if channel.name == default_text_channel:
                return channel
    return None
Ejemplo n.º 10
0
    async def mute_add(self, ctx, member: discord.Member, *, reason=None):
        """(Mute an user)

        Example:
        mute add member#1234 reason
        """

        if member.id == self.bot.owner.id:
            await BotUtils.send_error_msg(self, ctx,
                                          "The Bot Owner cannot be muted.")
            return
        if member.id == self.bot.user.id:
            await BotUtils.send_error_msg(self, ctx,
                                          "The Bot itself cannot be muted.")
            return
        if member.id == ctx.message.author.id:
            await BotUtils.send_error_msg(self, ctx,
                                          "You cannot mute yourself.")
            return
        if BotUtils.is_server_owner(ctx, member):
            await BotUtils.send_error_msg(
                self, ctx, "You cannot mute the Server's Owner.")
            return

        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if BotUtils.is_member_admin(member) and rs[0]["mute_admins"] == 'N':
            await BotUtils.send_error_msg(self, ctx,
                                          "You cannot mute a Server's Admin.")
            return

        if reason is not None and len(reason) > 29:
            await BotUtils.send_error_msg(self, ctx,
                                          "Reason has too many characters.")
            return

        mutesSql = MutesSql(self.bot)
        rs = await mutesSql.get_server_mute_user(member)
        if len(rs) == 0:
            await mutesSql.insert_mute_user(member, ctx.message.author, reason)
            msg = f"Successfully muted {member}"
            color = self.bot.settings["EmbedColor"]
            if reason is not None:
                msg += f"\nReason: {reason}"
            await BotUtils.send_msg(self, ctx, color, Formatting.inline(msg))
        else:
            msg = f"{member} is already muted."
            if rs[0]["reason"] is not None:
                msg += f"\nReason: {reason}"
            await BotUtils.send_error_msg(self, ctx, msg)
Ejemplo n.º 11
0
        async def on_member_update(before, after):
            # do nothing if its a bot
            if after.bot:
                return

            # do nothing if changed status
            if str(before.status) != str(after.status):
                return

            # check for gw2 game activity
            await Gw2Utils.last_session_gw2_event(bot, before, after)

            if str(before.nick) != str(after.nick):
                serverConfigsSql = ServerConfigsSql(self.bot)
                rs_sc = await serverConfigsSql.get_server_configs(
                    after.guild.id)
                if len(rs_sc) > 0 and rs_sc[0]["msg_on_member_update"] == "Y":
                    msg = "Profile Changes:\n\n"
                    now = dt.datetime.now()
                    color = self.bot.settings["EmbedColor"]
                    embed = discord.Embed(color=color)
                    embed.set_author(name=after.display_name,
                                     icon_url=after.avatar_url)
                    embed.set_footer(text=f"{now.strftime('%c')}")

                    if before.nick is not None and after.nick is None:
                        embed.add_field(name="Previous Nickname",
                                        value=str(before.nick))
                    elif before.nick is not None:
                        embed.add_field(name="Previous Nickname",
                                        value=str(before.nick))
                    embed.add_field(name="New Nickname", value=str(after.nick))
                    msg += f"New Nickname: `{after.nick}`\n"

                    if len(embed.fields) > 0:
                        channel_to_send_msg = await BotUtils.channel_to_send_msg(
                            bot, after.guild)
                        if channel_to_send_msg is not None:
                            try:
                                await channel_to_send_msg.send(embed=embed)
                            except discord.HTTPException:
                                await channel_to_send_msg.send(msg)
Ejemplo n.º 12
0
    async def config_default_text_channel(self, ctx, *, text_channel: str):
        """(Set default text channel to be used for bot messages)
        
        Use "none" to use first public available channel
        
        Example:
        config defaultchannel <channel_name>
        config defaultchannel <none>
        """

        await ctx.message.channel.trigger_typing()
        channel_exists = False
        for channel in ctx.guild.text_channels:
            if text_channel.lower() == str(channel.name).lower():
                channel_exists = True

        if text_channel.lower() == "none":
            channel_exists = True
            text_channel = None

        if channel_exists is False:
            raise commands.BadArgument(
                message="BadArgument_default_text_channel")

        if text_channel is None:
            msg = "First public text channel is going to be used for bot messages"
        else:
            msg = f"Default text channel to be used for bot messages: {Formatting.inline(text_channel)}"

        color = discord.Color.green()
        embed = discord.Embed(description=msg, color=color)
        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if rs[0]["default_text_channel"] != str(text_channel):
            await serverConfigsSql.update_default_text_channel(
                ctx.guild.id, str(text_channel))

        await BotUtils.send_embed(self, ctx, embed, False, msg)
Ejemplo n.º 13
0
        async def on_guild_update(before, after):
            author = None
            async for entry in after.audit_logs(
                    limit=1, action=discord.AuditLogAction.guild_update):
                author = entry.user

            serversSql = ServersSql(self.bot)
            await serversSql.update_server_changes(before, after)

            serverConfigsSql = ServerConfigsSql(self.bot)
            rs = await serverConfigsSql.get_server_configs(after.id)
            if len(rs) > 0 and rs[0]["msg_on_server_update"] == "Y":
                msg = "New Server Settings\n"
                now = dt.datetime.now()
                color = self.bot.settings["EmbedColor"]
                embed = discord.Embed(color=color)
                embed.set_author(name=msg, icon_url=author.avatar_url)
                embed.set_footer(text=f"{now.strftime('%c')}")

                if str(before.name) != str(after.name):
                    if before.name is not None:
                        embed.add_field(name="Previous Name",
                                        value=str(before.name))
                    embed.add_field(name="New Name", value=str(after.name))
                    msg += f"New Server Name: `{after.name}`\n"

                if str(before.region) != str(after.region):
                    before_flag = BotUtils.get_region_flag(str(before.region))
                    after_flag = BotUtils.get_region_flag(str(after.region))
                    if before.region is not None:
                        embed.add_field(name="Previous Region",
                                        value=before_flag + " " +
                                        str(before.region))
                    embed.add_field(name="New Region",
                                    value=f"{after_flag} {after.region}")
                    msg += f"New Server Region: {after_flag} `{after.region}`\n"

                if str(before.icon_url) != str(after.icon_url):
                    embed.set_thumbnail(url=after.icon_url)
                    embed.add_field(name="New Server Icon",
                                    value="-->",
                                    inline=True)
                    msg += f"New Server Icon: \n{after.icon_url}\n"

                if str(before.owner_id) != str(after.owner_id):
                    embed.set_thumbnail(url=after.icon_url)
                    if before.owner_id is not None:
                        embed.add_field(name="Previous Server Owner",
                                        value=str(before.owner))
                    embed.add_field(name="New Server Owner",
                                    value=str(after.owner),
                                    inline=True)
                    msg += f"New Server Owner: `{after.owner}`\n"

                if len(embed.fields) > 0:
                    channel_to_send_msg = await BotUtils.channel_to_send_msg(
                        bot, after)
                    if channel_to_send_msg is not None:
                        try:
                            await channel_to_send_msg.send(embed=embed)
                        except discord.HTTPException:
                            await channel_to_send_msg.send(msg)
Ejemplo n.º 14
0
    async def config_config_list(self, ctx):
        """(List all bot configurations)
        
        Example:
        config list
        """

        serverConfigsSql = ServerConfigsSql(self.bot)
        profanityFilterSql = ProfanityFilterSql(self.bot)

        sc = await serverConfigsSql.get_server_configs(ctx.guild.id)
        pf = await profanityFilterSql.get_all_server_profanity_filter_channels(
            ctx.guild.id)

        if len(pf) > 0:
            channel_names_lst = []
            for key, value in pf.items():
                channel_names_lst.append(f"{value['channel_name']}")
            channel_names = '\n'.join(channel_names_lst)
        else:
            channel_names = "No channels listed"

        on = Formatting.green_text("ON")
        off = Formatting.red_text("OFF")
        color = self.bot.settings["EmbedColor"]

        embed = discord.Embed(color=color)
        embed.set_thumbnail(url=f"{ctx.guild.icon_url}")
        embed.set_author(name=f"Configurations for {ctx.guild.name}",
                         icon_url=f"{ctx.guild.icon_url}")

        embed.add_field(
            name=
            f"Admins can be blacklisted (cannot use any commands)\n*`{ctx.prefix}config bladmin [on | off]`*",
            value=f"{on}" if sc[0]["blacklist_admins"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Admins can be muted (cannot type anything)\n*`{ctx.prefix}config muteadmin [on | off]`*",
            value=f"{on}" if sc[0]["mute_admins"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Display a message when someone joins the server\n*`{ctx.prefix}config joinmessage [on | off]`*",
            value=f"{on}" if sc[0]["msg_on_join"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Display a message when someone leaves the server\n*`{ctx.prefix}config leavemessage [on | off]`*",
            value=f"{on}" if sc[0]["msg_on_leave"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Display a message when the server gets updated\n*`{ctx.prefix}config servermessage [on | off]`*",
            value=f"{on}"
            if sc[0]["msg_on_server_update"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Display a message when someone changes their profile\n*`{ctx.prefix}config membermessage [on | off]`*",
            value=f"{on}"
            if sc[0]["msg_on_member_update"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Block messages from invisible members\n*`{ctx.prefix}config blockinvisible [on | off]`*",
            value=f"{on}" if sc[0]["block_invis_members"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Mention everyone when pool commands are used\n*`{ctx.prefix}config mentionpool [on | off]`*",
            value=f"{on}"
            if sc[0]["mention_everyone_pool_cmd"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Anonymous pools\n(hide the author's name from the pool command)\n*`{ctx.prefix}config anonymouspool [on | off]`*",
            value=f"{on}" if sc[0]["anonymous_pool"] == 'Y' else f"{off}",
            inline=False)
        embed.add_field(
            name=
            f"Bot will react to member words\n*`{ctx.prefix}config botreactions [on | off] <channel_name>`*",
            value=f"{on}" if sc[0]["bot_word_reactions"] == 'Y' else f"{off}",
            inline=False)

        if sc[0]["default_text_channel"] is not None and sc[0][
                "default_text_channel"] != "":
            default_text_channel = sc[0]["default_text_channel"]
        else:
            default_text_channel = f"{BotUtils.get_server_first_public_text_channel(ctx.guild)}"

        embed.add_field(
            name=
            f"Text channel to display bot messages\n(defaults to the top first public channel)\n*`{ctx.prefix}config defaultchannel <channel_name>`*",
            value=Formatting.inline(default_text_channel),
            inline=False)
        embed.add_field(name="Text channels with profanity filter activated",
                        value=Formatting.inline(channel_names),
                        inline=False)

        embed.set_footer(text=f"For more info: {ctx.prefix}help config")
        await BotUtils.send_embed(self, ctx, embed, True)
Ejemplo n.º 15
0
    async def simplepool(self, ctx, *, question: str):
        """(Create a simple yes,no,emojis pool)

        - All emojis found in the question are going to be converted to reactions
        - Need at least two emojis
        - If no emojis are found, "Thumbs Up" and "Thums Down" are going to be the only reactions

        Example:
        simplepool <question goes here> <:emoji: :emoji:>

        simplepool Question? :robot: :heart:
        simplepool Question?
        """

        await ctx.message.channel.trigger_typing()
        await BotUtils.delete_last_channel_message(self, ctx)

        server = ctx.message.guild
        question_list = []
        reactions_list = []

        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(server.id)
        if rs[0]["mention_everyone_pool_cmd"] == 'Y':
            mention_everyone = True
        else:
            mention_everyone = False

        if rs[0]["anonymous_pool"] == 'Y':
            anonymous_pool = True
        else:
            anonymous_pool = False

        for word in question.split():
            is_server_emoji = False
            is_discord_emoji = False
            is_question = True
            temp_emoji = None

            if len(word.encode('utf-8')) > len(word):
                is_discord_emoji = True
                is_question = False
                temp_emoji = str(word)

            if is_discord_emoji is False:
                if len(server.emojis) > 0:
                    for emoji in server.emojis:
                        sename_str = f"<:{emoji.name}:{emoji.id}>"
                        if str(word) == str(sename_str):
                            is_server_emoji = True
                            is_question = False
                            temp_emoji = emoji

            if is_question is True:
                question_list.append(str(word))
            elif is_server_emoji is True or is_discord_emoji is True:
                emoji_already_in_list = False
                if len(reactions_list) > 0:
                    for rl in reactions_list:
                        if str(word) == str(rl):
                            emoji_already_in_list = True

                if emoji_already_in_list is False:
                    reactions_list.append(temp_emoji)

        new_question = ' '.join(question_list)
        if len(new_question) == 0:
            msg = f"Please ask at least one question!!!\n Command: {ctx.prefix}simplepool"
            await BotUtils.send_error_msg(self, ctx, msg)
            return

        color = BotUtils.get_random_color()
        embed = discord.Embed(color=color,
                              description=Formatting.orange_text(new_question))

        if anonymous_pool is False:
            author_name = BotUtils.get_member_name_by_id(
                self, ctx, ctx.message.author.id)
            embed.set_author(name=author_name,
                             icon_url=ctx.message.author.avatar_url)

        try:
            msg = await ctx.send(embed=embed)
        except discord.Forbidden:
            msg = await ctx.send(new_question)

        if len(reactions_list) == 0:
            await msg.add_reaction("\U0001F44D")
            await msg.add_reaction("\U0001F44E")
        elif len(reactions_list) == 1:
            msg = f"Please use more than one emoji!!!\n Command: {ctx.prefix}pool"
            await BotUtils.send_error_msg(self, ctx, msg)
            return
        elif len(reactions_list) > 1:
            for reaction in reactions_list:
                await msg.add_reaction(reaction)

        if (mention_everyone):
            m = await ctx.send("@everyone")
            m.mention_everyone = True
Ejemplo n.º 16
0
    async def pool(self, ctx, *, questions: str):
        """(Creates a numeric list of choices pool)

        - Choices are going to be separated by semicolon (;)
        - First sentence before the first semicolon will be the question
        - All emojis found with the choices are going to stay at the message
        - Need at least two choices
        - No more than 10 choices allowed

        Example:
        pool Question?; First choice; Second choice; Third choice
        """

        await ctx.message.channel.trigger_typing()
        await BotUtils.delete_last_channel_message(self, ctx)

        new_question_list = []
        serverConfigsSql = ServerConfigsSql(self.bot)
        rs = await serverConfigsSql.get_server_configs(ctx.guild.id)
        if rs[0]["mention_everyone_pool_cmd"] == 'Y':
            mention_everyone = True
        else:
            mention_everyone = False

        if rs[0]["anonymous_pool"] == 'Y':
            anonymous_pool = True
        else:
            anonymous_pool = False

        counter = 0
        for question in questions.split(";"):
            if str(question) != "":
                if counter == 0:
                    new_question_list.append(str(question))
                else:
                    new_question_list.append(f"{counter}) {question}")
                counter += 1

        new_question = '\n'.join(new_question_list)
        color = BotUtils.get_random_color()
        embed = discord.Embed(color=color,
                              description=Formatting.orange_text(new_question))
        list_size = len(new_question_list)

        if list_size == 2:
            msg = "Command \"pool\" need at least two choices!!!\n" \
                  "Choices are separated by semicolon (;)\n" \
                  "The first sentence is always the question\n" \
                  f"For a simple line pool, use the command: {ctx.prefix}simplepool" \
                  f"For more info: {ctx.prefix}help pool"
            await BotUtils.send_error_msg(self, ctx, msg)
            return

        if list_size > 11:
            msg = "Cannot exceed more than 10 choices.\n" \
                  f"command: {ctx.prefix}pool"
            await BotUtils.send_error_msg(self, ctx, msg)
            return

        if anonymous_pool is False:
            author_name = BotUtils.get_member_name_by_id(
                self, ctx, ctx.message.author.id)
            embed.set_author(name=author_name,
                             icon_url=ctx.message.author.avatar_url)

        try:
            msg = await ctx.send(embed=embed)
        except discord.Forbidden:
            msg = await ctx.send(new_question)

        for x in range(1, list_size):
            if x == 10:
                await msg.add_reaction("\U0001F51F")
            else:
                await msg.add_reaction(f"{x}\u20e3")

        if (mention_everyone):
            m = await ctx.send("@everyone")
            m.mention_everyone = True
Ejemplo n.º 17
0
async def execute_server_msg(self, ctx):
    is_command = True if ctx.prefix is not None else False
    serverConfigsSql = ServerConfigsSql(self.bot)
    rs_user_channel_configs = await serverConfigsSql.get_user_channel_configs(ctx.author, ctx.message.channel.id)

    if len(rs_user_channel_configs) == 0:
        self.bot.log.error("error with serverConfigsSql.get_user_channel_configs")
        return

    # block messages from invisible members
    if rs_user_channel_configs[0]["block_invis_members"] == "Y":
        is_member_invis = _check_member_invisible(self, ctx)
        if is_member_invis:
            await BotUtils.delete_last_channel_message(self, ctx)
            msg = "You are Invisible (offline)\n" \
                  f"Server \"{ctx.guild.name}\" does not allow messages from invisible members.\n" \
                  "Please change your status if you want to send messages to this server."
            embed = discord.Embed(title="", color=discord.Color.red(), description=Formatting.error_inline(msg))
            embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
            try:
                await ctx.message.author.send(embed=embed)
            except discord.HTTPException:
                try:
                    await ctx.send(embed=embed)
                except discord.HTTPException:
                    await ctx.send(f"{ctx.message.author.mention} {msg}")
            return

    # block bad words profanity filter "on" current channel
    if rs_user_channel_configs[0]["profanity_filter"] is not None and rs_user_channel_configs[0][
        "profanity_filter"] == 'Y':
        bad_word = await _check_profanity_filter_words(self, ctx.message)
        if bad_word: return

    # check for custom messages
    if rs_user_channel_configs[0]["bot_word_reactions"] == "Y":
        customMessages = await _check_custom_messages(self, ctx.message)
        if customMessages: return

    # checking if member is muted in the current server
    if rs_user_channel_configs[0]["muted"] is not None and rs_user_channel_configs[0]["muted"] == 'Y':
        try:
            await ctx.message.delete()
        except:
            msg = "Bot does not have permission to delete messages.\n" \
                  "Missing permission: \"Manage Messages\"`"
            embed = discord.Embed(title="", color=discord.Color.red(), description=msg)
            try:
                await ctx.channel.send(embed=embed)
            except discord.HTTPException:
                await ctx.channel.send(f"{msg}")
            return

        msg = "You are muted.\n" \
              f"Server: {ctx.guild}\n" \
              "You cannot type anything.\n" \
              "Please do not insist.\n"
        if rs_user_channel_configs[0]['muted_reason'] is not None:
            msg += f"\nReason: {rs_user_channel_configs[0]['muted_reason']}"
        embed = discord.Embed(title="", color=discord.Color.red(), description=Formatting.error_inline(msg))
        embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
        try:
            await ctx.message.author.send(embed=embed)
        except:
            await ctx.send(f"{ctx.message.author.mention}\n{msg}")
        return

    if is_command:
        ignore_prefixes_characteres = await _check_prefixes_characteres(self, ctx.message)
        if ignore_prefixes_characteres: return

        if not (await _check_exclusive_users(self, ctx)):
            return

        # checking if member is blacklisted
        if rs_user_channel_configs[0]["blacklisted"] is not None and rs_user_channel_configs[0]["blacklisted"] == 'Y':
            if ctx.message.content.startswith(ctx.prefix):
                msg = "You are blacklisted.\n" \
                      "You cannot execute any Bot commands.\n" \
                      "Please do not insist.\n"
                if rs_user_channel_configs[0]['blacklisted_reason'] is not None:
                    msg += f"\nReason: {rs_user_channel_configs[0]['blacklisted_reason']}"
                embed = discord.Embed(title="", color=discord.Color.red(), description=Formatting.error_inline(msg))
                embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
                try:
                    await ctx.message.channel.send(embed=embed)
                except discord.HTTPException:
                    await ctx.send(f"{ctx.message.author.mention}\n{msg}")
                return

        # execute custom commands
        commandsSql = CommandsSql(self.bot)
        rs_command = await commandsSql.get_command(ctx.author.guild.id, str(ctx.invoked_with))
        if len(rs_command) > 0:
            await ctx.message.channel.trigger_typing()
            await ctx.message.channel.send(str(rs_command[0]["description"]))
            return

        await self.bot.process_commands(ctx.message)