Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Commit

Permalink
Fix/alice recreating user (#289)
Browse files Browse the repository at this point in the history
* Now new_user returns True if user was recreated

* Implemented normal recreation of user in alice
  • Loading branch information
YogurtTheHorse authored Mar 21, 2018
1 parent 2210cf0 commit 0cbf202
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 6 additions & 9 deletions main_alice.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ def main():
# Функция для непосредственной обработки диалога.
def handle_dialog(req, res):
user_id = 'alice' + req['session']['user_id']

if req['session']['new']:
# Это новый пользователь.
# Инициализируем сессию и поприветствуем его.
res['response']['text'] = 'Теперь скажи мне свое имя'
usermanager.new_user(user_id)
return
global text, buttons_list
text = ''
buttons_list = [ ]
Expand All @@ -68,9 +61,13 @@ def reply(txt, buttons=None, photo=None):
buttons_list.extend(btn)
else:
buttons_list.append(btn)

usermanager.message(user_id, reply, req['request']['command'])

if req['session']['new']:
if not usermanager.new_user(user_id, reply=reply):
text = 'Теперь скажи мне свое имя'
else:
usermanager.message(user_id, reply, req['request']['command'])

res['response']['text'] = text.strip()

res['response']['buttons'] = [
Expand Down
3 changes: 3 additions & 0 deletions usermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ def save_user(usr):

def new_user(uid, nickname=None, reply=lambda *x, **y: None):
usr = get_user(uid)
res = False

if usr is None or usr.confirm_restart(reply):
usr = User(uid)
if nickname is not None:
usr.nickname = nickname
reply('Теперь скажи мне свое имя.')
res = True

save_user(usr)
return res

def random_user():
return get_user(random.choice(list(get_telegram_users())))
Expand Down

0 comments on commit 0cbf202

Please sign in to comment.