aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'callback.py')
-rw-r--r--callback.py54
1 files changed, 45 insertions, 9 deletions
diff --git a/callback.py b/callback.py
index 5fe4593..cec6188 100644
--- a/callback.py
+++ b/callback.py
@@ -13,6 +13,8 @@ from dbstore.peewee_store import User, db, TOOT_VISIBILITY_PRIVATE, TOOT_VISIBIL
13import uuid 13import uuid
14from mastodon import Mastodon 14from mastodon import Mastodon
15from util import decrypt, check_user 15from util import decrypt, check_user
16from datetime import datetime, timedelta
17from config import KEY_IS_SCHEDULED_TOOT
16 18
17 19
18def generate_uuid(): 20def generate_uuid():
@@ -131,9 +133,15 @@ async def callback_location_sharing(update: Update, context: ContextTypes.DEFAUL
131 133
132 content_type = "text/markdown" if user["home_instance_type"] == "pleroma" else None 134 content_type = "text/markdown" if user["home_instance_type"] == "pleroma" else None
133 135
136 if user["delayed_checkin"] > 0:
137 scheduled_at = datetime.now() + timedelta(minutes=user["delayed_checkin"])
138 else:
139 scheduled_at = None
140
134 status = get_mastodon_client(update.effective_user.id).status_post(content, 141 status = get_mastodon_client(update.effective_user.id).status_post(content,
135 visibility=user["tool_visibility"], 142 visibility=user["tool_visibility"],
136 content_type=content_type, 143 content_type=content_type,
144 scheduled_at=scheduled_at,
137 media_ids=[]) 145 media_ids=[])
138 146
139 context.user_data[KEY_TOOT_STATUS_ID] = status["id"] 147 context.user_data[KEY_TOOT_STATUS_ID] = status["id"]
@@ -216,17 +224,32 @@ async def _process_location_selection(context: ContextTypes.DEFAULT_TYPE, user:
216 224
217 content_type = "text/markdown" if user["home_instance_type"] == "pleroma" else None 225 content_type = "text/markdown" if user["home_instance_type"] == "pleroma" else None
218 226
227 if user["delayed_checkin"] > 0:
228 scheduled_at = datetime.now() + timedelta(minutes=user["delayed_checkin"])
229 else:
230 scheduled_at = None
231
219 status = get_mastodon_client(context.user_data["user_id"]).status_post(content, 232 status = get_mastodon_client(context.user_data["user_id"]).status_post(content,
220 visibility=user["toot_visibility"], 233 visibility=user["toot_visibility"],
221 content_type=content_type, 234 content_type=content_type,
235 scheduled_at=scheduled_at,
222 media_ids=[]) 236 media_ids=[])
237 if "scheduled_at" in status:
238 context.user_data[KEY_TOOT_STATUS_ID] = status["id"]
239 context.user_data[KEY_TOOT_STATUS_CONTENT] = content
240 context.user_data[KEY_IS_SCHEDULED_TOOT] = True
223 241
224 context.user_data[KEY_TOOT_STATUS_ID] = status["id"] 242 await context.bot.send_message(chat_id=context.user_data.get("chat_id"),
225 context.user_data[KEY_TOOT_STATUS_CONTENT] = content 243 text=f"Selected place: {poi_name}, \nToot scheduled at: {status['scheduled_at']}",
244 parse_mode=ParseMode.MARKDOWN)
245 elif "url" in status:
246 context.user_data[KEY_TOOT_STATUS_ID] = status["id"]
247 context.user_data[KEY_TOOT_STATUS_CONTENT] = content
248 context.user_data[KEY_IS_SCHEDULED_TOOT] = False
226 249
227 await context.bot.send_message(chat_id=context.user_data.get("chat_id"), 250 await context.bot.send_message(chat_id=context.user_data.get("chat_id"),
228 text=f"Selected place: {poi_name}, \nPosted to Mastodon: {status['url']}", 251 text=f"Selected place: {poi_name}, \nPosted to Mastodon: {status['url']}",
229 parse_mode=ParseMode.MARKDOWN) 252 parse_mode=ParseMode.MARKDOWN)
230 253
231 msg = await context.bot.send_message(chat_id=context.user_data.get("chat_id"), 254 msg = await context.bot.send_message(chat_id=context.user_data.get("chat_id"),
232 text=PROMPT_ADD_COMMENT, 255 text=PROMPT_ADD_COMMENT,
@@ -276,10 +299,23 @@ async def callback_add_comment(update: Update, context: ContextTypes.DEFAULT_TYP
276 content_type = "text/markdown" if user["home_instance_type"] == "pleroma" else None 299 content_type = "text/markdown" if user["home_instance_type"] == "pleroma" else None
277 300
278 comment = update.effective_message.text 301 comment = update.effective_message.text
279 get_mastodon_client(update.effective_user.id).status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID), 302 if context.user_data.get(KEY_IS_SCHEDULED_TOOT):
280 content_type=content_type, 303 # TODO:
281 status=f"{comment}\n\n" + context.user_data.get( 304 # Mastodon don't have API to update the content of scheduled toots
282 KEY_TOOT_STATUS_CONTENT)) 305 # we need to store scheduled toots in memory before posting to the server
306 pass
307 # get_mastodon_client(update.effective_user.id).scheduled_status_update(
308 # id=context.user_data.get(KEY_TOOT_STATUS_ID),
309 # content_type=content_type,
310 # status=f"{comment}\n\n" + context.user_data.get(
311 # KEY_TOOT_STATUS_CONTENT))
312
313 else:
314 get_mastodon_client(update.effective_user.id).status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID),
315 content_type=content_type,
316 status=f"{comment}\n\n" + context.user_data.get(
317 KEY_TOOT_STATUS_CONTENT))
318
283 context.user_data[KEY_TOOT_STATUS_CONTENT] = f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT) 319 context.user_data[KEY_TOOT_STATUS_CONTENT] = f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT)
284 320
285 return await _process_comment(context) 321 return await _process_comment(context)
Powered by cgit v1.2.3 (git 2.41.0)