diff options
author | clarkzjw <[email protected]> | 2023-02-22 11:43:10 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-22 11:43:10 -0800 |
commit | b3786171167337685c21d64f4eed4a7cc1c5b130 (patch) | |
tree | 8d1f31958930f4cc3628c8d5e31ad239bfb4857b | |
parent | eab21831cf13c9afdafc59adde32c85b9716e76b (diff) | |
download | swarm2fediverse-b3786171167337685c21d64f4eed4a7cc1c5b130.tar.gz |
more code formatting
-rw-r--r-- | callback.py | 246 | ||||
-rw-r--r-- | command.py | 11 | ||||
-rw-r--r-- | config.py | 6 | ||||
-rw-r--r-- | prompt/string.py | 11 |
4 files changed, 136 insertions, 138 deletions
diff --git a/callback.py b/callback.py index 6a09421..9b82d78 100644 --- a/callback.py +++ b/callback.py | |||
@@ -13,43 +13,39 @@ from foursquare.poi import query_poi | |||
13 | from toot import mastodon_client | 13 | from toot import mastodon_client |
14 | 14 | ||
15 | 15 | ||
16 | async def callback_skip_media(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 16 | def generate_toot_text(poi_name, poi_locality, poi_region, poi_lat, poi_lon): |
17 | query = update.callback_query | 17 | osm_url = OSM_ENDPOINT.format(poi_lat, poi_lon) |
18 | await query.answer() | 18 | |
19 | 19 | location = "" | |
20 | await query.delete_message() | 20 | if poi_locality: |
21 | await query.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) | 21 | location = poi_locality |
22 | 22 | if poi_region: | |
23 | return ConversationHandler.END | 23 | location += ", " + poi_region |
24 | if location: | ||
25 | return f"I'm at {poi_name} in {location}, {osm_url}" | ||
26 | else: | ||
27 | return f"I'm at {poi_name}, {osm_url}" | ||
24 | 28 | ||
25 | 29 | ||
26 | async def callback_location_sharing(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 30 | async def callback_location_sharing(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
27 | if update.message.venue is not None: | 31 | if update.message.venue is not None: |
28 | fsq_id = update.message.venue.foursquare_id | 32 | context.user_data["fsq_id"] = update.message.venue.foursquare_id |
29 | title = update.message.venue.title | 33 | context.user_data["title"] = update.message.venue.title |
30 | context.user_data["fsq_id"] = fsq_id | ||
31 | context.user_data["title"] = title | ||
32 | context.user_data["latitude"] = update.message.venue.location.latitude | 34 | context.user_data["latitude"] = update.message.venue.location.latitude |
33 | context.user_data["longitude"] = update.message.venue.location.longitude | 35 | context.user_data["longitude"] = update.message.venue.location.longitude |
34 | 36 | ||
35 | poi = get_loc(context.user_data["fsq_id"]) | 37 | poi = get_loc(context.user_data.get("fsq_id")) |
36 | media_id = [] | 38 | content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) |
37 | content = f"I'm at {poi['name']} in {poi['locality']}, {poi['region']}, {poi['osm_url']}" | 39 | status = mastodon_client.status_post(content, visibility=DEFAULT_TOOT_VISIBILITY, media_ids=[]) |
38 | status = mastodon_client.status_post( | ||
39 | content, | ||
40 | visibility="private", | ||
41 | media_ids=media_id) | ||
42 | 40 | ||
43 | context.user_data["status_id"] = status["id"] | 41 | context.user_data[KEY_TOOT_STATUS_ID] = status["id"] |
44 | context.user_data["status_content"] = content | 42 | context.user_data[KEY_TOOT_STATUS_CONTENT] = content |
45 | 43 | ||
46 | await update.message.reply_text( | 44 | await update.message.reply_text(text=f"Selected place: {poi['name']}, \nPosted to Mastodon: {status['url']}", |
47 | text=f"Selected place: {poi['name']}, \nPosted to Mastodon: {status['url']}", | 45 | parse_mode=ParseMode.MARKDOWN) |
48 | parse_mode=ParseMode.MARKDOWN, | ||
49 | ) | ||
50 | 46 | ||
51 | prompt_attach_comment_msg = await update.message.reply_text(PROMPT_ADD_COMMENT, reply_markup=INLINE_SKIP_MENU) | 47 | msg = await update.message.reply_text(PROMPT_ADD_COMMENT, reply_markup=INLINE_SKIP_MENU) |
52 | context.user_data[PROMPT_ADD_COMMENT] = prompt_attach_comment_msg.message_id | 48 | context.user_data[PROMPT_ADD_COMMENT] = msg.message_id |
53 | 49 | ||
54 | return ADD_COMMENT | 50 | return ADD_COMMENT |
55 | else: | 51 | else: |
@@ -57,71 +53,18 @@ async def callback_location_sharing(update: Update, context: ContextTypes.DEFAUL | |||
57 | context.user_data["longitude"] = update.message.location.longitude | 53 | context.user_data["longitude"] = update.message.location.longitude |
58 | 54 | ||
59 | await update.message.reply_text("Searching...", reply_markup=ReplyKeyboardRemove()) | 55 | await update.message.reply_text("Searching...", reply_markup=ReplyKeyboardRemove()) |
60 | prompt_msg = await update.message.reply_text(PROMPT_LOCATION_KEYWORD, reply_markup=INLINE_SKIP_MENU) | 56 | msg = await update.message.reply_text(PROMPT_LOCATION_KEYWORD, reply_markup=INLINE_SKIP_MENU) |
61 | 57 | ||
62 | context.user_data[PROMPT_LOCATION_KEYWORD] = prompt_msg.message_id | 58 | context.user_data[PROMPT_LOCATION_KEYWORD] = msg.message_id |
63 | return LOCATION_SEARCH_KEYWORD | 59 | return LOCATION_SEARCH_KEYWORD |
64 | 60 | ||
65 | 61 | ||
66 | async def callback_manual_location(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | ||
67 | loc = update.effective_message.text | ||
68 | osm_url = OSM_ENDPOINT.format(context.user_data["latitude"], context.user_data["longitude"]) | ||
69 | media_id = [] | ||
70 | content = f"I'm at {loc}, {osm_url}" | ||
71 | status = mastodon_client.status_post( | ||
72 | content, | ||
73 | visibility="private", | ||
74 | media_ids=media_id) | ||
75 | |||
76 | context.user_data["status_id"] = status["id"] | ||
77 | context.user_data["status_content"] = content | ||
78 | |||
79 | await update.message.reply_text( | ||
80 | text=f"Manually selected place: {loc}, \nPosted to Mastodon: {status['url']}", | ||
81 | parse_mode=ParseMode.MARKDOWN, | ||
82 | ) | ||
83 | |||
84 | prompt_attach_comment_msg = await update.message.reply_text(PROMPT_ADD_COMMENT, reply_markup=INLINE_SKIP_MENU) | ||
85 | context.user_data[PROMPT_ADD_COMMENT] = prompt_attach_comment_msg.message_id | ||
86 | |||
87 | return ADD_COMMENT | ||
88 | |||
89 | |||
90 | async def callback_location_confirmation(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | ||
91 | query = update.callback_query | ||
92 | await query.answer() | ||
93 | context.user_data["fsq_id"] = query.data | ||
94 | |||
95 | await query.delete_message() | ||
96 | |||
97 | poi = get_loc(context.user_data["fsq_id"]) | ||
98 | media_id = [] | ||
99 | content = f"I'm at {poi['name']} in {poi['locality']}, {poi['region']}, {poi['osm_url']}" | ||
100 | status = mastodon_client.status_post( | ||
101 | content, | ||
102 | visibility="private", | ||
103 | media_ids=media_id) | ||
104 | |||
105 | context.user_data["status_id"] = status["id"] | ||
106 | context.user_data["status_content"] = content | ||
107 | |||
108 | await query.message.reply_text( | ||
109 | text=f"Selected place: {poi['name']}, `{query.data}`\nPosted to Mastodon: {status['url']}", | ||
110 | parse_mode=ParseMode.MARKDOWN, | ||
111 | ) | ||
112 | |||
113 | prompt_attach_comment_msg = await query.message.reply_text(PROMPT_ADD_COMMENT, reply_markup=INLINE_SKIP_MENU) | ||
114 | context.user_data[PROMPT_ADD_COMMENT] = prompt_attach_comment_msg.message_id | ||
115 | |||
116 | return ADD_COMMENT | ||
117 | |||
118 | |||
119 | async def callback_location_keyword_search(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 62 | async def callback_location_keyword_search(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
120 | await context.bot.delete_message(update.effective_chat.id, context.user_data[PROMPT_LOCATION_KEYWORD]) | 63 | await context.bot.delete_message(update.effective_chat.id, context.user_data.get(PROMPT_LOCATION_KEYWORD)) |
121 | 64 | ||
122 | location_search_keyword = update.effective_message.text | 65 | location_search_keyword = update.effective_message.text |
123 | latitude = context.user_data["latitude"] | 66 | latitude = context.user_data.get("latitude") |
124 | longitude = context.user_data["longitude"] | 67 | longitude = context.user_data.get("longitude") |
125 | 68 | ||
126 | keyboard = [] | 69 | keyboard = [] |
127 | poi_result = query_poi(location_search_keyword, latitude, longitude) | 70 | poi_result = query_poi(location_search_keyword, latitude, longitude) |
@@ -134,13 +77,13 @@ async def callback_location_keyword_search(update: Update, context: ContextTypes | |||
134 | ]) | 77 | ]) |
135 | 78 | ||
136 | if len(keyboard) == 0: | 79 | if len(keyboard) == 0: |
137 | msg = await update.message.reply_text(PROMPT_NO_NEARBY_POI) | 80 | msg = await update.message.reply_text(PROMPT_WAIT_LOCATION_CONFIRMATION_NO_NEARBY_POI) |
138 | else: | 81 | else: |
139 | reply_markup = InlineKeyboardMarkup(keyboard) | ||
140 | context.user_data["location_search"] = location_search_keyword | 82 | context.user_data["location_search"] = location_search_keyword |
141 | msg = await update.message.reply_text(PROMPT_CHOOSE_POI_FROM_LIST, reply_markup=reply_markup) | 83 | msg = await update.message.reply_text(PROMPT_WAIT_LOCATION_CONFIRMATION, |
84 | reply_markup=InlineKeyboardMarkup(keyboard)) | ||
142 | 85 | ||
143 | context.user_data[PROMPT_CHOOSE_POI_FROM_LIST] = msg.message_id | 86 | context.user_data[PROMPT_WAIT_LOCATION_CONFIRMATION] = msg.message_id |
144 | return LOCATION_CONFIRMATION | 87 | return LOCATION_CONFIRMATION |
145 | 88 | ||
146 | 89 | ||
@@ -149,8 +92,8 @@ async def callback_skip_location_keyword(update: Update, context: ContextTypes.D | |||
149 | await query.answer() | 92 | await query.answer() |
150 | 93 | ||
151 | await query.message.delete() | 94 | await query.message.delete() |
152 | latitude = context.user_data["latitude"] | 95 | latitude = context.user_data.get("latitude") |
153 | longitude = context.user_data["longitude"] | 96 | longitude = context.user_data.get("longitude") |
154 | 97 | ||
155 | keyboard = [] | 98 | keyboard = [] |
156 | 99 | ||
@@ -159,21 +102,64 @@ async def callback_skip_location_keyword(update: Update, context: ContextTypes.D | |||
159 | InlineKeyboardButton(poi["name"], callback_data=poi["fsq_id"]), | 102 | InlineKeyboardButton(poi["name"], callback_data=poi["fsq_id"]), |
160 | ]) | 103 | ]) |
161 | 104 | ||
162 | reply_markup = InlineKeyboardMarkup(keyboard) | 105 | await query.message.reply_text(PROMPT_WAIT_LOCATION_CONFIRMATION, reply_markup=InlineKeyboardMarkup(keyboard)) |
163 | await query.message.reply_text(PROMPT_CHOOSE_POI_FROM_LIST, reply_markup=reply_markup) | ||
164 | 106 | ||
165 | return LOCATION_CONFIRMATION | 107 | return LOCATION_CONFIRMATION |
166 | 108 | ||
167 | 109 | ||
110 | async def callback_location_confirmation(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | ||
111 | query = update.callback_query | ||
112 | await query.answer() | ||
113 | |||
114 | context.user_data["fsq_id"] = query.data | ||
115 | await query.delete_message() | ||
116 | |||
117 | poi = get_loc(context.user_data.get("fsq_id")) | ||
118 | content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) | ||
119 | status = mastodon_client.status_post(content, visibility=DEFAULT_TOOT_VISIBILITY, media_ids=[]) | ||
120 | |||
121 | context.user_data[KEY_TOOT_STATUS_ID] = status["id"] | ||
122 | context.user_data[KEY_TOOT_STATUS_CONTENT] = content | ||
123 | |||
124 | await query.message.reply_text( | ||
125 | text=f"Selected place: {poi['name']}, `{query.data}`\nPosted to Mastodon: {status['url']}", | ||
126 | parse_mode=ParseMode.MARKDOWN, | ||
127 | ) | ||
128 | |||
129 | msg = await query.message.reply_text(PROMPT_ADD_COMMENT, reply_markup=INLINE_SKIP_MENU) | ||
130 | context.user_data[PROMPT_ADD_COMMENT] = msg.message_id | ||
131 | |||
132 | return ADD_COMMENT | ||
133 | |||
134 | |||
135 | async def callback_manual_location(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | ||
136 | manual_poi_name = update.effective_message.text | ||
137 | content = generate_toot_text(manual_poi_name, "", "", context.user_data.get("latitude"), | ||
138 | context.user_data.get("longitude")) | ||
139 | status = mastodon_client.status_post(content, visibility=DEFAULT_TOOT_VISIBILITY, media_ids=[]) | ||
140 | |||
141 | context.user_data[KEY_TOOT_STATUS_ID] = status["id"] | ||
142 | context.user_data[KEY_TOOT_STATUS_CONTENT] = content | ||
143 | |||
144 | await update.message.reply_text( | ||
145 | text=f"Manually selected place: {manual_poi_name}, \nPosted to Mastodon: {status['url']}", | ||
146 | parse_mode=ParseMode.MARKDOWN, | ||
147 | ) | ||
148 | |||
149 | msg = await update.message.reply_text(PROMPT_ADD_COMMENT, reply_markup=INLINE_SKIP_MENU) | ||
150 | context.user_data[PROMPT_ADD_COMMENT] = msg.message_id | ||
151 | |||
152 | return ADD_COMMENT | ||
153 | |||
154 | |||
168 | async def callback_add_comment(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 155 | async def callback_add_comment(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
169 | await context.bot.delete_message(update.effective_chat.id, context.user_data[PROMPT_ADD_COMMENT]) | 156 | await context.bot.delete_message(update.effective_chat.id, context.user_data.get(PROMPT_ADD_COMMENT)) |
170 | comment = update.effective_message.text | 157 | comment = update.effective_message.text |
171 | 158 | ||
172 | mastodon_client.status_update( | 159 | mastodon_client.status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID), |
173 | status=f"{comment} " + context.user_data["status_content"], | 160 | status=f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT)) |
174 | id=context.user_data["status_id"]) | ||
175 | 161 | ||
176 | context.user_data["status_content"] = f"{comment} " + context.user_data["status_content"] | 162 | context.user_data[KEY_TOOT_STATUS_CONTENT] = f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT) |
177 | prompt_attach_photo_msg = await update.message.reply_text(PROMPT_ADD_MEDIA, reply_markup=INLINE_SKIP_MENU) | 163 | prompt_attach_photo_msg = await update.message.reply_text(PROMPT_ADD_MEDIA, reply_markup=INLINE_SKIP_MENU) |
178 | context.user_data[PROMPT_ADD_MEDIA] = prompt_attach_photo_msg.message_id | 164 | context.user_data[PROMPT_ADD_MEDIA] = prompt_attach_photo_msg.message_id |
179 | 165 | ||
@@ -181,7 +167,7 @@ async def callback_add_comment(update: Update, context: ContextTypes.DEFAULT_TYP | |||
181 | 167 | ||
182 | 168 | ||
183 | async def callback_skip_comment(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 169 | async def callback_skip_comment(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
184 | await context.bot.delete_message(update.effective_chat.id, context.user_data[PROMPT_ADD_COMMENT]) | 170 | await context.bot.delete_message(update.effective_chat.id, context.user_data.get(PROMPT_ADD_COMMENT)) |
185 | prompt_attach_photo_msg = await context.bot.send_message(chat_id=update.effective_chat.id, | 171 | prompt_attach_photo_msg = await context.bot.send_message(chat_id=update.effective_chat.id, |
186 | text=PROMPT_ADD_MEDIA, | 172 | text=PROMPT_ADD_MEDIA, |
187 | reply_markup=INLINE_SKIP_MENU) | 173 | reply_markup=INLINE_SKIP_MENU) |
@@ -189,45 +175,44 @@ async def callback_skip_comment(update: Update, context: ContextTypes.DEFAULT_TY | |||
189 | return ADD_MEDIA | 175 | return ADD_MEDIA |
190 | 176 | ||
191 | 177 | ||
192 | async def process_media_group(context: CallbackContext): | 178 | async def callback_add_media(update: Update, context: CallbackContext): |
193 | context.job.data = cast(List[MsgDict], context.job.data) | 179 | async def process_media_group(context: CallbackContext): |
194 | 180 | context.job.data = cast(List[MsgDict], context.job.data) | |
195 | media_id = [] | ||
196 | chat_id = context.job.data[0].get("chat_id") | ||
197 | for msg_dict in context.job.data: | ||
198 | if len(media_id) >= 4: | ||
199 | await context.bot.send_message(chat_id=chat_id, text=PROMPT_MAX_PHOTO_REACHED, reply_markup=MAIN_MENU) | ||
200 | return | ||
201 | 181 | ||
202 | file = await context.bot.get_file(msg_dict.get("media_id")) | 182 | _media_id = [] |
203 | img = io.BytesIO() | 183 | chat_id = context.job.data[0].get("chat_id") |
204 | await file.download_to_memory(img) | 184 | for _msg_dict in context.job.data: |
185 | if len(_media_id) >= 4: | ||
186 | await context.bot.send_message(chat_id=chat_id, text=PROMPT_MAX_PHOTO_REACHED, reply_markup=MAIN_MENU) | ||
187 | return | ||
205 | 188 | ||
206 | img.seek(0) | 189 | _file = await context.bot.get_file(_msg_dict.get("media_id")) |
190 | _img = io.BytesIO() | ||
191 | await _file.download_to_memory(_img) | ||
207 | 192 | ||
208 | media = mastodon_client.media_post(img.read(), mime_type="image/jpeg") | 193 | _img.seek(0) |
209 | media_id.append(media["id"]) | ||
210 | 194 | ||
211 | mastodon_client.status_update( | 195 | _media = mastodon_client.media_post(_img.read(), mime_type="image/jpeg") |
212 | status=msg_dict.get("content"), | 196 | _media_id.append(_media["id"]) |
213 | id=msg_dict.get("status_id"), | ||
214 | media_ids=media_id) | ||
215 | 197 | ||
216 | await context.bot.send_message(chat_id=chat_id, text=PROMPT_DONE, reply_markup=MAIN_MENU) | 198 | mastodon_client.status_update( |
199 | status=_msg_dict.get("content"), | ||
200 | id=_msg_dict.get("status_id"), | ||
201 | media_ids=_media_id) | ||
217 | 202 | ||
203 | await context.bot.send_message(chat_id=chat_id, text=PROMPT_DONE, reply_markup=MAIN_MENU) | ||
218 | 204 | ||
219 | async def callback_add_media(update: Update, context: CallbackContext): | ||
220 | await update.message.reply_chat_action(ChatAction.TYPING) | 205 | await update.message.reply_chat_action(ChatAction.TYPING) |
221 | 206 | ||
222 | try: | 207 | try: |
223 | await context.bot.delete_message(chat_id=update.message.chat_id, | 208 | await context.bot.delete_message(chat_id=update.message.chat_id, |
224 | message_id=context.user_data[PROMPT_ADD_MEDIA]) | 209 | message_id=context.user_data.get(PROMPT_ADD_MEDIA)) |
225 | except BadRequest as e: | 210 | except BadRequest as e: |
226 | if "not found" in str(e.message): | 211 | if "not found" in str(e.message): |
227 | pass | 212 | pass |
228 | 213 | ||
229 | status_id = context.user_data["status_id"] | 214 | status_id = context.user_data.get(KEY_TOOT_STATUS_ID) |
230 | status_content = context.user_data["status_content"] | 215 | status_content = context.user_data.get(KEY_TOOT_STATUS_CONTENT) |
231 | 216 | ||
232 | message = update.effective_message | 217 | message = update.effective_message |
233 | context.user_data["media"] = [] | 218 | context.user_data["media"] = [] |
@@ -253,9 +238,16 @@ async def callback_add_media(update: Update, context: CallbackContext): | |||
253 | img.seek(0) | 238 | img.seek(0) |
254 | 239 | ||
255 | media = mastodon_client.media_post(img.read(), mime_type="image/jpeg") | 240 | media = mastodon_client.media_post(img.read(), mime_type="image/jpeg") |
256 | mastodon_client.status_update( | 241 | mastodon_client.status_update(status=status_content, id=status_id, media_ids=media["id"]) |
257 | status=status_content, | ||
258 | id=status_id, | ||
259 | media_ids=media["id"]) | ||
260 | 242 | ||
261 | await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) | 243 | await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) |
244 | |||
245 | |||
246 | async def callback_skip_media(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | ||
247 | query = update.callback_query | ||
248 | await query.answer() | ||
249 | |||
250 | await query.delete_message() | ||
251 | await query.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) | ||
252 | |||
253 | return ConversationHandler.END | ||
@@ -7,14 +7,7 @@ from config import * | |||
7 | 7 | ||
8 | 8 | ||
9 | async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 9 | async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
10 | hello = "Hello, this is `checkin.bot`. \n\n" \ | 10 | await update.message.reply_text(PROMPT_START, parse_mode=ParseMode.MARKDOWN) |
11 | "This is a Telegram bot with functionality similar to Foursquare Swarm, " \ | ||
12 | "but check in and post your location to the Fediverse (Mastodon/Pleroma) instead of Twitter.\n\n" \ | ||
13 | "Aware of privacy concerns, this bot will not store your location data." \ | ||
14 | "*Be safe and cautious when sharing your real time location on the web.* \n\n" \ | ||
15 | "Start using this bot by sharing your location using Telegram context menu to it." | ||
16 | |||
17 | await update.message.reply_text(hello, parse_mode=ParseMode.MARKDOWN) | ||
18 | await update.message.reply_text(PROMPT_CHOOSE_ACTION, reply_markup=MAIN_MENU) | 11 | await update.message.reply_text(PROMPT_CHOOSE_ACTION, reply_markup=MAIN_MENU) |
19 | 12 | ||
20 | return WAIT_LOCATION | 13 | return WAIT_LOCATION |
@@ -25,7 +18,7 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No | |||
25 | 18 | ||
26 | 19 | ||
27 | async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 20 | async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
28 | for prompt in [PROMPT_LOCATION_KEYWORD, PROMPT_CHOOSE_POI_FROM_LIST, PROMPT_ADD_COMMENT, PROMPT_ADD_MEDIA]: | 21 | for prompt in [PROMPT_LOCATION_KEYWORD, PROMPT_WAIT_LOCATION_CONFIRMATION, PROMPT_ADD_COMMENT, PROMPT_ADD_MEDIA]: |
29 | try: | 22 | try: |
30 | if context.user_data.get(prompt): | 23 | if context.user_data.get(prompt): |
31 | await context.bot.delete_message(chat_id=update.message.chat_id, | 24 | await context.bot.delete_message(chat_id=update.message.chat_id, |
@@ -16,6 +16,8 @@ TOOT_CLIENT_ID = config["TOOT"]["CLIENT_ID"] | |||
16 | TOOT_CLIENT_SECRET = config["TOOT"]["CLIENT_SECRET"] | 16 | TOOT_CLIENT_SECRET = config["TOOT"]["CLIENT_SECRET"] |
17 | TOOT_ACCESS_TOKEN = config["TOOT"]["ACCESS_TOKEN"] | 17 | TOOT_ACCESS_TOKEN = config["TOOT"]["ACCESS_TOKEN"] |
18 | 18 | ||
19 | DEFAULT_TOOT_VISIBILITY = "private" | ||
20 | |||
19 | MEDIA_GROUP_TIMEOUT = 3 | 21 | MEDIA_GROUP_TIMEOUT = 3 |
20 | 22 | ||
21 | WAIT_LOCATION, LOCATION_SEARCH_KEYWORD, LOCATION_CONFIRMATION, ADD_MEDIA, ADD_COMMENT = range(5) | 23 | WAIT_LOCATION, LOCATION_SEARCH_KEYWORD, LOCATION_CONFIRMATION, ADD_MEDIA, ADD_COMMENT = range(5) |
@@ -36,3 +38,7 @@ class MsgDict(TypedDict): | |||
36 | status_id: int | 38 | status_id: int |
37 | content: str | 39 | content: str |
38 | chat_id: int | 40 | chat_id: int |
41 | |||
42 | |||
43 | KEY_TOOT_STATUS_ID = "toot_status_id" | ||
44 | KEY_TOOT_STATUS_CONTENT = "toot_status_content" | ||
diff --git a/prompt/string.py b/prompt/string.py index af3363a..9a5a357 100644 --- a/prompt/string.py +++ b/prompt/string.py | |||
@@ -1,9 +1,16 @@ | |||
1 | PROMPT_START = "Hello, this is `checkin.bot`. \n\n" \ | ||
2 | "This is a Telegram bot with functionality similar to Foursquare Swarm, " \ | ||
3 | "but check in and post your location to the Fediverse (Mastodon/Pleroma) instead of Twitter.\n\n" \ | ||
4 | "Aware of privacy concerns, this bot will not store your location data." \ | ||
5 | "*Be safe and cautious when sharing your real time location on the web.* \n\n" \ | ||
6 | "Start using this bot by sharing your location using Telegram context menu to it." | ||
7 | |||
1 | PROMPT_CHOOSE_ACTION = "Use bot keyboard to choose an action" | 8 | PROMPT_CHOOSE_ACTION = "Use bot keyboard to choose an action" |
2 | PROMPT_ADD_COMMENT = "You can continue adding comments, or press skip" | 9 | PROMPT_ADD_COMMENT = "You can continue adding comments, or press skip" |
3 | PROMPT_ADD_MEDIA = "You can continue adding photos, or press skip" | 10 | PROMPT_ADD_MEDIA = "You can continue adding photos, or press skip" |
4 | PROMPT_LOCATION_KEYWORD = "You can input location search keywords or press skip" | 11 | PROMPT_LOCATION_KEYWORD = "You can input location search keywords or press skip" |
5 | PROMPT_NO_NEARBY_POI = "No nearby places found. You can input location name manually" | 12 | PROMPT_WAIT_LOCATION_CONFIRMATION_NO_NEARBY_POI = "No nearby places found. But you can input location name manually." |
6 | PROMPT_CHOOSE_POI_FROM_LIST = "Where are you?" | 13 | PROMPT_WAIT_LOCATION_CONFIRMATION = "Where are you?" |
7 | PROMPT_HELP = "Use /start to test this bot." | 14 | PROMPT_HELP = "Use /start to test this bot." |
8 | PROMPT_CANCELED = "Canceled" | 15 | PROMPT_CANCELED = "Canceled" |
9 | PROMPT_MAX_PHOTO_REACHED = "Cannot attach more than 4 medias, only first 4 will be posted" | 16 | PROMPT_MAX_PHOTO_REACHED = "Cannot attach more than 4 medias, only first 4 will be posted" |