diff options
-rw-r--r-- | callback.py | 25 | ||||
-rw-r--r-- | 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): | |||
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 | ||
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 | |||
3 | asgiref==3.6.0 | 3 | asgiref==3.6.0 |
4 | blurhash==1.1.4 | 4 | blurhash==1.1.4 |
5 | certifi==2022.12.7 | 5 | certifi==2022.12.7 |
6 | cffi==1.15.1 | ||
6 | charset-normalizer==3.0.1 | 7 | charset-normalizer==3.0.1 |
7 | click==8.1.3 | 8 | click==8.1.3 |
9 | crypto==1.4.1 | ||
10 | cryptography==39.0.1 | ||
8 | decorator==5.1.1 | 11 | decorator==5.1.1 |
9 | greenlet==2.0.2 | 12 | greenlet==2.0.2 |
10 | h11==0.14.0 | 13 | h11==0.14.0 |
@@ -14,16 +17,21 @@ httpcore==0.16.3 | |||
14 | httpx==0.23.3 | 17 | httpx==0.23.3 |
15 | hyperframe==6.0.1 | 18 | hyperframe==6.0.1 |
16 | idna==3.4 | 19 | idna==3.4 |
17 | Mastodon.py==1.8.0 | 20 | Mastodon.py @ git+https://cgit.jinwei.me/clarkzjw/mastodon.py@503d58d226c52901532067d3dcb5a7814699f7fb |
21 | Naked==0.1.32 | ||
18 | peewee==3.15.4 | 22 | peewee==3.15.4 |
19 | Pillow==9.4.0 | 23 | Pillow==9.4.0 |
24 | pycparser==2.21 | ||
25 | pycrypto==2.6.1 | ||
20 | python-dateutil==2.8.2 | 26 | python-dateutil==2.8.2 |
21 | python-magic==0.4.27 | 27 | python-magic==0.4.27 |
22 | python-telegram-bot==20.1 | 28 | python-telegram-bot==20.1 |
23 | pytz==2022.7.1 | 29 | pytz==2022.7.1 |
24 | pytz-deprecation-shim==0.1.0.post0 | 30 | pytz-deprecation-shim==0.1.0.post0 |
31 | PyYAML==6.0 | ||
25 | requests==2.28.2 | 32 | requests==2.28.2 |
26 | rfc3986==1.5.0 | 33 | rfc3986==1.5.0 |
34 | shellescape==3.8.1 | ||
27 | six==1.16.0 | 35 | six==1.16.0 |
28 | sniffio==1.3.0 | 36 | sniffio==1.3.0 |
29 | SQLAlchemy==2.0.4 | 37 | SQLAlchemy==2.0.4 |