aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/bot.py b/bot.py
index d49aaa5..f9a664a 100644
--- a/bot.py
+++ b/bot.py
@@ -20,7 +20,8 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
20 ) 20 )
21 21
22from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ReplyKeyboardMarkup, KeyboardButton 22from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ReplyKeyboardMarkup, KeyboardButton
23from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters, ConversationHandler, CallbackContext 23from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters, \
24 ConversationHandler, CallbackContext
24from config import BOT_TOKEN 25from config import BOT_TOKEN
25from foursquare.poi import query_poi 26from foursquare.poi import query_poi
26from dbstore.dbm_store import get_loc 27from dbstore.dbm_store import get_loc
@@ -39,9 +40,9 @@ logging.basicConfig(
39logger = logging.getLogger(__name__) 40logger = logging.getLogger(__name__)
40 41
41MAIN_MENU = ReplyKeyboardMarkup([ 42MAIN_MENU = ReplyKeyboardMarkup([
42 [KeyboardButton(text="Check-in here", request_location=True)], 43 [KeyboardButton(text="Check-in here", request_location=True)],
43 # [KeyboardButton(text="/cancel")], 44 # [KeyboardButton(text="/cancel")],
44 # [KeyboardButton(text="/setting")] 45 # [KeyboardButton(text="/setting")]
45]) 46])
46 47
47SKIP_LOCATION_SEARCH = "skip_location_search" 48SKIP_LOCATION_SEARCH = "skip_location_search"
@@ -50,6 +51,7 @@ SKIP_MENU = InlineKeyboardMarkup([
50 [telegram.InlineKeyboardButton("Skip", callback_data=SKIP_LOCATION_SEARCH)] 51 [telegram.InlineKeyboardButton("Skip", callback_data=SKIP_LOCATION_SEARCH)]
51]) 52])
52 53
54
53# SETTING_MENU = InlineKeyboardMarkup( 55# SETTING_MENU = InlineKeyboardMarkup(
54# [ 56# [
55# [InlineKeyboardButton(text="/tos")], 57# [InlineKeyboardButton(text="/tos")],
@@ -77,9 +79,10 @@ async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
77 context.user_data["longitude"] = update.message.location.longitude 79 context.user_data["longitude"] = update.message.location.longitude
78 80
79 await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove()) 81 await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove())
80 await update.message.reply_text("You can input location search keywords or press skip", 82 prompt_msg = await update.message.reply_text("You can input location search keywords or press skip",
81 reply_markup=SKIP_MENU) 83 reply_markup=SKIP_MENU)
82 84
85 context.user_data["prompt_msg_id"] = prompt_msg.message_id
83 return LOCATION_SEARCH 86 return LOCATION_SEARCH
84 87
85 88
@@ -110,11 +113,18 @@ async def process_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -
110 # reply_markup=MAIN_MENU 113 # reply_markup=MAIN_MENU
111 ) 114 )
112 115
113 await query.message.reply_text("You can continue attaching photos, or press skip to finish", reply_markup=SKIP_MENU) 116 prompt_attach_photo_msg = await query.message.reply_text(
117 "You can continue attaching photos, or press skip to finish", reply_markup=SKIP_MENU)
118 context.user_data["prompt_attach_photo_msg_id"] = prompt_attach_photo_msg.message_id
119
114 return PHOTO 120 return PHOTO
115 121
116 122
117async def location_search_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 123async def location_search_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
124 await context.bot.delete_message(update.effective_chat.id, context.user_data["prompt_msg_id"])
125 # query = update.callback_query
126 # await query.message.delete()
127
118 location_search = update.effective_message.text 128 location_search = update.effective_message.text
119 latitude = context.user_data["latitude"] 129 latitude = context.user_data["latitude"]
120 longitude = context.user_data["longitude"] 130 longitude = context.user_data["longitude"]
@@ -265,9 +275,10 @@ async def media_group_sender(context: CallbackContext):
265 275
266async def photo(update: Update, context: CallbackContext): 276async def photo(update: Update, context: CallbackContext):
267 """Stores the photo and asks for a location.""" 277 """Stores the photo and asks for a location."""
268 global scheduler
269 await update.message.reply_chat_action(telegram.constants.ChatAction.TYPING) 278 await update.message.reply_chat_action(telegram.constants.ChatAction.TYPING)
270 279
280 await context.bot.delete_message(chat_id=update.message.chat_id, message_id=context.user_data["prompt_attach_photo_msg_id"])
281
271 status_id = context.user_data["status_id"] 282 status_id = context.user_data["status_id"]
272 status_content = context.user_data["status_content"] 283 status_content = context.user_data["status_content"]
273 284
@@ -308,9 +319,7 @@ async def photo(update: Update, context: CallbackContext):
308async def skip_photo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 319async def skip_photo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
309 query = update.callback_query 320 query = update.callback_query
310 await query.answer() 321 await query.answer()
311 print("skip photo: ", query.data)
312 322
313 print(context.user_data)
314 await query.delete_message() 323 await query.delete_message()
315 await query.message.reply_text( 324 await query.message.reply_text(
316 text="Done.", reply_markup=MAIN_MENU 325 text="Done.", reply_markup=MAIN_MENU
@@ -330,11 +339,12 @@ def main() -> None:
330 LOCATION: [ 339 LOCATION: [
331 MessageHandler(filters.LOCATION, checkin), 340 MessageHandler(filters.LOCATION, checkin),
332 ], 341 ],
333 WAIT_LOC: [CallbackQueryHandler(process_callback)],
334 LOCATION_SEARCH: [ 342 LOCATION_SEARCH: [
335 MessageHandler(filters.TEXT, location_search_callback), 343 MessageHandler(filters.TEXT, location_search_callback),
336 CallbackQueryHandler(skip_location_search), 344 CallbackQueryHandler(skip_location_search),
337 ], 345 ],
346 WAIT_LOC: [CallbackQueryHandler(process_callback)],
347
338 PHOTO: [MessageHandler(filters.PHOTO, photo), 348 PHOTO: [MessageHandler(filters.PHOTO, photo),
339 CallbackQueryHandler(skip_photo)], 349 CallbackQueryHandler(skip_photo)],
340 }, 350 },
Powered by cgit v1.2.3 (git 2.41.0)