Skip to content

Commit

Permalink
feat: Implement inline settings suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
otomir23 committed Jul 9, 2024
1 parent 7a0fa19 commit a792001
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions locales/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type-select-title = select download type (。 · ᎑ ·。)
downloading-title = downloading... (˶ᵔ ᵕ ᵔ˶)
uploading-title = uploading... (˶ᵔ ᵕ ᵔ˶)
settings-open = open settings
settings-title = settings
setting-output = output
Expand Down
1 change: 1 addition & 0 deletions locales/ru.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type-select-title = выбери тип загрузки (。 · ᎑ ·。)
downloading-title = скачиваю... (˶ᵔ ᵕ ᵔ˶)
uploading-title = загружаю... (˶ᵔ ᵕ ᵔ˶)
settings-open = открыть настройки
settings-title = настройки
setting-output = формат
Expand Down
11 changes: 8 additions & 3 deletions src/telegram/bot/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ downloadDp.onNewMessage(filters.chat("private"), async (msg) => {
downloadDp.onInlineQuery(async (ctx) => {
const { t, e } = await evaluatorsFor(ctx.user)

const settingsSwitchPm = {
text: t("settings-open"),
parameter: "settings",
}

if (!ctx.query.trim()) {
await ctx.answer([])
await ctx.answer([], { switchPm: settingsSwitchPm })
return
}

Expand All @@ -65,7 +70,7 @@ downloadDp.onInlineQuery(async (ctx) => {
title: t("error-title"),
description: e(req.error),
}),
], { cacheTime: 0 })
], { cacheTime: 0, switchPm: settingsSwitchPm })
return
}

Expand All @@ -83,7 +88,7 @@ downloadDp.onInlineQuery(async (ctx) => {
text: e(selectMsg.caption),
},
}),
], { cacheTime: 0 })
], { cacheTime: 0, switchPm: settingsSwitchPm })
})

downloadDp.onAnyCallbackQuery(OutputButton.filter(), async (upd) => {
Expand Down
2 changes: 1 addition & 1 deletion src/telegram/bot/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const bot = new TelegramClient({
const dp = Dispatcher.for(bot)

dp.onError(createDispatcherErrorHandler(bot))
dp.extend(startDp)
dp.extend(settingsDp)
dp.extend(startDp)
dp.extend(statsDp)
dp.extend(downloadDp)

Expand Down
17 changes: 10 additions & 7 deletions src/telegram/bot/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ const settingsReplyMarkup = (e: TextEvaluator, settings: Settings): InlineKeyboa
])),
)

settingsDp.onNewMessage(filters.command("settings"), async (msg) => {
const { t, e } = await evaluatorsFor(msg.sender)
const settings = await getPeerSettings(msg.sender)
await msg.replyText(t("settings-title"), {
replyMarkup: settingsReplyMarkup(e, settings),
})
})
settingsDp.onNewMessage(
filters.or(filters.command("settings"), filters.deeplink(["settings"])),
async (msg) => {
const { t, e } = await evaluatorsFor(msg.sender)
const settings = await getPeerSettings(msg.sender)
await msg.replyText(t("settings-title"), {
replyMarkup: settingsReplyMarkup(e, settings),
})
},
)

settingsDp.onAnyCallbackQuery(SettingButton.filter(), async (upd) => {
const settings = await getPeerSettings(upd.user)
Expand Down
2 changes: 1 addition & 1 deletion src/telegram/bot/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Dispatcher, filters } from "@mtcute/dispatcher"
import { translatorFor } from "#telegram/helpers/i18n"

export const startDp = Dispatcher.child()
startDp.onNewMessage(filters.command("start"), async (msg) => {
startDp.onNewMessage(filters.start, async (msg) => {
const t = await translatorFor(msg.sender)
await msg.replyText(t("start"))
})

0 comments on commit a792001

Please sign in to comment.