diff options
-rw-r--r-- | bot.py | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -179,6 +179,9 @@ async def media_group_sender(context: CallbackContext): | |||
179 | media_id = [] | 179 | media_id = [] |
180 | chat_id = context.job.data[0].get("chat_id") | 180 | chat_id = context.job.data[0].get("chat_id") |
181 | for msg_dict in context.job.data: | 181 | for msg_dict in context.job.data: |
182 | if len(media_id) >= 4: | ||
183 | print("Cannot attach more than 4 photos") | ||
184 | break | ||
182 | file = await context.bot.get_file(msg_dict.get("media_id")) | 185 | file = await context.bot.get_file(msg_dict.get("media_id")) |
183 | img = io.BytesIO() | 186 | img = io.BytesIO() |
184 | await file.download_to_memory(img) | 187 | await file.download_to_memory(img) |
@@ -218,8 +221,6 @@ async def photo(update: Update, context: CallbackContext): | |||
218 | "content": status_content, | 221 | "content": status_content, |
219 | "chat_id": message.chat_id, | 222 | "chat_id": message.chat_id, |
220 | } | 223 | } |
221 | global jobname | ||
222 | jobname = str(message.media_group_id) | ||
223 | jobs = context.job_queue.get_jobs_by_name(str(message.media_group_id)) | 224 | jobs = context.job_queue.get_jobs_by_name(str(message.media_group_id)) |
224 | if jobs: | 225 | if jobs: |
225 | jobs[0].data.append(msg_dict) | 226 | jobs[0].data.append(msg_dict) |
@@ -234,16 +235,25 @@ async def photo(update: Update, context: CallbackContext): | |||
234 | img = io.BytesIO() | 235 | img = io.BytesIO() |
235 | await file.download_to_memory(img) | 236 | await file.download_to_memory(img) |
236 | img.seek(0) | 237 | img.seek(0) |
237 | context.user_data["photo"].append(img.read()) | ||
238 | 238 | ||
239 | await process_location(update, context) | 239 | media = mastodon_client.media_post(img.read(), mime_type="image/jpeg") |
240 | mastodon_client.status_update( | ||
241 | status=status_content, | ||
242 | id=status_id, | ||
243 | media_ids=media["id"]) | ||
244 | |||
245 | await update.message.reply_text(text="Done", | ||
246 | reply_markup=telegram.ReplyKeyboardMarkup([ | ||
247 | [telegram.KeyboardButton(text="Check in", request_location=True)], | ||
248 | [telegram.KeyboardButton(text="Setting")]])) | ||
240 | 249 | ||
241 | 250 | ||
242 | async def skip_photo(update: Update, context: ContextTypes.DEFAULT_TYPE): | 251 | async def skip_photo(update: Update, context: ContextTypes.DEFAULT_TYPE): |
243 | print(context.user_data) | 252 | print(context.user_data) |
244 | reply_markup = telegram.ReplyKeyboardRemove() | ||
245 | await update.message.reply_text( | 253 | await update.message.reply_text( |
246 | text="Done.", reply_markup=reply_markup | 254 | text="Done.", reply_markup=telegram.ReplyKeyboardMarkup([ |
255 | [telegram.KeyboardButton(text="Check in", request_location=True)], | ||
256 | [telegram.KeyboardButton(text="Setting")]]) | ||
247 | ) | 257 | ) |
248 | return ConversationHandler.END | 258 | return ConversationHandler.END |
249 | 259 | ||
@@ -254,6 +264,7 @@ def main() -> None: | |||
254 | conv_handler = ConversationHandler( | 264 | conv_handler = ConversationHandler( |
255 | entry_points=[ | 265 | entry_points=[ |
256 | CommandHandler("start", start), | 266 | CommandHandler("start", start), |
267 | MessageHandler(filters.LOCATION, checkin), | ||
257 | ], | 268 | ], |
258 | states={ | 269 | states={ |
259 | LOCATION: [ | 270 | LOCATION: [ |
@@ -265,6 +276,7 @@ def main() -> None: | |||
265 | }, | 276 | }, |
266 | fallbacks=[CommandHandler("cancel", cancel)], | 277 | fallbacks=[CommandHandler("cancel", cancel)], |
267 | per_message=False, | 278 | per_message=False, |
279 | allow_reentry=True, | ||
268 | ) | 280 | ) |
269 | 281 | ||
270 | application.add_handler(conv_handler) | 282 | application.add_handler(conv_handler) |