mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-17 13:53:53 +00:00
fix up to 11.0.0
This commit is contained in:
parent
fbb41c7714
commit
57dd2380cd
@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
@ -54,7 +54,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
val content = contentMessage.content
|
val content = contentMessage.content
|
||||||
|
|
||||||
when {
|
when {
|
||||||
content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
|
content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context)
|
||||||
else -> {
|
else -> {
|
||||||
execute(content.createResend(it.context))
|
execute(content.createResend(it.context))
|
||||||
it
|
it
|
||||||
|
@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLi
|
|||||||
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||||
import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
||||||
import dev.inmo.tgbotapi.utils.buildEntities
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
|
||||||
@ -31,9 +32,9 @@ suspend fun doInlineQueriesBot(token: String) {
|
|||||||
answer(
|
answer(
|
||||||
it,
|
it,
|
||||||
results = results.map { resultNumber ->
|
results = results.map { resultNumber ->
|
||||||
val resultAsString = resultNumber.toString()
|
val inlineQueryId = InlineQueryId(resultNumber.toString())
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
resultAsString,
|
inlineQueryId,
|
||||||
"Title $resultNumber",
|
"Title $resultNumber",
|
||||||
InputTextMessageContent(
|
InputTextMessageContent(
|
||||||
buildEntities {
|
buildEntities {
|
||||||
|
@ -15,6 +15,7 @@ import dev.inmo.tgbotapi.extensions.utils.withContent
|
|||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@ -137,7 +138,7 @@ suspend fun activateKeyboardsBot(
|
|||||||
it,
|
it,
|
||||||
results = listOf(
|
results = listOf(
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
it.query,
|
InlineQueryId(it.query),
|
||||||
"Send buttons",
|
"Send buttons",
|
||||||
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
||||||
replyMarkup = inlineKeyboard {
|
replyMarkup = inlineKeyboard {
|
||||||
|
@ -11,10 +11,7 @@ import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
||||||
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
||||||
import dev.inmo.tgbotapi.types.ChatId
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
|
||||||
import dev.inmo.tgbotapi.types.PollIdentifier
|
|
||||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
|
||||||
import dev.inmo.tgbotapi.types.chat.*
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
import dev.inmo.tgbotapi.types.chat.GroupChat
|
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
@ -44,7 +41,7 @@ suspend fun main(vararg args: String) {
|
|||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
val me = getMe()
|
val me = getMe()
|
||||||
|
|
||||||
val pollToChat = mutableMapOf<PollIdentifier, IdChatIdentifier>()
|
val pollToChat = mutableMapOf<PollId, IdChatIdentifier>()
|
||||||
val pollToChatMutex = Mutex()
|
val pollToChatMutex = Mutex()
|
||||||
|
|
||||||
onCommand("anonymous") {
|
onCommand("anonymous") {
|
||||||
|
@ -67,7 +67,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
|
|
||||||
val bot = telegramBot(botToken)
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
val allowedAdmin = ChatId(args[1].toLong())
|
val allowedAdmin = ChatId(RawChatId(args[1].toLong()))
|
||||||
|
|
||||||
fun Boolean?.allowedSymbol() = when (this) {
|
fun Boolean?.allowedSymbol() = when (this) {
|
||||||
true -> "✅"
|
true -> "✅"
|
||||||
@ -377,8 +377,8 @@ suspend fun main(args: Array<String>) {
|
|||||||
initialFilter = { it.user.id == allowedAdmin }
|
initialFilter = { it.user.id == allowedAdmin }
|
||||||
) {
|
) {
|
||||||
val (channelIdString, userIdString) = it.data.split(" ").drop(1)
|
val (channelIdString, userIdString) = it.data.split(" ").drop(1)
|
||||||
val channelId = ChatId(channelIdString.toLong())
|
val channelId = ChatId(RawChatId(channelIdString.toLong()))
|
||||||
val userId = ChatId(userIdString.toLong())
|
val userId = ChatId(RawChatId(userIdString.toLong()))
|
||||||
val chatMember = getChatMember(channelId, userId)
|
val chatMember = getChatMember(channelId, userId)
|
||||||
val asAdmin = chatMember.administratorChatMemberOrNull()
|
val asAdmin = chatMember.administratorChatMemberOrNull()
|
||||||
val asMember = chatMember.memberChatMemberOrNull()
|
val asMember = chatMember.memberChatMemberOrNull()
|
||||||
|
@ -44,7 +44,7 @@ fun StickerSet?.buildInfo() = buildEntities {
|
|||||||
StickerType.Regular -> "Regular"
|
StickerType.Regular -> "Regular"
|
||||||
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
||||||
}
|
}
|
||||||
) + " sticker set with title " + bold(title) + " and name " + bold(name)
|
) + " sticker set with title " + bold(title) + " and name " + bold(name.string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticke
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
||||||
|
import dev.inmo.tgbotapi.types.StickerSetName
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.files.*
|
import dev.inmo.tgbotapi.types.files.*
|
||||||
import dev.inmo.tgbotapi.types.toChatId
|
import dev.inmo.tgbotapi.types.toChatId
|
||||||
@ -32,7 +33,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
val me = getMe()
|
val me = getMe()
|
||||||
fun Chat.stickerSetName() = "s${id.chatId}_by_${me.username ?.usernameWithoutAt}"
|
fun Chat.stickerSetName() = StickerSetName("s${id.chatId}_by_${me.username ?.withoutAt}")
|
||||||
onCommand("start") {
|
onCommand("start") {
|
||||||
reply(it) {
|
reply(it) {
|
||||||
botCommand("delete") + " - to clear stickers"
|
botCommand("delete") + " - to clear stickers"
|
||||||
@ -82,7 +83,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}.onFailure { _ ->
|
}.onFailure { _ ->
|
||||||
createNewStickerSet(
|
createNewStickerSet(
|
||||||
it.chat.id.toChatId(),
|
it.chat.id.toChatId(),
|
||||||
stickerSetName,
|
stickerSetName.string,
|
||||||
"Sticker set by ${me.firstName}",
|
"Sticker set by ${me.firstName}",
|
||||||
it.content.media.stickerFormat,
|
it.content.media.stickerFormat,
|
||||||
listOf(
|
listOf(
|
||||||
|
@ -18,6 +18,7 @@ import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
|||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||||
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
||||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||||
@ -77,9 +78,9 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
post("inline") {
|
post("inline") {
|
||||||
val requestBody = call.receiveText()
|
val requestBody = call.receiveText()
|
||||||
val queryId = call.parameters[webAppQueryIdField] ?: error("$webAppQueryIdField should be presented")
|
val queryId = call.parameters[webAppQueryIdField] ?.let(::InlineQueryId) ?: error("$webAppQueryIdField should be presented")
|
||||||
|
|
||||||
bot.answer(queryId, InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody)))
|
bot.answerInlineQuery(queryId, listOf(InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody))))
|
||||||
call.respond(HttpStatusCode.OK)
|
call.respond(HttpStatusCode.OK)
|
||||||
}
|
}
|
||||||
post("check") {
|
post("check") {
|
||||||
|
@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2344m
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=1.9.23
|
kotlin_version=1.9.23
|
||||||
telegram_bot_api_version=11.0.0-branch_11.0.0-build2158
|
telegram_bot_api_version=11.0.0
|
||||||
micro_utils_version=0.20.39
|
micro_utils_version=0.20.39
|
||||||
serialization_version=1.6.3
|
serialization_version=1.6.3
|
||||||
ktor_version=2.3.9
|
ktor_version=2.3.9
|
||||||
|
Loading…
Reference in New Issue
Block a user