Пример #1
0
def delete_user_data(user_id):
    with Vedis(private_constants.db_users) as db:
        try:
            del db[user_id]
            users = ast.literal_eval(db['USERS'].decode('utf-8'))
            users.remove(user_id)
            db['USERS'] = users
        except Exception as e:
            func_name = _getframe().f_code.co_name
            print(
                f'{e.__class__.__name__} while running "{func_name}" 1 with args: {e.args}'
            )
    with Vedis(private_constants.db_file) as db:
        try:
            del db[user_id]
        except Exception as e:
            func_name = _getframe().f_code.co_name
            print(
                f'{e.__class__.__name__} while running "{func_name}" 2 with args: {e.args}'
            )
    with Vedis(private_constants.db_state_file) as db:
        try:
            del db[user_id]
        except Exception as e:
            func_name = _getframe().f_code.co_name
            print(
                f'{e.__class__.__name__} while running "{func_name}" 3 with args: {e.args}'
            )
Пример #2
0
def get_current_hash(user_id, key):
    with Vedis(config.db_status) as db:
        h = db.Hash(str(user_id))
        try:
            return h.to_dict()
        except KeyError:  # Если такого ключа почему-то не оказалось
            return 0  # значение по умолчанию - начало диалога
Пример #3
0
def set_property(id, value):
    with Vedis(config.db_file) as db:
        try:
            db[id] = value
            return True
        except:
            return False
Пример #4
0
def get_current_state(user_id):
    with Vedis(config.db_file) as db:
        try:
            return db[user_id].decode(
            )  # Если используете Vedis версии ниже, чем 0.7.1, то .decode() НЕ НУЖЕН
        except KeyError:  # Если такого ключа почему-то не оказалось
            return config.States.S_START.value  # значение по умолчанию - начало диалога
Пример #5
0
def get_current_state(user_id, social_network = 'inst'):
    with Vedis(sconfig.last_posts) as db:
        try:
            key = f'{social_network}_{user_id}'
            return db[key].decode()
        except KeyError: 
            return None 
Пример #6
0
def change_current_state(user_id, param, value):
    with Vedis(db_file) as db:
        try:
            db.hset(user_id, param, value)
            print(db.hgetall(user_id))
        except KeyError:
            print('ошибка')
Пример #7
0
def addAccountName(user_id, name):
    with Vedis(config.db_file_users) as db:
        try:
            db[user_id] = {"accName": name, "Network": ""}
            return True
        except:
            return False
Пример #8
0
def get_state(user_id):
    with Vedis(config.db_file) as dba:
        try:
            s=dba[user_id]
            return s.decode()
        except KeyError:  # Agar biron sababga ko'ra bunday kalit bo'lmasa
            return config.States.S_Start.value  # sukut dialog oynasining boshlanishi
def get_current_state(user_id):
    with Vedis(config.db_file) as db:
        try:
            return db[user_id].decode()
        except KeyError:
            # Если пользователь не найден, возвращаем признак старта нового диалога с ботом
            return config.States.S_START.value
Пример #10
0
def set_menu_state(user_id):
    with Vedis(STATES_FILE) as db:
        try:
            db[user_id] = States.S_CHOOSE_MENU_OPT.value
            return True
        except:
            return False
Пример #11
0
def set_state(user_id, value):
    with Vedis(STATES_FILE) as db:
        try:
            db[user_id] = value
            return True
        except:
            return False
Пример #12
0
def set_state(user_id: str, value: str) -> bool:
    with Vedis(db_file) as db:
        try:
            db[user_id] = value
            return True
        except:
            return False
Пример #13
0
def get_data(user_id):
    with Vedis(private_constants.db_file) as db:
        try:
            data = ast.literal_eval(db[user_id].decode('utf-8'))
            return data
        except (KeyError, OSError):
            return {'DATA': {}}
Пример #14
0
def setUserData(user_id, timezone, city, time_notice_status,
                currency_notice_status, weather_notice_status):
    with Vedis(config.db_status) as db:
        h = db.Hash(str(user_id))
        try:
            if time_notice_status == True:
                time_notice_status = '1'
            else:
                time_notice_status = '0'

            if currency_notice_status == True:
                currency_notice_status = '1'
            else:
                currency_notice_status = '0'

            if weather_notice_status == True:
                weather_notice_status = '1'
            else:
                weather_notice_status = '0'

            h['timezone'] = str(timezone)
            h['city'] = str(city)
            h['time_notice_status'] = time_notice_status
            h['currency_notice_status'] = currency_notice_status
            h['weather_notice_status'] = weather_notice_status
            return True
        except:
            return False
Пример #15
0
def return_pages(telegram_id):
    with Vedis(os.path.join(base_dir, 'tech_info.vdb')) as db:
        try:
            user = db.Hash(telegram_id)
            return user['pages'].decode('UTF-8')
        except Exception as err:
            print(err)
Пример #16
0
def get_current_state(user_id, db_name):
    with Vedis(db_name) as db:
        try:
            return db[user_id]
        except KeyError:
            # Вот тут подумать что возвращать.
            return config.States.S_USE_MENU.value
Пример #17
0
def register_next_step(user_id, value):
    with Vedis('vedis/users.db') as db:
        try:
            db[user_id] = value
            return True
        except:
            return False
Пример #18
0
def del_state(user_id):
    with Vedis(conf.db_file) as db:
        try:
            del (db[user_id])
            return True
        except:
            return False
Пример #19
0
def cleareByName(user_id):
    with Vedis(config.db_file_users) as db:
        try:
            db[user_id] = {"accName": "", "Network": ""}
            return True
        except:
            return False
Пример #20
0
def set_property(user_state, value):
    with Vedis(conf.db_file) as db:
        try:
            db[user_state] = value
            return True
        except:
            return False
Пример #21
0
def add_to_end(user_id, value):
    with Vedis(config.db_file) as db:
        try:
            db[user_id] = db[user_id].decode() + value
            return True
        except:
            return False
Пример #22
0
def set_language(telegram_id, language):
    with Vedis(os.path.join(base_dir, 'tech_info.vdb')) as db:
        try:
            user = db.Hash(telegram_id)
            user['language'] = language
        except Exception as err:
            print(err)
Пример #23
0
def get_current_state(user_id, param):
    with Vedis(db_file) as db:
        try:
            return db.hget(user_id, param)

        except KeyError:
            print('ошибка')
Пример #24
0
def set_position(telegram_id, position):
    with Vedis(os.path.join(base_dir, 'tech_info.vdb')) as db:
        try:
            user = db.Hash(telegram_id)
            user['position'] = position
        except Exception as err:
            print(err)
Пример #25
0
def del_state(field):
    with Vedis(config.db_file) as db:
        try:
            del db[field]
            return True  # Если используете Vedis версии ниже, чем 0.7.1, то .decode() НЕ НУЖЕН
        except:  # Если такого ключа почему-то не оказалось
            return False  # значение по умолчанию - начало диалога
Пример #26
0
def set_offset(telegram_id, offset):
    with Vedis(os.path.join(base_dir, 'tech_info.vdb')) as db:
        try:
            user = db.Hash(telegram_id)
            user['offset'] = offset
        except Exception as err:
            print(err)
Пример #27
0
def del_state(field):
    with Vedis(config.db_file) as db:
        try:
            del(db[field])
            return True
        except:
            return False
Пример #28
0
def set_pages(telegram_id, pages):
    with Vedis(os.path.join(base_dir, 'tech_info.vdb')) as db:
        try:
            user = db.Hash(telegram_id)
            user['pages'] = pages
        except Exception as err:
            print(err)
Пример #29
0
def set_state(user_id, value):
    with Vedis(config.db_file) as db:
        try:
            db[user_id] = value
            return True
        except:
            return False
Пример #30
0
def set_state(user_id, state):
    with Vedis(config.db_status) as db:
        try:
            db[user_id] = state
            return True
        except KeyError:
            return False