mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Update custom_states.py
This commit is contained in:
parent
8dcfa0c282
commit
fc347ae166
@ -17,7 +17,7 @@ def start_ex(message):
|
|||||||
"""
|
"""
|
||||||
Start command. Here we are starting state
|
Start command. Here we are starting state
|
||||||
"""
|
"""
|
||||||
bot.set_state(message.chat.id, 1)
|
bot.set_state(message.from_user.id, 1)
|
||||||
bot.send_message(message.chat.id, 'Hi, write me a name')
|
bot.send_message(message.chat.id, 'Hi, write me a name')
|
||||||
|
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ def any_state(message):
|
|||||||
Cancel state
|
Cancel state
|
||||||
"""
|
"""
|
||||||
bot.send_message(message.chat.id, "Your state was cancelled.")
|
bot.send_message(message.chat.id, "Your state was cancelled.")
|
||||||
bot.delete_state(message.chat.id)
|
bot.delete_state(message.from_user.id)
|
||||||
|
|
||||||
@bot.message_handler(state=MyStates.name)
|
@bot.message_handler(state=MyStates.name)
|
||||||
def name_get(message):
|
def name_get(message):
|
||||||
@ -36,8 +36,8 @@ def name_get(message):
|
|||||||
State 1. Will process when user's state is 1.
|
State 1. Will process when user's state is 1.
|
||||||
"""
|
"""
|
||||||
bot.send_message(message.chat.id, f'Now write me a surname')
|
bot.send_message(message.chat.id, f'Now write me a surname')
|
||||||
bot.set_state(message.chat.id, 2)
|
bot.set_state(message.from_user.id, 2)
|
||||||
with bot.retrieve_data(message.chat.id) as data:
|
with bot.retrieve_data(message.from_user.id) as data:
|
||||||
data['name'] = message.text
|
data['name'] = message.text
|
||||||
|
|
||||||
|
|
||||||
@ -47,16 +47,16 @@ def ask_age(message):
|
|||||||
State 2. Will process when user's state is 2.
|
State 2. Will process when user's state is 2.
|
||||||
"""
|
"""
|
||||||
bot.send_message(message.chat.id, "What is your age?")
|
bot.send_message(message.chat.id, "What is your age?")
|
||||||
bot.set_state(message.chat.id, 3)
|
bot.set_state(message.from_user.id, 3)
|
||||||
with bot.retrieve_data(message.chat.id) as data:
|
with bot.retrieve_data(message.from_user.id) as data:
|
||||||
data['surname'] = message.text
|
data['surname'] = message.text
|
||||||
|
|
||||||
# result
|
# result
|
||||||
@bot.message_handler(state=MyStates.age, is_digit=True)
|
@bot.message_handler(state=MyStates.age, is_digit=True)
|
||||||
def ready_for_answer(message):
|
def ready_for_answer(message):
|
||||||
with bot.retrieve_data(message.chat.id) as data:
|
with bot.retrieve_data(message.from_user.id) as data:
|
||||||
bot.send_message(message.chat.id, "Ready, take a look:\n<b>Name: {name}\nSurname: {surname}\nAge: {age}</b>".format(name=data['name'], surname=data['surname'], age=message.text), parse_mode="html")
|
bot.send_message(message.chat.id, "Ready, take a look:\n<b>Name: {name}\nSurname: {surname}\nAge: {age}</b>".format(name=data['name'], surname=data['surname'], age=message.text), parse_mode="html")
|
||||||
bot.delete_state(message.chat.id)
|
bot.delete_state(message.from_user.id)
|
||||||
|
|
||||||
#incorrect number
|
#incorrect number
|
||||||
@bot.message_handler(state=MyStates.age, is_digit=False)
|
@bot.message_handler(state=MyStates.age, is_digit=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user