Пример #1
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)
Пример #2
0
    async def blacklist_list(self, ctx):
        """(List all blacklisted users)
         
        Example:
        blacklist list
        """

        bl_members = []
        bl_reason = []
        bl_author = []
        position = 1

        blacklistsSql = BlacklistsSql(self.bot)
        rs = await blacklistsSql.get_all_server_blacklisted_users(ctx.guild.id)
        if len(rs) > 0:
            for key, value in rs.items():
                member_name = f"{ctx.guild.get_member(value['discord_user_id'])}"
                author_name = BotUtils.get_member_name_by_id(
                    self, ctx, value["discord_author_id"])
                bl_author.append(author_name)
                bl_members.append(f"{position}) {member_name}")
                if value["reason"] is None:
                    bl_reason.append("---")
                else:
                    bl_reason.append(value["reason"])
                position += 1

            members = '\n'.join(bl_members)
            reason = '\n'.join(bl_reason)
            author = '\n'.join(bl_author)

            embed = discord.Embed(
                description="*`Members that cannot execute any bot commands`*",
                color=discord.Color.red())
            embed.set_footer(text=f"For more info: {ctx.prefix}help blacklist")
            embed.set_author(name="Blalcklisted members in this server:\n\n",
                             icon_url=f"{ctx.guild.icon_url}")
            embed.add_field(name="Member",
                            value=Formatting.inline(members),
                            inline=True)
            embed.add_field(name="Added by",
                            value=Formatting.inline(author),
                            inline=True)
            embed.add_field(name="Reason",
                            value=Formatting.inline(reason),
                            inline=True)

            await BotUtils.send_embed(self, ctx, embed, False)
        else:
            await BotUtils.send_error_msg(
                self, ctx, "There are no blacklisted members in this server.")
Пример #3
0
    async def blacklist_remove_all_users(self, ctx):
        """(Remove all blacklisted users)
         
        Example:
        blacklist removeall
        """

        blacklistsSql = BlacklistsSql(self.bot)
        rs = await blacklistsSql.get_all_server_blacklisted_users(ctx.guild.id)
        if len(rs) > 0:
            color = self.bot.settings["EmbedColor"]
            await blacklistsSql.delete_all_blacklisted_users(ctx.guild.id)
            await BotUtils.send_msg(
                self, ctx, color,
                "Successfully removed all members from the blacklist.")
        else:
            await BotUtils.send_error_msg(
                self, ctx, "There are no blacklisted members in this server.")
Пример #4
0
    async def blacklist_remove_user(self, ctx, *, member: discord.Member):
        """(Remove blacklisted user)
         
        Example:
        blacklist remove member#1234
        """

        if member is not None:
            blacklistsSql = BlacklistsSql(self.bot)
            rs = await blacklistsSql.get_server_blacklisted_user(member)
            if len(rs) > 0:
                await blacklistsSql.delete_blacklisted_user(member)
                msg = f"Successfully removed {member} from the blacklist."
                color = self.bot.settings["EmbedColor"]
                await BotUtils.send_msg(self, ctx, color,
                                        Formatting.inline(msg))
                await ctx.send(f"{member.mention}")
            else:
                msg = f"{member} is not blacklisted."
                await BotUtils.send_error_msg(self, ctx, msg)
        else:
            msg = f"Member {member} not found"
            await BotUtils.send_error_msg(self, ctx, msg)
Пример #5
0
async def execute_private_msg(self, ctx):
    is_command = True if ctx.prefix is not None else False
    if is_command is False:
        # checking for custom messages
        customMessages = await _check_custom_messages(self, ctx.message)
        if customMessages:
            return

        if BotUtils.is_bot_owner(ctx, ctx.message.author):
            msg = f"Hello master.\nWhat can i do for you?"
            embed = discord.Embed(color=discord.Color.green(), description=f"{Formatting.inline(msg)}")
            await ctx.message.author.send(embed=embed)

            cmd = self.bot.get_command("owner")
            await ctx.author.send(Formatting.box(cmd.help))
        else:
            msg = "Hello, I don't accept direct messages."
            embed = discord.Embed(color=discord.Color.red(), description=f"{Formatting.error_inline(msg)}")
            await ctx.message.author.send(embed=embed)
    else:
        if not (await _check_exclusive_users(self, ctx)):
            return

        blacklistsSql = BlacklistsSql(self.bot)
        bl = await blacklistsSql.get_blacklisted_user(ctx.message.author.id)
        if len(bl) > 0:
            if ctx.message.content.startswith(ctx.prefix):
                servers_lst = []
                reason_lst = []
                for key, value in bl.items():
                    servers_lst.append(value["server_name"])
                    if value["reason"] is None:
                        reason_lst.append("---")
                    else:
                        reason_lst.append(value["reason"])

            servers = '\n'.join(servers_lst)
            if len(reason_lst) > 0:
                reason = '\n'.join(reason_lst)
            msg = "You are blacklisted.\n" \
                  "You cannot execute any Bot commands until your are removed from all servers."
            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)
            embed.add_field(name="You are blacklisted on following servers:",
                            value=Formatting.inline(servers),
                            inline=True)
            embed.add_field(name="Reason", value=Formatting.inline(reason), inline=True)
            await ctx.message.channel.send(embed=embed)
            return

        msg = "That command is not allowed in direct messages."
        embed = discord.Embed(color=discord.Color.red(), description=f"{Formatting.error_inline(msg)}")
        user_cmd = ctx.message.content.split(' ', 1)[0]
        allowed_DM_commands = self.bot.settings["DMCommands"]

        if allowed_DM_commands is not None:
            if (isinstance(allowed_DM_commands, tuple)):  # more than 1 command, between quotes
                sorted_cmds = sorted(sorted(allowed_DM_commands))
            elif (isinstance(allowed_DM_commands, str)):
                if "," in allowed_DM_commands:
                    sorted_cmds = allowed_DM_commands.split(",")
                else:
                    sorted_cmds = allowed_DM_commands.split()

            for allowed_cmd in sorted_cmds:
                if user_cmd == ctx.prefix + allowed_cmd:
                    await self.bot.process_commands(ctx.message)
                    return

            allowed_cmds = '\n'.join(sorted_cmds)
            embed.add_field(name="Commands allowed in direct messages:",
                            value=f"{Formatting.inline(allowed_cmds)}",
                            inline=False)

        await ctx.message.author.send(embed=embed)