aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-23 20:51:02 -0800
committerclarkzjw <[email protected]>2023-02-23 20:51:02 -0800
commit1e448735a15b633cb7743a01ce6249a506196ab8 (patch)
treea6cb3c4c7b2c8b38e820ed6727342efad02b0ee9 /callback.py
parentaf56ead63269aff81c7b23251fca3ca650eb94fe (diff)
parent22004ca84f838ec16ae43abc9ab2b185fef5bb2e (diff)
downloadswarm2fediverse-1e448735a15b633cb7743a01ce6249a506196ab8.tar.gz
Merge branch 'feature/update_menu'
bot: fix mastodon.py missing in status.update()
Diffstat (limited to 'callback.py')
-rw-r--r--callback.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/callback.py b/callback.py
index ecce2bf..1abef5e 100644
--- a/callback.py
+++ b/callback.py
@@ -57,6 +57,11 @@ async def process_media_group(context: CallbackContext):
57 mastodon_client = get_mastodon_client(context.user_data["user_id"]) 57 mastodon_client = get_mastodon_client(context.user_data["user_id"])
58 media_id = [] 58 media_id = []
59 chat_id = context.job.data[0].get("chat_id") 59 chat_id = context.job.data[0].get("chat_id")
60
61 with db.connection_context():
62 u = User.get(User.telegram_user_id == context.user_data["user_id"])
63 content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain"
64
60 for media_dict in context.job.data: 65 for media_dict in context.job.data:
61 if len(media_id) >= 4: 66 if len(media_id) >= 4:
62 await context.bot.send_message(chat_id=chat_id, text=PROMPT_MAX_PHOTO_REACHED, reply_markup=MAIN_MENU) 67 await context.bot.send_message(chat_id=chat_id, text=PROMPT_MAX_PHOTO_REACHED, reply_markup=MAIN_MENU)
@@ -69,6 +74,7 @@ async def process_media_group(context: CallbackContext):
69 74
70 mastodon_client.status_update(id=media_dict.get("status_id"), 75 mastodon_client.status_update(id=media_dict.get("status_id"),
71 status=media_dict.get("content"), 76 status=media_dict.get("content"),
77 content_type=content_type,
72 media_ids=media_id) 78 media_ids=media_id)
73 79
74 await context.bot.send_message(chat_id=chat_id, text=PROMPT_DONE, reply_markup=MAIN_MENU) 80 await context.bot.send_message(chat_id=chat_id, text=PROMPT_DONE, reply_markup=MAIN_MENU)
@@ -118,8 +124,6 @@ async def callback_location_sharing(update: Update, context: ContextTypes.DEFAUL
118 poi = query_poi_by_fsq_id(context.user_data.get("fsq_id")) 124 poi = query_poi_by_fsq_id(context.user_data.get("fsq_id"))
119 content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) 125 content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"])
120 126
121 # TODO
122 # mastodon.py status_update() currently does not support content_type parameter
123 with db.connection_context(): 127 with db.connection_context():
124 u = User.get(User.telegram_user_id == update.effective_user.id) 128 u = User.get(User.telegram_user_id == update.effective_user.id)
125 content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" 129 content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain"
@@ -262,9 +266,14 @@ async def callback_add_comment(update: Update, context: ContextTypes.DEFAULT_TYP
262 context.user_data["user_id"] = update.effective_user.id 266 context.user_data["user_id"] = update.effective_user.id
263 await context.bot.delete_message(update.effective_chat.id, context.user_data.get(PROMPT_ADD_COMMENT)) 267 await context.bot.delete_message(update.effective_chat.id, context.user_data.get(PROMPT_ADD_COMMENT))
264 268
269 with db.connection_context():
270 u = User.get(User.telegram_user_id == context.user_data["user_id"])
271 content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain"
272
265 comment = update.effective_message.text 273 comment = update.effective_message.text
266 get_mastodon_client(update.effective_user.id).status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID), 274 get_mastodon_client(update.effective_user.id).status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID),
267 status=f"{comment} " + context.user_data.get( 275 content_type=content_type,
276 status=f"{comment}\n\n" + context.user_data.get(
268 KEY_TOOT_STATUS_CONTENT)) 277 KEY_TOOT_STATUS_CONTENT))
269 context.user_data[KEY_TOOT_STATUS_CONTENT] = f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT) 278 context.user_data[KEY_TOOT_STATUS_CONTENT] = f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT)
270 279
@@ -317,7 +326,15 @@ async def callback_add_media(update: Update, context: CallbackContext):
317 media = mastodon_client.media_post(img, 326 media = mastodon_client.media_post(img,
318 description=message.caption_html, 327 description=message.caption_html,
319 mime_type="image/jpeg") 328 mime_type="image/jpeg")
320 mastodon_client.status_update(status=status_content, id=status_id, media_ids=media["id"]) 329
330 with db.connection_context():
331 u = User.get(User.telegram_user_id == context.user_data["user_id"])
332 content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain"
333
334 mastodon_client.status_update(status=status_content,
335 id=status_id,
336 content_type=content_type,
337 media_ids=media["id"])
321 338
322 await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) 339 await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU)
323 340
Powered by cgit v1.2.3 (git 2.41.0)