Skip to content

Commit

Permalink
Update FSM example.
Browse files Browse the repository at this point in the history
  • Loading branch information
JrooTJunior committed Sep 21, 2018
1 parent 2c749e4 commit 88c5b3a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 158 deletions.
16 changes: 0 additions & 16 deletions docs/source/examples/finite_state_machine_example_2.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/source/examples/index.rst
Expand Up @@ -9,7 +9,6 @@ Examples
adwanced_executor_example
proxy_and_emojize
finite_state_machine_example
finite_state_machine_example_2
throtling_example
i18n_example
regexp_commands_filter_example
Expand Down
30 changes: 15 additions & 15 deletions examples/finite_state_machine_example.py
Expand Up @@ -59,9 +59,10 @@ async def process_name(message: types.Message, state: FSMContext):
"""
Process user name
"""
await Form.next()
await state.update_data(name=message.text)
async with state.proxy() as data:
data['name'] = message.text

await Form.next()
await message.reply("How old are you?")


Expand Down Expand Up @@ -98,22 +99,21 @@ async def failed_process_gender(message: types.Message):

@dp.message_handler(state=Form.gender)
async def process_gender(message: types.Message, state: FSMContext):
data = await state.get_data()
data['gender'] = message.text
async with state.proxy() as data:
data['gender'] = message.text

# Remove keyboard
markup = types.ReplyKeyboardRemove()
# Remove keyboard
markup = types.ReplyKeyboardRemove()

# And send message
await bot.send_message(message.chat.id, md.text(
md.text('Hi! Nice to meet you,', md.bold(data['name'])),
md.text('Age:', data['age']),
md.text('Gender:', data['gender']),
sep='\n'), reply_markup=markup, parse_mode=ParseMode.MARKDOWN)
# And send message
await bot.send_message(message.chat.id, md.text(
md.text('Hi! Nice to meet you,', md.bold(data['name'])),
md.text('Age:', data['age']),
md.text('Gender:', data['gender']),
sep='\n'), reply_markup=markup, parse_mode=ParseMode.MARKDOWN)

# Finish conversation
# WARNING! This method will destroy all data in storage for current user!
await state.finish()
# Finish conversation
data.state = None


if __name__ == '__main__':
Expand Down
126 changes: 0 additions & 126 deletions examples/finite_state_machine_example_2.py

This file was deleted.

0 comments on commit 88c5b3a

Please sign in to comment.