Skip to content
Permalink
Browse files

Fix/alice recreating user (#289)

* Now new_user returns True if user was recreated

* Implemented normal recreation of user in alice
  • Loading branch information...
YogurtTheHorse committed Mar 21, 2018
1 parent 2210cf0 commit 0cbf202536f808227a865695d336d4f99a8befb6
Showing with 9 additions and 9 deletions.
  1. +6 −9 main_alice.py
  2. +3 −0 usermanager.py
@@ -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 = [ ]
@@ -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'] = [
@@ -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())))

0 comments on commit 0cbf202

Please sign in to comment.
You can’t perform that action at this time.