コード例 #1
0
def db_rm_blacklist(phone):
    """Removes a blacklisted phone from the database.

    Args:
        phone (str): Phone of the contact.
    """
    DB.remove((CONTACT.phone == phone) & (CONTACT.blacklisted == True))
コード例 #2
0
def db_rm_contact(name):
    """Remove a contact from the the database.

    Args:
        name (str): Name of the contact to remove.
    """
    DB.remove(CONTACT.name == name.lower())
コード例 #3
0
def db_toggle_bridge_by_wa(phone, toggle):
    result = DB.get((CONTACT.phone == phone))

    if not result:
        return None

    DB.update({'enabled': toggle}, (CONTACT.phone == phone))

    return toggle
コード例 #4
0
def db_toggle_bridge_by_tg(group, toggle):
    result = DB.get((CONTACT.group == group))

    if not result:
        return None

    DB.update({'enabled': toggle}, (CONTACT.group == group))

    return toggle
コード例 #5
0
def db_is_bridge_enabled_by_tg(group):
    result = DB.get((CONTACT.group == group))

    if not result:
        return None

    return result.get('enabled')
コード例 #6
0
def db_is_bridge_enabled_by_wa(phone):
    result = DB.get((CONTACT.phone == phone))

    if not result:
        return None

    return result.get('enabled')
コード例 #7
0
def db_get_group(contact):
    result = DB.get((CONTACT.name == contact.lower()))

    if not result:
        return None

    # return None for backward compatibility if there is no group column
    return result.get('group')
コード例 #8
0
ファイル: helper.py プロジェクト: jasonahjie/wat-bridge
def db_add_blacklist(phone):
    """Add a new blacklisted phone to the database.

    Args:
        phone (str): Phone of the contact.

    Returns:
        ID of the inserted element.
    """
    return DB.insert({'name': None, 'phone': phone, 'blacklisted': True})
コード例 #9
0
def db_list_contacts():
    """Obtain a list of contacts.

    The list contains tuples with (name, phone)

    Returns:
        List of tuples
    """
    result = DB.search(CONTACT.blacklisted == False)

    return [(a['name'], a['phone'], a.get('group')) for a in result]
コード例 #10
0
def get_blacklist():
    """Obtain a list of blacklisted phones.

    Returns:
        List of strings.
    """
    result = DB.search(CONTACT.blacklisted == True)

    if not result:
        return []

    return [a['phone'] for a in result]
コード例 #11
0
def get_contact(phone):
    """Get contact name from a phone number.

    Args:
        phone (str): Phone to search.

    Returns:
        String with the contact name or `None` if not found.
    """
    result = DB.get((CONTACT.phone == phone) & (CONTACT.blacklisted == False))

    if not result:
        return None

    return result['name']
コード例 #12
0
def db_get_contact_by_group(group):
    """Get phone number from a group id.

    Args:
        group (int): Group id assigned to the contact.

    Returns:
        String with the phone number or `None` if not found.
    """
    result = DB.get((CONTACT.group == group))

    if not result:
        return None

    return result['name']
コード例 #13
0
def is_blacklisted(phone):
    """Check if a phone number is blacklisted.

    Args:
        phone (str): Phone to check

    Returns:
        True or False
    """
    result = DB.get((CONTACT.phone == phone) & (CONTACT.blacklisted == True))

    if not result:
        return False

    return True
コード例 #14
0
ファイル: helper.py プロジェクト: jasonahjie/wat-bridge
def db_add_contact(name, phone):
    """Add a new contact to the database.

    Args:
        name (str): Name to use for the contact.
        phone (str): Phone of the contact.

    Returns:
        ID of the inserted element.
    """
    return DB.insert({
        'name': name.lower(),
        'phone': phone,
        'blacklisted': False
    })
コード例 #15
0
def get_phone(contact):
    """Get phone number from a contact name.

    Args:
        contact (str): Name assigned to the contact

    Returns:
        String with the phone number or `None` if not found.
    """
    result = DB.get((CONTACT.name == contact.lower())
                    & (CONTACT.blacklisted == False))

    if not result:
        return None

    return result['phone']
コード例 #16
0
def db_set_group(contact, group):
    DB.update({'group': group}, (CONTACT.name == contact.lower()))
コード例 #17
0
def db_set_phone(contact, phone):
    DB.update({'phone': phone}, (CONTACT.name == contact.lower()))