Esempio n. 1
0
async def handle_help(message: types.Message) -> None:
    with get_db_session() as db:
        user = crud.get_user(db, message.chat.id)
    reply_markup = KeyboardMarkUpFactory.build_main_menu(user)
    await TelegramMessageService.send_keyboard_markup(dp.bot, message.chat.id,
                                                      WELCOME_TEXT,
                                                      reply_markup)
Esempio n. 2
0
async def handle_weather(message: types.Message) -> None:
    chat_id = message.chat.id
    with get_db_session() as db:
        user = crud.get_user(db, chat_id)

    if text := await he_weather.get_weather_warning(user.location):
        await notify_with_24h_cache(user, text)
Esempio n. 3
0
async def handle_weather(message: types.Message) -> None:
    chat_id = message.chat.id
    with get_db_session() as db:
        user = crud.get_user(db, chat_id)

    text = await he_weather.get_weather_6h_forecast_text(user.location)
    await TelegramMessageService.send_text(dp.bot, chat_id, text)
Esempio n. 4
0
    async def wrapper(message: types.Message):
        chat_id = message.chat.id
        with get_db_session() as db:
            user = crud.get_user(db, chat_id)

        if not user:
            return await update_location(message)

        await func(message)
Esempio n. 5
0
async def update_subscription_callback_handler(query: types.CallbackQuery):
    is_enable = query.data == ENABLE_SUB
    with get_db_session() as db:
        crud.update_user_status(db, query.message.chat.id, is_enable)
        text = "已开启订阅" if is_enable else "已关闭订阅"
        user = crud.get_user(db, query.message.chat.id)
        await query.answer(text)
        await query.message.edit_reply_markup(
            KeyboardMarkUpFactory.build_cron_options(user))
Esempio n. 6
0
async def handle_sub(message: types.Message) -> None:
    with get_db_session() as db:
        crud.update_user_status(db, message.chat.id, True)
        await TelegramMessageService.send_text(dp.bot, message.chat.id,
                                               "已开启定时订阅")

        user = crud.get_user(db, message.chat.id)
        reply_markup = KeyboardMarkUpFactory.build_cron_options(user)
        await TelegramMessageService.send_keyboard_markup(
            dp.bot, message.chat.id, WELCOME_TEXT, reply_markup)
Esempio n. 7
0
async def process_ding_token(message: types.Message, state: FSMContext):
    ding_bot_token = await extra_ding_token_from_message(message.text)
    if not ding_bot_token:
        return await message.reply(
            "机器人的Webhook地址非法!"
            "\n参考格式:https://oapi.dingtalk.com/robot/send?access_token=XXXXXX"
            "\n取消输入:/cancel")

    with get_db_session() as db:
        crud.update_or_create_ding_bot(db, message.chat.id, ding_bot_token)

    # 发送测试消息
    with get_db_session() as db:
        chat = crud.get_user(db, chat_id=message.chat.id)
    text = await he_weather.get_weather_forecast(chat.location)
    await DingBotMessageService.send_text(ding_bot_token, text)
    await message.reply("钉钉Token关联成功,请注意查收测试消息~")
    await state.finish()
Esempio n. 8
0
async def sub_cron_update_callback_handler(query: types.CallbackQuery):
    hour = query.data
    chat_id = query.message.chat.id

    with get_db_session() as db:
        # 激活用户
        crud.update_user_status(db, query.message.chat.id, True)
        user = crud.get_user(db, query.message.chat.id)

        # 新增/删除订阅
        cron_job, created = crud.create_or_delete_cron_job(db, chat_id, hour)
        if created:
            await query.answer("订阅成功")
        else:
            await query.answer("已取消")

        db.refresh(user)
        cron_sub_menu = KeyboardMarkUpFactory.build_cron_options(user)
        await query.message.edit_reply_markup(cron_sub_menu)
Esempio n. 9
0
async def exit_callback_handler(query: types.CallbackQuery):
    with get_db_session() as db:
        user = crud.get_user(db, query.message.chat.id)
        await query.message.edit_reply_markup(
            KeyboardMarkUpFactory.build_main_menu(user))
        await query.answer('')