aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/bot.py b/bot.py
index 364a85f..fe45970 100644
--- a/bot.py
+++ b/bot.py
@@ -11,6 +11,7 @@ from starlette.requests import Request
11from starlette.responses import PlainTextResponse, Response, JSONResponse 11from starlette.responses import PlainTextResponse, Response, JSONResponse
12from starlette.routing import Route 12from starlette.routing import Route
13from telegram import Update 13from telegram import Update
14from telegram.error import BadRequest
14from telegram.ext import ( 15from telegram.ext import (
15 Application, 16 Application,
16 CallbackContext, 17 CallbackContext,
@@ -33,7 +34,8 @@ from callback import (
33 callback_skip_location_keyword_search, 34 callback_skip_location_keyword_search,
34 callback_add_comment, 35 callback_add_comment,
35 callback_skip_comment, 36 callback_skip_comment,
36 callback_add_media 37 callback_add_media,
38 callback_delayed_checkin
37) 39)
38from command import ( 40from command import (
39 start_command, 41 start_command,
@@ -44,7 +46,8 @@ from command import (
44 toggle_visibility_command, 46 toggle_visibility_command,
45 callback_toggle_visibility, 47 callback_toggle_visibility,
46 logout_command, 48 logout_command,
47 list_command 49 list_command,
50 delayed_checkin_command,
48) 51)
49from config import ( 52from config import (
50 FEDI_LOGIN, 53 FEDI_LOGIN,
@@ -57,7 +60,8 @@ from config import (
57 BOT_TOKEN, 60 BOT_TOKEN,
58 BOT_SCOPE, 61 BOT_SCOPE,
59 MAIN_MENU, 62 MAIN_MENU,
60 WAIT_VISIBILITY 63 WAIT_VISIBILITY,
64 DELAYED_CHECKIN,
61) 65)
62 66
63from prompt.string import PROMPT_CHOOSE_ACTION 67from prompt.string import PROMPT_CHOOSE_ACTION
@@ -114,10 +118,14 @@ async def process_oauth_login_callback(update: FediLoginCallbackUpdate, context:
114 user.access_key = encrypt(access_token, ENCRYPT_KEY) 118 user.access_key = encrypt(access_token, ENCRYPT_KEY)
115 user.save() 119 user.save()
116 120
117 text = "You have successfully logged in to your Mastodon account!" 121 text = "You have successfully logged in to your Mastodon account!"
122 try:
118 await context.bot.delete_message(chat_id=user.telegram_user_id, message_id=context.user_data[PROMPT_FEDI_LOGIN]) 123 await context.bot.delete_message(chat_id=user.telegram_user_id, message_id=context.user_data[PROMPT_FEDI_LOGIN])
119 await context.bot.send_message(chat_id=user.telegram_user_id, text=text) 124 await context.bot.send_message(chat_id=user.telegram_user_id, text=text)
120 await context.bot.send_message(chat_id=user.telegram_user_id, text=PROMPT_CHOOSE_ACTION, reply_markup=MAIN_MENU) 125 await context.bot.send_message(chat_id=user.telegram_user_id, text=PROMPT_CHOOSE_ACTION, reply_markup=MAIN_MENU)
126 except BadRequest as e:
127 if "not found" in str(e.message):
128 pass
121 129
122 130
123async def main() -> None: 131async def main() -> None:
@@ -176,11 +184,26 @@ async def main() -> None:
176 allow_reentry=True, 184 allow_reentry=True,
177 ) 185 )
178 186
187 delayed_checkin_handler = ConversationHandler(
188 entry_points=[
189 CommandHandler("delay", delayed_checkin_command),
190 ],
191 states={
192 DELAYED_CHECKIN: [
193 MessageHandler(filters.TEXT & ~filters.COMMAND, callback_delayed_checkin),
194 ],
195 },
196 fallbacks=[CommandHandler("cancel", cancel_command)],
197 per_message=False,
198 allow_reentry=True,
199 )
200
179 application.add_handler(CommandHandler("logout", logout_command)) 201 application.add_handler(CommandHandler("logout", logout_command))
180 application.add_handler(CommandHandler("list", list_command)) 202 application.add_handler(CommandHandler("list", list_command))
181 application.add_handler(CommandHandler("Help", help_command)) 203 application.add_handler(CommandHandler("Help", help_command))
182 application.add_handler(TypeHandler(type=FediLoginCallbackUpdate, callback=process_oauth_login_callback)) 204 application.add_handler(TypeHandler(type=FediLoginCallbackUpdate, callback=process_oauth_login_callback))
183 205
206 application.add_handler(delayed_checkin_handler, 3)
184 application.add_handler(visibility_conversation_handler, 2) 207 application.add_handler(visibility_conversation_handler, 2)
185 application.add_handler(checkin_handler, 1) 208 application.add_handler(checkin_handler, 1)
186 209
Powered by cgit v1.2.3 (git 2.41.0)