Skip to content

Commit

Permalink
fix: added length check for the /start argument
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed Nov 25, 2023
1 parent e1299ef commit 3a7d9a5
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/main/kotlin/app/meetacy/telegram/bot/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ suspend fun main(): Unit = coroutineScope {

val token = System.getenv("BOT_TOKEN")
val secretBotKey = System.getenv("SECRET_KEY").let(::SecretTelegramBotKey)
val secretBotKeySize = 256

val bot = telegramBot(token)
val meetacy = MeetacyApi.production()
Expand Down Expand Up @@ -53,23 +54,31 @@ suspend fun main(): Unit = coroutineScope {
}

val commandParts = content.text.split(" ")

suspend fun sendStartMessage() = bot.sendMessage(
chat = message.chat,
text = "Welcome to Meetacy Service Bot that helps with authorization by Telegram. " +
"For now there is no other functions. To follow up with our news, subscribe to our channel ⬇\uFE0F\uFE0F\uFE0F",
replyMarkup = inlineKeyboard {
+URLInlineKeyboardButton(
text = "@meetacy",
url = "https://t.me/meetacy"
)
}
)

if (commandParts.size != 2) {
bot.sendMessage(
chat = message.chat,
text = "Welcome to Meetacy Service Bot that helps with authorization by Telegram. " +
"For now there is no other functions. To follow up with our news, subscribe to our channel ⬇\uFE0F\uFE0F\uFE0F",
replyMarkup = inlineKeyboard {
+URLInlineKeyboardButton(
text = "@meetacy",
url = "https://t.me/meetacy"
)
}
)
sendStartMessage()
return@onEach
}

val (_, temporalHash) = commandParts

if (temporalHash.length != secretBotKeySize) {
sendStartMessage()
return@onEach
}

scope.launch {
meetacy.auth.telegram.finish(
temporalHash = TemporalTelegramHash(temporalHash),
Expand Down

0 comments on commit 3a7d9a5

Please sign in to comment.