aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--callback.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/callback.py b/callback.py
index 38b0456..2c69fbd 100644
--- a/callback.py
+++ b/callback.py
@@ -40,20 +40,19 @@ async def process_media_group(context: CallbackContext):
40 40
41 media_id = [] 41 media_id = []
42 chat_id = context.job.data[0].get("chat_id") 42 chat_id = context.job.data[0].get("chat_id")
43 for msg_dict in context.job.data: 43 for media_dict in context.job.data:
44 if len(media_id) >= 4: 44 if len(media_id) >= 4:
45 await context.bot.send_message(chat_id=chat_id, text=PROMPT_MAX_PHOTO_REACHED, reply_markup=MAIN_MENU) 45 await context.bot.send_message(chat_id=chat_id, text=PROMPT_MAX_PHOTO_REACHED, reply_markup=MAIN_MENU)
46 return 46 return
47 47
48 file = await context.bot.get_file(msg_dict.get("media_id")) 48 file = await context.bot.get_file(media_dict.get("media_id"))
49 img = await get_img_file_bytes(file) 49 img = await get_img_file_bytes(file)
50 media = mastodon_client.media_post(img, mime_type="image/jpeg") 50 media = mastodon_client.media_post(img, description=media_dict.get("caption"), mime_type="image/jpeg")
51 media_id.append(media["id"]) 51 media_id.append(media["id"])
52 52
53 mastodon_client.status_update( 53 mastodon_client.status_update(id=media_dict.get("status_id"),
54 status=msg_dict.get("content"), 54 status=media_dict.get("content"),
55 id=msg_dict.get("status_id"), 55 media_ids=media_id)
56 media_ids=media_id)
57 56
58 await context.bot.send_message(chat_id=chat_id, text=PROMPT_DONE, reply_markup=MAIN_MENU) 57 await context.bot.send_message(chat_id=chat_id, text=PROMPT_DONE, reply_markup=MAIN_MENU)
59 58
@@ -222,7 +221,7 @@ async def callback_add_media(update: Update, context: CallbackContext):
222 context.user_data["media"] = [] 221 context.user_data["media"] = []
223 if message.media_group_id: 222 if message.media_group_id:
224 media_id = message.photo[-1].file_id if message.photo else message.effective_attachment.file_id 223 media_id = message.photo[-1].file_id if message.photo else message.effective_attachment.file_id
225 msg_dict = { 224 group_media = {
226 "media_id": media_id, 225 "media_id": media_id,
227 "caption": message.caption_html, 226 "caption": message.caption_html,
228 "status_id": status_id, 227 "status_id": status_id,
@@ -231,14 +230,18 @@ async def callback_add_media(update: Update, context: CallbackContext):
231 } 230 }
232 jobs = context.job_queue.get_jobs_by_name(str(message.media_group_id)) 231 jobs = context.job_queue.get_jobs_by_name(str(message.media_group_id))
233 if jobs: 232 if jobs:
234 jobs[0].data.append(msg_dict) 233 jobs[0].data.append(group_media)
235 else: 234 else:
236 context.job_queue.run_once(callback=process_media_group, when=MEDIA_GROUP_TIMEOUT, 235 context.job_queue.run_once(callback=process_media_group,
237 data=[msg_dict], name=str(message.media_group_id)) 236 when=MEDIA_GROUP_TIMEOUT,
237 data=[group_media],
238 name=str(message.media_group_id))
238 else: 239 else:
239 file = await update.message.effective_attachment[-1].get_file() 240 file = await update.message.effective_attachment[-1].get_file()
240 img = await get_img_file_bytes(file) 241 img = await get_img_file_bytes(file)
241 media = mastodon_client.media_post(img, mime_type="image/jpeg") 242 media = mastodon_client.media_post(img,
243 description=message.caption_html,
244 mime_type="image/jpeg")
242 mastodon_client.status_update(status=status_content, id=status_id, media_ids=media["id"]) 245 mastodon_client.status_update(status=status_content, id=status_id, media_ids=media["id"])
243 246
244 await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) 247 await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU)
Powered by cgit v1.2.3 (git 2.41.0)