Exemplo n.º 1
0
def get_privilege(user_id) -> str or None:
    """
    Return the privilege from users table by user_id
    """
    try:
        user = Users.select().where(Users.user_id == user_id)[0]
        commit()
        return str(user.privilege)
    except Exception:
        rollback()
        return None
Exemplo n.º 2
0
def get_user(user_id) -> str or None:
    """
    Return an user from users table with by user_id
    """
    try:
        user = Users.select().where(Users.user_id == user_id)[0]
        commit()
        return f"{user.user_id} {user.name} {user.surname} {user.privilege}"
    except Exception:
        rollback()
        return None
Exemplo n.º 3
0
def get_number(user_id):
    """
    Return a number or numbers
    """
    try:
        numbers = BlackList.select().where(BlackList.user_id == user_id)
        res = [f"{number.user_id} {number.number}" for number in numbers]
        commit()
        return res
    except Exception:
        rollback()
        return list()
Exemplo n.º 4
0
def get_users() -> list or None:
    """
    Return the list of users {id : name : surname : privilege}
    """
    try:
        users = Users.select()
        res = [f"{user.user_id} {user.name} {user.surname} {user.privilege}" for user in users]
        commit()
        return res
    except Exception:
        rollback()
        return None
Exemplo n.º 5
0
def add_number(user_id, number) -> bool:
    """
    Adds a number to the table if user_id is exists in users table\n
    Return True if added, or False if not
    """
    try:
        BlackList.create(user_id=user_id, number=number.lower().strip('+'))
        commit()
        return True
    except Exception:
        rollback()
        return False
Exemplo n.º 6
0
def rem_user(user_id) -> bool:
    """
    Remove user from users table and will removed all numbers from blacklist table\n
    Return True if removed or False if not
    """
    try:
        user = Users.get(user_id=user_id)
        user.delete_instance()
        commit()
        return True
    except Exception:
        rollback()
        return False
Exemplo n.º 7
0
def get_numbers() -> list:
    """
    Return list of numbers
    """
    try:
        numbers = BlackList.select()
        list = []
        for num in numbers:
            list.append(num.number)
        return list
        commit()
    except Exception:
        rollback()
Exemplo n.º 8
0
def add_user(user_id, name, surname, privilege) -> bool:
    """
    Adds a user to the table if it doesn't exist\n
    Return True if added, or False if not
    """
    try:
        Users.create(user_id=user_id,
                     name=name,
                     surname=surname,
                     privilege=privilege.lower().strip())
        commit()
        return True
    except Exception:
        db.rollback()
        return False
Exemplo n.º 9
0
def get_ddosnumberlist(isUnique: bool = True) -> dict or None:
    """
    Return the list of blacklist table {id : number}
    """
    try:
        numberList = DdosNumberList.select()
        if isUnique:
            res = dict()
            for row in numberList:
                res[f"{row.user_id}"] = row.number
        else:
            res = [f"{row.user_id} {row.number}" for row in numberList]
        commit()
        return res
    except Exception:
        rollback()
        return None
Exemplo n.º 10
0
def rem_number(user_id, number: str) -> bool:
    """
    Remove number from ddos_number_list table\n
    Return True if removed or False if not
    """
    try:
        i = 0
        for user_bl in DdosNumberList.select().where(
            (DdosNumberList.user_id == user_id)
                & (DdosNumberList.number == number.lower().strip('+'))):
            user_bl.delete_instance()
            i += 1
        commit()
        if i == 0:
            return False
        return True
    except Exception:
        rollback()
        return False