Skip to content

Commit

Permalink
modified
Browse files Browse the repository at this point in the history
  • Loading branch information
elizaveta-andreeva committed Aug 23, 2023
1 parent d1da0da commit 96b81a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
26 changes: 9 additions & 17 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
change_user_pronoun,
get_user_pronoun,
get_user_chosen_name,
push_user_mode, push_user_initial_reason,
push_user_mode,
push_user_initial_reason,
get_user_initial_reason, get_user_initial_reason_flag, set_user_initial_reason_flag,
)
from keyboard import (
mood_keyboard,
Expand All @@ -55,8 +57,6 @@

PREPARE, TYPING, SELECT_YES_NO, MENU = "PREPARE", "TYPING", "SELECT_YES_NO", "MENU"

MODE = "" # "WAITING FOR NAME" / "NAME RECEIVED" / "WAITING FOR INITIAL REASON" / "INITIAL REASON RECEIVED"


# def start(update: Update, context: CallbackContext) -> int:
def start(update: Update, context: CallbackContext) -> str:
Expand All @@ -65,9 +65,6 @@ def start(update: Update, context: CallbackContext) -> str:
user = init_user(update.effective_user)
set_last_usage(user)

global MODE
MODE = "WAITING FOR NAME"

dialog(update, text='Здравствуйте! Я бот-психолог. Как можно обращаться к вам?')


Expand Down Expand Up @@ -103,7 +100,7 @@ def button(update: Update, context: CallbackContext) -> str:
elif query.data.startswith('c_'):
handle_conversation_mode(update, context, user, query)
elif query.data.startswith('q_'):
handle_questions(update, query)
handle_questions(update, user, query)
return ''


Expand Down Expand Up @@ -173,8 +170,7 @@ def handle_mood(update, query):
schedule.save()


def handle_questions(update, query):
global MODE
def handle_questions(update, user, query):
if query.data == 'q_1':
dialog(update, 'Если тебе интересно, то подробнее о методе можно прочитать в книгах Девид Бернса'
' \"Терапия Настроения\" и Роберта Лихи \"Свобода от тревоги\".')
Expand All @@ -194,11 +190,9 @@ def handle_questions(update, query):
dialog(update, 'Если у тебя нет вопросов, мы можем начать. Расскажи, пожалуйста, максимально подробно,'
' почему ты решил_а обратиться ко мне сегодня, о чем бы тебе хотелось поговорить? '
'Наш разговор совершенно конфиденциален')
MODE = "WAITING FOR INITIAL REASON"

set_user_initial_reason_flag(user, True)

def text_processing(update: Update, context: CallbackContext):
global MODE
user = init_user(update.effective_user)
if update.message.text == VALUES['menu_share_event']:
# TODO обработка выбора "поделиться событием"
Expand All @@ -207,17 +201,15 @@ def text_processing(update: Update, context: CallbackContext):
change_focus(update, context)
elif update.message.text == VALUES['menu_help']:
help_bot(update, context)
elif MODE == "WAITING FOR NAME":
elif get_user_chosen_name(user) == ' ':
chosen_name = update.message.text
push_user_chosen_name(user, chosen_name)
ask_user_pronoun(update, context)
MODE = "NAME RECEIVED"
elif MODE == "WAITING FOR INITIAL REASON":
elif get_user_initial_reason_flag(user):
reason = update.message.text
push_user_initial_reason(user, reason)
MODE = "INITIAL REASON RECEIVED"
set_user_initial_reason_flag(user, False)
else:
push_user_chosen_name(user, ' ')
engine_callback(update, context)


Expand Down
13 changes: 13 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class User(MongoModel):
is_bot = fields.BooleanField()
language_code = fields.CharField()
initial_reason = fields.CharField()
initial_reason_flag = fields.BooleanField() # True - ready to set initial_reason
focuses = fields.ListField(fields.DictField())
feelings = fields.ListField(fields.DictField())
ready_flag = fields.BooleanField()
Expand Down Expand Up @@ -132,6 +133,8 @@ def init_user(user) -> User:
is_bot=user.is_bot,
username=user.username,
chosen_name = ' ',
initial_reason = ' ',
initial_reason_flag = False,
language_code=user.language_code,
).save()

Expand Down Expand Up @@ -366,6 +369,16 @@ def set_user_ready_flag(user, flag):
db_user.save()


def set_user_initial_reason_flag(user, flag):
db_user = init_user(user)
db_user.initial_reason_flag = flag
db_user.save()


def get_user_initial_reason_flag(user):
db_user = init_user(user)
return db_user.initial_reason_flag

def set_schedule_is_on_flag(schedule, flag):
schedule.is_on = flag
schedule.save()
Expand Down

0 comments on commit 96b81a9

Please sign in to comment.