2019-10-11 21:59:36 +02:00
|
|
|
#!/usr/bin/env python
|
2023-09-09 23:12:30 +02:00
|
|
|
# pylint: disable=unused-argument
|
2019-10-11 21:59:36 +02:00
|
|
|
# This program is dedicated to the public domain under the CC0 license.
|
|
|
|
|
|
|
|
"""
|
|
|
|
First, a few callback functions are defined. Then, those functions are passed to
|
2022-04-24 12:38:09 +02:00
|
|
|
the Application and registered at their respective places.
|
2019-10-11 21:59:36 +02:00
|
|
|
Then, the bot is started and runs until we press Ctrl-C on the command line.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
Example of a bot-user conversation using nested ConversationHandlers.
|
|
|
|
Send /start to initiate the conversation.
|
|
|
|
Press Ctrl-C on the command line or send a signal to the process to stop the
|
|
|
|
bot.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
2022-05-05 09:27:54 +02:00
|
|
|
from typing import Any, Dict, Tuple
|
2019-10-11 21:59:36 +02:00
|
|
|
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
|
2019-10-11 21:59:36 +02:00
|
|
|
from telegram.ext import (
|
2022-05-05 09:27:54 +02:00
|
|
|
Application,
|
|
|
|
CallbackQueryHandler,
|
2019-10-11 21:59:36 +02:00
|
|
|
CommandHandler,
|
2022-05-12 19:36:25 +02:00
|
|
|
ContextTypes,
|
2022-05-05 09:27:54 +02:00
|
|
|
ConversationHandler,
|
2019-10-11 21:59:36 +02:00
|
|
|
MessageHandler,
|
2021-11-20 11:36:18 +01:00
|
|
|
filters,
|
2019-10-11 21:59:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Enable logging
|
|
|
|
logging.basicConfig(
|
|
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
|
|
|
|
)
|
2023-06-07 22:32:04 +02:00
|
|
|
# set higher logging level for httpx to avoid all GET and POST requests being logged
|
|
|
|
logging.getLogger("httpx").setLevel(logging.WARNING)
|
|
|
|
|
2019-10-11 21:59:36 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
# State definitions for top level conversation
|
|
|
|
SELECTING_ACTION, ADDING_MEMBER, ADDING_SELF, DESCRIBING_SELF = map(chr, range(4))
|
|
|
|
# State definitions for second level conversation
|
|
|
|
SELECTING_LEVEL, SELECTING_GENDER = map(chr, range(4, 6))
|
|
|
|
# State definitions for descriptions conversation
|
|
|
|
SELECTING_FEATURE, TYPING = map(chr, range(6, 8))
|
|
|
|
# Meta states
|
|
|
|
STOPPING, SHOWING = map(chr, range(8, 10))
|
|
|
|
# Shortcut for ConversationHandler.END
|
|
|
|
END = ConversationHandler.END
|
|
|
|
|
|
|
|
# Different constants for this example
|
|
|
|
(
|
|
|
|
PARENTS,
|
|
|
|
CHILDREN,
|
|
|
|
SELF,
|
|
|
|
GENDER,
|
|
|
|
MALE,
|
|
|
|
FEMALE,
|
|
|
|
AGE,
|
|
|
|
NAME,
|
|
|
|
START_OVER,
|
|
|
|
FEATURES,
|
|
|
|
CURRENT_FEATURE,
|
|
|
|
CURRENT_LEVEL,
|
|
|
|
) = map(chr, range(10, 22))
|
|
|
|
|
|
|
|
|
|
|
|
# Helper
|
2021-03-13 16:21:03 +01:00
|
|
|
def _name_switcher(level: str) -> Tuple[str, str]:
|
2019-10-11 21:59:36 +02:00
|
|
|
if level == PARENTS:
|
2020-10-31 16:33:34 +01:00
|
|
|
return "Father", "Mother"
|
|
|
|
return "Brother", "Sister"
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Top level conversation callbacks
|
2022-05-12 19:36:25 +02:00
|
|
|
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Select an action: Adding parent/child or show data."""
|
|
|
|
text = (
|
2021-03-28 18:53:44 +02:00
|
|
|
"You may choose to add a family member, yourself, show the gathered data, or end the "
|
|
|
|
"conversation. To abort, simply type /stop."
|
2020-10-09 17:22:07 +02:00
|
|
|
)
|
2021-03-28 18:53:44 +02:00
|
|
|
|
2019-10-11 21:59:36 +02:00
|
|
|
buttons = [
|
2020-10-09 17:22:07 +02:00
|
|
|
[
|
2019-10-11 21:59:36 +02:00
|
|
|
InlineKeyboardButton(text="Add family member", callback_data=str(ADDING_MEMBER)),
|
|
|
|
InlineKeyboardButton(text="Add yourself", callback_data=str(ADDING_SELF)),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(text="Show data", callback_data=str(SHOWING)),
|
|
|
|
InlineKeyboardButton(text="Done", callback_data=str(END)),
|
2020-10-09 17:22:07 +02:00
|
|
|
],
|
2019-10-11 21:59:36 +02:00
|
|
|
]
|
|
|
|
keyboard = InlineKeyboardMarkup(buttons)
|
|
|
|
|
2021-03-28 18:53:44 +02:00
|
|
|
# If we're starting over we don't need to send a new message
|
2019-10-11 21:59:36 +02:00
|
|
|
if context.user_data.get(START_OVER):
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
|
|
|
await update.callback_query.edit_message_text(text=text, reply_markup=keyboard)
|
2019-10-11 21:59:36 +02:00
|
|
|
else:
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.message.reply_text(
|
2021-03-28 18:53:44 +02:00
|
|
|
"Hi, I'm Family Bot and I'm here to help you gather information about your family."
|
2019-10-11 21:59:36 +02:00
|
|
|
)
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.message.reply_text(text=text, reply_markup=keyboard)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
context.user_data[START_OVER] = False
|
|
|
|
return SELECTING_ACTION
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def adding_self(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2021-03-28 18:53:44 +02:00
|
|
|
"""Add information about yourself."""
|
2019-10-11 21:59:36 +02:00
|
|
|
context.user_data[CURRENT_LEVEL] = SELF
|
|
|
|
text = "Okay, please tell me about yourself."
|
|
|
|
button = InlineKeyboardButton(text="Add info", callback_data=str(MALE))
|
|
|
|
keyboard = InlineKeyboardMarkup.from_button(button)
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
|
|
|
await update.callback_query.edit_message_text(text=text, reply_markup=keyboard)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return DESCRIBING_SELF
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def show_data(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Pretty print gathered data."""
|
2020-10-09 17:22:07 +02:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
def pretty_print(data: Dict[str, Any], level: str) -> str:
|
|
|
|
people = data.get(level)
|
2019-10-11 21:59:36 +02:00
|
|
|
if not people:
|
|
|
|
return "\nNo information yet."
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
return_str = ""
|
2019-10-11 21:59:36 +02:00
|
|
|
if level == SELF:
|
2022-04-24 12:38:09 +02:00
|
|
|
for person in data[level]:
|
|
|
|
return_str += f"\nName: {person.get(NAME, '-')}, Age: {person.get(AGE, '-')}"
|
2019-10-11 21:59:36 +02:00
|
|
|
else:
|
|
|
|
male, female = _name_switcher(level)
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
for person in data[level]:
|
2019-10-11 21:59:36 +02:00
|
|
|
gender = female if person[GENDER] == FEMALE else male
|
2022-04-24 12:38:09 +02:00
|
|
|
return_str += (
|
|
|
|
f"\n{gender}: Name: {person.get(NAME, '-')}, Age: {person.get(AGE, '-')}"
|
|
|
|
)
|
|
|
|
return return_str
|
2019-10-11 21:59:36 +02:00
|
|
|
|
2020-10-31 16:33:34 +01:00
|
|
|
user_data = context.user_data
|
2022-04-24 12:38:09 +02:00
|
|
|
text = f"Yourself:{pretty_print(user_data, SELF)}"
|
|
|
|
text += f"\n\nParents:{pretty_print(user_data, PARENTS)}"
|
|
|
|
text += f"\n\nChildren:{pretty_print(user_data, CHILDREN)}"
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
buttons = [[InlineKeyboardButton(text="Back", callback_data=str(END))]]
|
|
|
|
keyboard = InlineKeyboardMarkup(buttons)
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
|
|
|
await update.callback_query.edit_message_text(text=text, reply_markup=keyboard)
|
2020-10-31 16:33:34 +01:00
|
|
|
user_data[START_OVER] = True
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return SHOWING
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def stop(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""End Conversation by command."""
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.message.reply_text("Okay, bye.")
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return END
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def end(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""End conversation from InlineKeyboardButton."""
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
2020-03-28 12:07:23 +01:00
|
|
|
|
2019-10-11 21:59:36 +02:00
|
|
|
text = "See you around!"
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.edit_message_text(text=text)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return END
|
|
|
|
|
|
|
|
|
|
|
|
# Second level conversation callbacks
|
2022-05-12 19:36:25 +02:00
|
|
|
async def select_level(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Choose to add a parent or a child."""
|
|
|
|
text = "You may add a parent or a child. Also you can show the gathered data or go back."
|
|
|
|
buttons = [
|
2020-10-09 17:22:07 +02:00
|
|
|
[
|
2019-10-11 21:59:36 +02:00
|
|
|
InlineKeyboardButton(text="Add parent", callback_data=str(PARENTS)),
|
|
|
|
InlineKeyboardButton(text="Add child", callback_data=str(CHILDREN)),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(text="Show data", callback_data=str(SHOWING)),
|
|
|
|
InlineKeyboardButton(text="Back", callback_data=str(END)),
|
2020-10-09 17:22:07 +02:00
|
|
|
],
|
2019-10-11 21:59:36 +02:00
|
|
|
]
|
|
|
|
keyboard = InlineKeyboardMarkup(buttons)
|
2020-03-28 12:07:23 +01:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
|
|
|
await update.callback_query.edit_message_text(text=text, reply_markup=keyboard)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return SELECTING_LEVEL
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def select_gender(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Choose to add mother or father."""
|
|
|
|
level = update.callback_query.data
|
|
|
|
context.user_data[CURRENT_LEVEL] = level
|
|
|
|
|
|
|
|
text = "Please choose, whom to add."
|
|
|
|
|
|
|
|
male, female = _name_switcher(level)
|
|
|
|
|
|
|
|
buttons = [
|
2020-10-09 17:22:07 +02:00
|
|
|
[
|
2021-03-28 18:53:44 +02:00
|
|
|
InlineKeyboardButton(text=f"Add {male}", callback_data=str(MALE)),
|
|
|
|
InlineKeyboardButton(text=f"Add {female}", callback_data=str(FEMALE)),
|
2019-10-11 21:59:36 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(text="Show data", callback_data=str(SHOWING)),
|
|
|
|
InlineKeyboardButton(text="Back", callback_data=str(END)),
|
2020-10-09 17:22:07 +02:00
|
|
|
],
|
2019-10-11 21:59:36 +02:00
|
|
|
]
|
|
|
|
keyboard = InlineKeyboardMarkup(buttons)
|
2020-03-28 12:07:23 +01:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
|
|
|
await update.callback_query.edit_message_text(text=text, reply_markup=keyboard)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return SELECTING_GENDER
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def end_second_level(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Return to top level conversation."""
|
|
|
|
context.user_data[START_OVER] = True
|
2022-04-24 12:38:09 +02:00
|
|
|
await start(update, context)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return END
|
|
|
|
|
|
|
|
|
|
|
|
# Third level callbacks
|
2022-05-12 19:36:25 +02:00
|
|
|
async def select_feature(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Select a feature to update for the person."""
|
|
|
|
buttons = [
|
2020-10-09 17:22:07 +02:00
|
|
|
[
|
2019-10-11 21:59:36 +02:00
|
|
|
InlineKeyboardButton(text="Name", callback_data=str(NAME)),
|
|
|
|
InlineKeyboardButton(text="Age", callback_data=str(AGE)),
|
|
|
|
InlineKeyboardButton(text="Done", callback_data=str(END)),
|
2020-10-09 17:22:07 +02:00
|
|
|
]
|
2019-10-11 21:59:36 +02:00
|
|
|
]
|
|
|
|
keyboard = InlineKeyboardMarkup(buttons)
|
|
|
|
|
|
|
|
# If we collect features for a new person, clear the cache and save the gender
|
|
|
|
if not context.user_data.get(START_OVER):
|
|
|
|
context.user_data[FEATURES] = {GENDER: update.callback_query.data}
|
|
|
|
text = "Please select a feature to update."
|
2020-03-28 12:07:23 +01:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
|
|
|
await update.callback_query.edit_message_text(text=text, reply_markup=keyboard)
|
2019-10-11 21:59:36 +02:00
|
|
|
# But after we do that, we need to send a new message
|
|
|
|
else:
|
|
|
|
text = "Got it! Please select a feature to update."
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.message.reply_text(text=text, reply_markup=keyboard)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
context.user_data[START_OVER] = False
|
|
|
|
return SELECTING_FEATURE
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def ask_for_input(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Prompt user to input data for selected feature."""
|
|
|
|
context.user_data[CURRENT_FEATURE] = update.callback_query.data
|
|
|
|
text = "Okay, tell me."
|
2020-03-28 12:07:23 +01:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.callback_query.answer()
|
|
|
|
await update.callback_query.edit_message_text(text=text)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return TYPING
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def save_input(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Save input for feature and return to feature selection."""
|
2020-10-31 16:33:34 +01:00
|
|
|
user_data = context.user_data
|
|
|
|
user_data[FEATURES][user_data[CURRENT_FEATURE]] = update.message.text
|
2019-10-11 21:59:36 +02:00
|
|
|
|
2020-10-31 16:33:34 +01:00
|
|
|
user_data[START_OVER] = True
|
2019-10-11 21:59:36 +02:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
return await select_feature(update, context)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def end_describing(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""End gathering of features and return to parent conversation."""
|
2020-10-31 16:33:34 +01:00
|
|
|
user_data = context.user_data
|
|
|
|
level = user_data[CURRENT_LEVEL]
|
|
|
|
if not user_data.get(level):
|
|
|
|
user_data[level] = []
|
|
|
|
user_data[level].append(user_data[FEATURES])
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
# Print upper level menu
|
|
|
|
if level == SELF:
|
2020-10-31 16:33:34 +01:00
|
|
|
user_data[START_OVER] = True
|
2022-04-24 12:38:09 +02:00
|
|
|
await start(update, context)
|
2019-10-11 21:59:36 +02:00
|
|
|
else:
|
2022-04-24 12:38:09 +02:00
|
|
|
await select_level(update, context)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return END
|
|
|
|
|
|
|
|
|
2022-05-12 19:36:25 +02:00
|
|
|
async def stop_nested(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
2019-10-11 21:59:36 +02:00
|
|
|
"""Completely end conversation from within nested conversation."""
|
2022-04-24 12:38:09 +02:00
|
|
|
await update.message.reply_text("Okay, bye.")
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
return STOPPING
|
|
|
|
|
|
|
|
|
2021-03-13 16:21:03 +01:00
|
|
|
def main() -> None:
|
2021-05-27 20:34:58 +02:00
|
|
|
"""Run the bot."""
|
2022-04-24 12:38:09 +02:00
|
|
|
# Create the Application and pass it your bot's token.
|
|
|
|
application = Application.builder().token("TOKEN").build()
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
# Set up third level ConversationHandler (collecting features)
|
|
|
|
description_conv = ConversationHandler(
|
|
|
|
entry_points=[
|
|
|
|
CallbackQueryHandler(
|
|
|
|
select_feature, pattern="^" + str(MALE) + "$|^" + str(FEMALE) + "$"
|
2020-10-09 17:22:07 +02:00
|
|
|
)
|
2019-10-11 21:59:36 +02:00
|
|
|
],
|
|
|
|
states={
|
|
|
|
SELECTING_FEATURE: [
|
|
|
|
CallbackQueryHandler(ask_for_input, pattern="^(?!" + str(END) + ").*$")
|
|
|
|
],
|
2021-11-20 11:36:18 +01:00
|
|
|
TYPING: [MessageHandler(filters.TEXT & ~filters.COMMAND, save_input)],
|
2019-10-11 21:59:36 +02:00
|
|
|
},
|
|
|
|
fallbacks=[
|
|
|
|
CallbackQueryHandler(end_describing, pattern="^" + str(END) + "$"),
|
|
|
|
CommandHandler("stop", stop_nested),
|
|
|
|
],
|
|
|
|
map_to_parent={
|
|
|
|
# Return to second level menu
|
|
|
|
END: SELECTING_LEVEL,
|
2021-03-28 18:53:44 +02:00
|
|
|
# End conversation altogether
|
2019-10-11 21:59:36 +02:00
|
|
|
STOPPING: STOPPING,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Set up second level ConversationHandler (adding a person)
|
|
|
|
add_member_conv = ConversationHandler(
|
|
|
|
entry_points=[CallbackQueryHandler(select_level, pattern="^" + str(ADDING_MEMBER) + "$")],
|
|
|
|
states={
|
|
|
|
SELECTING_LEVEL: [
|
2020-11-23 22:09:29 +01:00
|
|
|
CallbackQueryHandler(select_gender, pattern=f"^{PARENTS}$|^{CHILDREN}$")
|
2020-06-15 18:20:51 +02:00
|
|
|
],
|
2019-10-11 21:59:36 +02:00
|
|
|
SELECTING_GENDER: [description_conv],
|
|
|
|
},
|
|
|
|
fallbacks=[
|
|
|
|
CallbackQueryHandler(show_data, pattern="^" + str(SHOWING) + "$"),
|
|
|
|
CallbackQueryHandler(end_second_level, pattern="^" + str(END) + "$"),
|
|
|
|
CommandHandler("stop", stop_nested),
|
|
|
|
],
|
|
|
|
map_to_parent={
|
|
|
|
# After showing data return to top level menu
|
|
|
|
SHOWING: SHOWING,
|
|
|
|
# Return to top level menu
|
|
|
|
END: SELECTING_ACTION,
|
2021-03-28 18:53:44 +02:00
|
|
|
# End conversation altogether
|
2019-10-11 21:59:36 +02:00
|
|
|
STOPPING: END,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Set up top level ConversationHandler (selecting action)
|
2021-03-28 18:53:44 +02:00
|
|
|
# Because the states of the third level conversation map to the ones of the second level
|
2020-05-04 16:59:51 +02:00
|
|
|
# conversation, we need to make sure the top level conversation can also handle them
|
|
|
|
selection_handlers = [
|
|
|
|
add_member_conv,
|
|
|
|
CallbackQueryHandler(show_data, pattern="^" + str(SHOWING) + "$"),
|
|
|
|
CallbackQueryHandler(adding_self, pattern="^" + str(ADDING_SELF) + "$"),
|
|
|
|
CallbackQueryHandler(end, pattern="^" + str(END) + "$"),
|
|
|
|
]
|
2019-10-11 21:59:36 +02:00
|
|
|
conv_handler = ConversationHandler(
|
|
|
|
entry_points=[CommandHandler("start", start)],
|
|
|
|
states={
|
|
|
|
SHOWING: [CallbackQueryHandler(start, pattern="^" + str(END) + "$")],
|
2024-09-14 08:16:39 +02:00
|
|
|
SELECTING_ACTION: selection_handlers, # type: ignore[dict-item]
|
|
|
|
SELECTING_LEVEL: selection_handlers, # type: ignore[dict-item]
|
2019-10-11 21:59:36 +02:00
|
|
|
DESCRIBING_SELF: [description_conv],
|
2020-05-04 16:59:51 +02:00
|
|
|
STOPPING: [CommandHandler("start", start)],
|
2019-10-11 21:59:36 +02:00
|
|
|
},
|
|
|
|
fallbacks=[CommandHandler("stop", stop)],
|
|
|
|
)
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
application.add_handler(conv_handler)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
# Run the bot until the user presses Ctrl-C
|
2023-06-04 17:11:58 +02:00
|
|
|
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
2019-10-11 21:59:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|