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