Fix parse mode default for telegram bot
All checks were successful
publish-images / build (push) Successful in 56s
All checks were successful
publish-images / build (push) Successful in 56s
This commit is contained in:
18
bot/main.py
18
bot/main.py
@@ -12,6 +12,7 @@ from telegram.ext import (
|
|||||||
CallbackQueryHandler,
|
CallbackQueryHandler,
|
||||||
CommandHandler,
|
CommandHandler,
|
||||||
ContextTypes,
|
ContextTypes,
|
||||||
|
Defaults,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .boinc import BoincClient
|
from .boinc import BoincClient
|
||||||
@@ -55,9 +56,7 @@ async def render_view(view: View, client: BoincClient) -> str:
|
|||||||
async def start_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def start_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
client: BoincClient = context.bot_data["boinc_client"]
|
client: BoincClient = context.bot_data["boinc_client"]
|
||||||
text = await render_view("dashboard", client)
|
text = await render_view("dashboard", client)
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(text, reply_markup=build_keyboard(), parse_mode=ParseMode.HTML)
|
||||||
text, reply_markup=build_keyboard(), parse_mode=ParseMode.HTML
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def callback_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def callback_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
@@ -70,9 +69,7 @@ async def callback_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -
|
|||||||
except Exception as exc: # broad catch to show meaningful message in chat
|
except Exception as exc: # broad catch to show meaningful message in chat
|
||||||
logger.exception("Error rendering view %s", view)
|
logger.exception("Error rendering view %s", view)
|
||||||
text = f"Не удалось получить данные: {exc}"
|
text = f"Не удалось получить данные: {exc}"
|
||||||
await query.edit_message_text(
|
await query.edit_message_text(text=text, reply_markup=build_keyboard(), parse_mode=ParseMode.HTML)
|
||||||
text=text, reply_markup=build_keyboard(), parse_mode=ParseMode.HTML
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
@@ -85,12 +82,8 @@ async def main() -> None:
|
|||||||
sample_output=settings.sample_output,
|
sample_output=settings.sample_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
application = (
|
defaults = Defaults(parse_mode=ParseMode.HTML)
|
||||||
ApplicationBuilder()
|
application = ApplicationBuilder().token(settings.telegram_token).defaults(defaults).build()
|
||||||
.token(settings.telegram_token)
|
|
||||||
.parse_mode(ParseMode.HTML)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
application.bot_data["boinc_client"] = client
|
application.bot_data["boinc_client"] = client
|
||||||
|
|
||||||
application.add_handler(CommandHandler("start", start_handler))
|
application.add_handler(CommandHandler("start", start_handler))
|
||||||
@@ -103,4 +96,3 @@ async def main() -> None:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user