aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-21 21:36:12 -0800
committerclarkzjw <[email protected]>2023-02-21 21:36:12 -0800
commit09536a76b573841675c76d0fc36901eed45582b8 (patch)
treec45bdde0dd395ace8477b57672dac9a5bd457693
parent360eeec8df66ca0402739463ac0fdf9b5d5910f3 (diff)
downloadswarm2fediverse-09536a76b573841675c76d0fc36901eed45582b8.tar.gz
handle telegram built venue location
-rw-r--r--bot.py48
1 files changed, 41 insertions, 7 deletions
diff --git a/bot.py b/bot.py
index f9a664a..05483ca 100644
--- a/bot.py
+++ b/bot.py
@@ -6,6 +6,7 @@ import logging
6import io 6import io
7import telegram.constants 7import telegram.constants
8from telegram import __version__ as TG_VER 8from telegram import __version__ as TG_VER
9from pprint import pprint
9 10
10try: 11try:
11 from telegram import __version_info__ 12 from telegram import __version_info__
@@ -75,15 +76,48 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
75 76
76 77
77async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 78async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
78 context.user_data["latitude"] = update.message.location.latitude 79 pprint(update.message.location)
79 context.user_data["longitude"] = update.message.location.longitude 80 if update.message.venue is not None:
81 fsq_id = update.message.venue.foursquare_id
82 title = update.message.venue.title
83 context.user_data["fsq_id"] = fsq_id
84 context.user_data["title"] = title
85 context.user_data["latitude"] = update.message.venue.location.latitude
86 context.user_data["longitude"] = update.message.venue.location.longitude
87
88 poi = get_loc(context.user_data["fsq_id"])
89 media_id = []
90 content = f"I'm at {poi['name']} in {poi['locality']}, {poi['region']}, {poi['osm_url']}"
91 status = mastodon_client.status_post(
92 content,
93 visibility="private",
94 media_ids=media_id)
95
96 context.user_data["status_id"] = status["id"]
97 context.user_data["status_content"] = content
98
99 print("status_id", context.user_data["status_id"])
100
101 await update.message.reply_text(
102 text=f"Selected place: {poi['name']}, \nPosted to Mastodon: {status['url']}",
103 parse_mode=telegram.constants.ParseMode.MARKDOWN,
104 )
105
106 prompt_attach_photo_msg = await update.message.reply_text(
107 "You can continue attaching photos, or press skip to finish", reply_markup=SKIP_MENU)
108 context.user_data["prompt_attach_photo_msg_id"] = prompt_attach_photo_msg.message_id
109
110 return PHOTO
111 else:
112 context.user_data["latitude"] = update.message.location.latitude
113 context.user_data["longitude"] = update.message.location.longitude
80 114
81 await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove()) 115 await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove())
82 prompt_msg = await update.message.reply_text("You can input location search keywords or press skip", 116 prompt_msg = await update.message.reply_text("You can input location search keywords or press skip",
83 reply_markup=SKIP_MENU) 117 reply_markup=SKIP_MENU)
84 118
85 context.user_data["prompt_msg_id"] = prompt_msg.message_id 119 context.user_data["prompt_msg_id"] = prompt_msg.message_id
86 return LOCATION_SEARCH 120 return LOCATION_SEARCH
87 121
88 122
89async def process_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 123async def process_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
Powered by cgit v1.2.3 (git 2.41.0)