-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_event.py
131 lines (100 loc) · 3.97 KB
/
new_event.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import logging
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import (
CallbackQueryHandler,
CommandHandler,
ContextTypes,
ConversationHandler,
)
logger = logging.getLogger(__name__)
"""
Sport events creation
"""
SELECTING_GAME, SELECTING_DATE, SELECTING_PLACE, SELECTING_PLAYERS = range(4)
async def select_game(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
user = update.message.from_user
logger.info("User %s started creating a new sport event", user.full_name)
# TODO: Add "otro" button that allows to write. See nestedconversationbot example
keyboard = [
[
InlineKeyboardButton(text="Football", callback_data="football"),
InlineKeyboardButton(text="Volleyball", callback_data="volleyball"),
],
[
InlineKeyboardButton(text="Cancelar", callback_data="cancel"),
],
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(text="Tipo de evento", reply_markup=reply_markup)
return SELECTING_GAME
async def select_date(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
query = update.callback_query
await query.answer()
logger.info("User %s selected %s game", query.from_user.full_name, query.data)
# TODO: Add a calendar
keyboard = [
[
InlineKeyboardButton(text="Hoy", callback_data="today"),
InlineKeyboardButton(text="Mañana", callback_data="tomorrow"),
],
[
InlineKeyboardButton(text="Cancelar", callback_data="cancel"),
],
]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(text="Fecha", reply_markup=reply_markup)
return SELECTING_DATE
async def select_place(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
query = update.callback_query
await query.answer()
logger.info("User %s selected %s date", query.from_user.full_name, query.data)
# TODO: Add "otro" button that allows to write. See nestedconversationbot example
keyboard = [
[
InlineKeyboardButton(text="Campito", callback_data="campito"),
InlineKeyboardButton(text="Cañadón", callback_data="cañadon"),
],
[
InlineKeyboardButton(text="Ilunion", callback_data="ilunion"),
],
[
InlineKeyboardButton(text="Cancelar", callback_data="cancel"),
],
]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(text="Lugar", reply_markup=reply_markup)
return SELECTING_PLACE
async def save(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
query = update.callback_query
await query.answer()
logger.info(
"User %s selected %s min players", query.from_user.full_name, query.data
)
logger.info("User %s created a new event", query.from_user.full_name)
# TODO: save here the new event data collected through the flow
await query.edit_message_text(text="Se ha creado un nuevo evento!")
return ConversationHandler.END
async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
user = update.callback_query.from_user
query = update.callback_query
await query.delete_message()
logger.info("User %s cancelled the creation of a new sport event", user.full_name)
return ConversationHandler.END
new_event_conv_handler = ConversationHandler(
entry_points=[CommandHandler("crear", select_game)],
states={
SELECTING_GAME: [
CallbackQueryHandler(cancel, pattern="^cancel$"),
CallbackQueryHandler(select_date),
],
SELECTING_DATE: [
CallbackQueryHandler(cancel, pattern="^cancel$"),
CallbackQueryHandler(select_place),
],
SELECTING_PLACE: [
CallbackQueryHandler(cancel, pattern="^cancel$"),
CallbackQueryHandler(save),
],
},
fallbacks=[CallbackQueryHandler(cancel)],
)