From 22004ca84f838ec16ae43abc9ab2b185fef5bb2e Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 23 Feb 2023 20:50:42 -0800 Subject: fix mastodon.py missing in status.update() --- callback.py | 25 +++++++++++++++++++++---- requirements.txt | 10 +++++++++- 2 files changed, 30 insertions(+), 5 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): mastodon_client = get_mastodon_client(context.user_data["user_id"]) media_id = [] chat_id = context.job.data[0].get("chat_id") + + with db.connection_context(): + u = User.get(User.telegram_user_id == context.user_data["user_id"]) + content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + for media_dict in context.job.data: if len(media_id) >= 4: 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): mastodon_client.status_update(id=media_dict.get("status_id"), status=media_dict.get("content"), + content_type=content_type, media_ids=media_id) 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 poi = query_poi_by_fsq_id(context.user_data.get("fsq_id")) content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) - # TODO - # mastodon.py status_update() currently does not support content_type parameter with db.connection_context(): u = User.get(User.telegram_user_id == update.effective_user.id) 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 context.user_data["user_id"] = update.effective_user.id await context.bot.delete_message(update.effective_chat.id, context.user_data.get(PROMPT_ADD_COMMENT)) + with db.connection_context(): + u = User.get(User.telegram_user_id == context.user_data["user_id"]) + content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + comment = update.effective_message.text get_mastodon_client(update.effective_user.id).status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID), - status=f"{comment} " + context.user_data.get( + content_type=content_type, + status=f"{comment}\n\n" + context.user_data.get( KEY_TOOT_STATUS_CONTENT)) context.user_data[KEY_TOOT_STATUS_CONTENT] = f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT) @@ -317,7 +326,15 @@ async def callback_add_media(update: Update, context: CallbackContext): media = mastodon_client.media_post(img, description=message.caption_html, mime_type="image/jpeg") - mastodon_client.status_update(status=status_content, id=status_id, media_ids=media["id"]) + + with db.connection_context(): + u = User.get(User.telegram_user_id == context.user_data["user_id"]) + content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + + mastodon_client.status_update(status=status_content, + id=status_id, + content_type=content_type, + media_ids=media["id"]) await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) diff --git a/requirements.txt b/requirements.txt index c3166b6..d1e0036 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,8 +3,11 @@ APScheduler==3.10.0 asgiref==3.6.0 blurhash==1.1.4 certifi==2022.12.7 +cffi==1.15.1 charset-normalizer==3.0.1 click==8.1.3 +crypto==1.4.1 +cryptography==39.0.1 decorator==5.1.1 greenlet==2.0.2 h11==0.14.0 @@ -14,16 +17,21 @@ httpcore==0.16.3 httpx==0.23.3 hyperframe==6.0.1 idna==3.4 -Mastodon.py==1.8.0 +Mastodon.py @ git+https://cgit.jinwei.me/clarkzjw/mastodon.py@503d58d226c52901532067d3dcb5a7814699f7fb +Naked==0.1.32 peewee==3.15.4 Pillow==9.4.0 +pycparser==2.21 +pycrypto==2.6.1 python-dateutil==2.8.2 python-magic==0.4.27 python-telegram-bot==20.1 pytz==2022.7.1 pytz-deprecation-shim==0.1.0.post0 +PyYAML==6.0 requests==2.28.2 rfc3986==1.5.0 +shellescape==3.8.1 six==1.16.0 sniffio==1.3.0 SQLAlchemy==2.0.4 -- cgit v1.2.3