Exemplo n.º 1
0
    def check_permissions(self, member):
        if isinstance(member, discord.Member) and self.perms is not None:
            if (self.perms & util.MODERATOR_PERM) > 0:
                res = DB.query(
                    "SELECT * FROM perms WHERE server_id = '%d' AND perm_type = 2"
                    % (member.guild.id, ))

                for row in res:
                    if not row[3] and row[2] in list(
                            map(lambda x: str(x.id), member.roles)):
                        return True

                    if row[3] and row[2] == str(member.id):
                        return True

            if (self.perms & util.ADMINISTRATOR_PERM) > 0:
                res = DB.query(
                    "SELECT * FROM perms WHERE server_id = '%d' AND perm_type = 1"
                    % (member.guild.id, ))

                for row in res:
                    if not row[3] and row[2] in list(
                            map(lambda x: str(x.id), member.roles)):
                        return True

                    if row[3] and row[2] == str(member.id):
                        return True

                if len(res) == 0:
                    # prevents lock out
                    return True

            return False

        return True
Exemplo n.º 2
0
async def addcom(client, message):
    if message.guild is None:
        return "Command must be ran on a server..."

    splitmsg = message.content.split(" ", 2)
    reserved = util.get_command_list()

    if len(splitmsg) < 3:
        return "Invalid usage. Use format `&addcom command Response`"

    if splitmsg[1] in reserved:
        return "Cannot add a reserved command..."

    res = DB.query(
        "SELECT command FROM commands WHERE server_id = '%s' AND command = '%s'"
        % (
            message.guild.id,
            splitmsg[1],
        ))

    if len(res) > 0:
        return "Command already exists..."

    DB.exec("INSERT INTO commands (server_id, command, response) "
            "VALUES ('%s', '%s', '%s')" % (
                message.guild.id,
                splitmsg[1],
                splitmsg[2],
            ))

    return "Command added..."
Exemplo n.º 3
0
async def prefix(client, message):
    splitmsg = message.content.split(" ")
    if len(splitmsg) < 2:
        return "You need to provide a prefix..."

    DB.exec("UPDATE servers SET prefix = '%s' WHERE id = '%s'" % (
        splitmsg[1][0],
        message.guild.id,
    ))
    return "Updated prefix to %s" % (splitmsg[1][0], )
Exemplo n.º 4
0
async def deladmin(client, message):
    splitmsg = message.content.split(" ")

    if message.guild is None:
        return "Command must be run on a server."

    for x in message.mentions + message.role_mentions:
        DB.exec("DELETE FROM perms WHERE server_id = '%s' AND role_id = '%d'" %
                (message.guild.id, x.id))

    return "Revoked permission to use administrator bot commands..."
Exemplo n.º 5
0
async def delcom(client, message):
    if message.guild is None:
        return "Message must be run on server."

    splitmsg = message.content.split(" ")

    DB.exec("DELETE FROM commands WHERE server_id = '%d' AND command = '%s'" %
            (
                message.guild.id,
                splitmsg[1],
            ))

    return "Deleted command..."
Exemplo n.º 6
0
async def addmod(client, message):
    if message.guild is None:
        return "Command must be run on a server."

    for x in message.mentions:
        DB.exec("INSERT INTO perms (server_id, perm_type, role_id, is_user) "
                "VALUES ('%s', %d, '%s', TRUE)" %
                (message.guild.id, util.MODERATOR_PERM, x.id))

    for x in message.role_mentions:
        DB.exec("INSERT INTO perms (server_id, perm_type, role_id, is_user) "
                "VALUES ('%s', %s, '%s', FALSE)" %
                (message.guild.id, util.MODERATOR_PERM, x.id))

    return "Granted permission to use moderator bot commands..."
Exemplo n.º 7
0
async def addadmin(client, message):
    splitmsg = message.content.split(" ")

    if message.guild is None:
        return "Command must be run on a server."

    for x in message.mentions:
        DB.exec("INSERT INTO perms (server_id, perm_type, role_id, is_user) "
                "VALUES (%s, %d, %s, TRUE)" %
                (message.guild.id, util.ADMINISTRATOR_PERM, x.id))

    for x in message.role_mentions:
        DB.exec("INSERT INTO perms (server_id, perm_type, role_id, is_user) "
                "VALUES (%s, %s, %s, FALSE)" %
                (message.guild.id, util.ADMINISTRATOR_PERM, x.id))

    return "Granted permission to use administrator bot commands..."