Exemple #1
0
def store_name(user_data):
    """ this function is here only for /tacotop """

    uid = user_data.id

    with db:
        user = Usernames.select().where(Usernames.uid == uid)

        if user_data.username is None:
            username = None
            first_name = user_data.first_name
            last_name = user_data.last_name
            if last_name is None:
                name = first_name
            else:
                name = first_name + ' ' + last_name
        else:
            name = '@' + user_data.username
            username = user_data.username.lower()

        if user.exists():
            user = user.get()
            user.name = name
            user.username = username
            user.save()

        else:
            Usernames.create(id=len(Usernames.select()) + 5000,
                             uid=uid,
                             name=name,
                             username=username)

        return name
Exemple #2
0
def store_name(message):
    """ this function is here only for /tacotop """

    uid = get_uid(message)
    user_data = message.from_user

    if user_data.username is None:
        username = None
        first_name = user_data.first_name
        last_name = user_data.last_name
        if last_name is None:
            name = first_name
        else:
            name = first_name + ' ' + last_name
    else:
        name = '@' + user_data.username
        username = user_data.username.lower()

    user = Usernames.select().where(Usernames.uid == uid)

    if user.exists():
        user = user.get()
        user.name = name
        user.username = username
        user.save()

    else:
        Usernames.create(uid=uid, name=name, username=username)

    return name
Exemple #3
0
def resolve_name(uid):  # returns username if present in DB
    with db:
        user = Usernames.select().where(Usernames.uid == uid)
        if user.exists():
            return user.get().name
        else:
            return uid
Exemple #4
0
def store_name(update):  # this function is here only for /tacotop

    username = Usernames.select().where(Usernames.uid == get_uid(update))
    if username.exists():
        return username.get().name

    user = update.effective_message.from_user
    if user.username is None:
        first_name = user.first_name
        last_name = user.last_name
        if last_name is None:
            name = first_name
        else:
            name = first_name + ' ' + last_name
    else:
        name = '@' + user.username

    Usernames.create(uid=get_uid(update), name=name)
    return name