mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-08-15 13:46:27 +00:00
Compare commits
5 Commits
ba1ee5dfa3
...
36.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 40425f6451 | |||
| 56cc2e70c1 | |||
| 868cf646bd | |||
| 2f5fa711a7 | |||
| 5a2ba634c6 |
12
BotSubscriptionsBot/README.md
Normal file
12
BotSubscriptionsBot/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# BotSubscriptionsBot
|
||||||
|
|
||||||
|
Demonstrates Bot Subscriptions (subscription updates) support introduced in Telegram Bot API 10.2.
|
||||||
|
|
||||||
|
The bot logs and reacts to `subscription` updates — when a user's recurring Telegram Stars subscription to
|
||||||
|
the bot becomes active, is canceled, or fails — handling the typed `BotSubscriptionUpdated.State`.
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew :BotSubscriptionsBot:run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
BotSubscriptionsBot/build.gradle
Normal file
21
BotSubscriptionsBot/build.gradle
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
mainClassName="BotSubscriptionsBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
93
BotSubscriptionsBot/src/main/kotlin/BotSubscriptionsBot.kt
Normal file
93
BotSubscriptionsBot/src/main/kotlin/BotSubscriptionsBot.kt
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
|
import dev.inmo.kslog.common.LogLevel
|
||||||
|
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||||
|
import dev.inmo.kslog.common.setDefaultKSLog
|
||||||
|
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitBotSubscriptionUpdated
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBotSubscriptionUpdated
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.types.payments.BotSubscriptionUpdated
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot demonstrates Bot Subscriptions (subscription updates) support introduced in Telegram Bot API 10.2.
|
||||||
|
*
|
||||||
|
* When a user starts, renews, cancels or fails to pay a subscription to the bot (a recurring Telegram Stars
|
||||||
|
* payment), the bot receives a `subscription` update carrying a [BotSubscriptionUpdated].
|
||||||
|
*
|
||||||
|
* Key concepts demonstrated:
|
||||||
|
* - [onBotSubscriptionUpdated] — trigger whose handler receives a [BotSubscriptionUpdated] (`user`,
|
||||||
|
* `invoicePayload`, `state`)
|
||||||
|
* - [BotSubscriptionUpdated.State] — the typed sealed state: [BotSubscriptionUpdated.State.Active],
|
||||||
|
* [BotSubscriptionUpdated.State.Canceled], [BotSubscriptionUpdated.State.Failed] (data objects) and the
|
||||||
|
* [BotSubscriptionUpdated.State.Unknown] value-class fallback for any future state
|
||||||
|
* - `botSubscriptionUpdatedUpdatesFlow` — the raw update flow of
|
||||||
|
* [dev.inmo.tgbotapi.types.update.BotSubscriptionUpdatedUpdate] (available directly because a
|
||||||
|
* BehaviourContext is a `FlowsUpdatesFilter`); each emission's payload is its `data`
|
||||||
|
* - [waitBotSubscriptionUpdated] — expectation returning a flow of [BotSubscriptionUpdated]
|
||||||
|
*/
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
val isDebug = args.any { it == "debug" }
|
||||||
|
val isTestServer = args.any { it == "testServer" }
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
telegramBotWithBehaviourAndLongPolling(
|
||||||
|
botToken,
|
||||||
|
CoroutineScope(Dispatchers.IO),
|
||||||
|
testServer = isTestServer,
|
||||||
|
) {
|
||||||
|
val me = getMe()
|
||||||
|
println("Bot info: $me")
|
||||||
|
|
||||||
|
// subscription update: react to the typed BotSubscriptionUpdated.State
|
||||||
|
onBotSubscriptionUpdated { update ->
|
||||||
|
val user = update.user
|
||||||
|
val payload = update.invoicePayload
|
||||||
|
val stateText = when (val state = update.state) {
|
||||||
|
BotSubscriptionUpdated.State.Active -> "active ✅"
|
||||||
|
BotSubscriptionUpdated.State.Canceled -> "canceled ❌"
|
||||||
|
BotSubscriptionUpdated.State.Failed -> "payment failed ⚠️"
|
||||||
|
// Unknown is a value class carrying the raw state name — future-proof fallback
|
||||||
|
is BotSubscriptionUpdated.State.Unknown -> "unknown (${state.name})"
|
||||||
|
}
|
||||||
|
println("Subscription update from ${user.id}: payload=$payload, state=${update.state.name}")
|
||||||
|
|
||||||
|
// notify the subscriber (only works if they have an open chat with the bot)
|
||||||
|
runCatchingLogging {
|
||||||
|
send(user.id, "Your subscription (payload: $payload) is now: $stateText")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw flow variant of the same updates. BehaviourContext : FlowsUpdatesFilter, so the flow is
|
||||||
|
// available directly; each emission is a BotSubscriptionUpdatedUpdate whose payload is `.data`.
|
||||||
|
botSubscriptionUpdatedUpdatesFlow.subscribeSafelyWithoutExceptions(this) { update ->
|
||||||
|
println("[flow] update ${update.updateId}: user=${update.data.user.id}, state=${update.data.state.name}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitBotSubscriptionUpdated expectation: suspend until the next subscription update
|
||||||
|
onCommand("wait_subscription") {
|
||||||
|
reply(it, "Waiting for the next subscription update...")
|
||||||
|
val update = waitBotSubscriptionUpdated().first()
|
||||||
|
reply(it, "Subscription update: state=${update.state.name}, payload=${update.invoicePayload}")
|
||||||
|
}
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
12
CommunitiesBot/README.md
Normal file
12
CommunitiesBot/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# CommunitiesBot
|
||||||
|
|
||||||
|
Demonstrates Communities support introduced in Telegram Bot API 10.2.
|
||||||
|
|
||||||
|
Add the bot to a chat that belongs to a community. It reports when the chat is added to or removed from a
|
||||||
|
community, and `/community` prints the chat's current community (read from `getChat().community`).
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew :CommunitiesBot:run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
CommunitiesBot/build.gradle
Normal file
21
CommunitiesBot/build.gradle
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
mainClassName="CommunitiesBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
98
CommunitiesBot/src/main/kotlin/CommunitiesBot.kt
Normal file
98
CommunitiesBot/src/main/kotlin/CommunitiesBot.kt
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
|
import dev.inmo.kslog.common.LogLevel
|
||||||
|
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||||
|
import dev.inmo.kslog.common.setDefaultKSLog
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitCommunityChatAdded
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommunityChatAdded
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommunityChatRemoved
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot demonstrates Communities support introduced in Telegram Bot API 10.2.
|
||||||
|
*
|
||||||
|
* A community groups several chats together. When a chat is added to (or removed from) a community, the bot
|
||||||
|
* receives a service event in that chat.
|
||||||
|
*
|
||||||
|
* Key concepts demonstrated:
|
||||||
|
* - [onCommunityChatAdded] — trigger for the `community_chat_added` service event. The handler receives a
|
||||||
|
* [dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage] carrying a
|
||||||
|
* [dev.inmo.tgbotapi.types.communities.CommunityChatAdded] whose `community` is the
|
||||||
|
* [dev.inmo.tgbotapi.types.communities.Community] (`id`: [dev.inmo.tgbotapi.types.communities.CommunityId],
|
||||||
|
* `name`) the chat was added to
|
||||||
|
* - [onCommunityChatRemoved] — trigger for the fieldless `community_chat_removed` service event
|
||||||
|
* - [waitCommunityChatAdded] — expectation returning a flow of [dev.inmo.tgbotapi.types.communities.CommunityChatAdded]
|
||||||
|
* - [dev.inmo.tgbotapi.types.chat.ExtendedChat.community] — the community a chat belongs to
|
||||||
|
* (`ChatFullInfo.community`), available directly from [getChat] without any cast
|
||||||
|
*/
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
val isDebug = args.any { it == "debug" }
|
||||||
|
val isTestServer = args.any { it == "testServer" }
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
telegramBotWithBehaviourAndLongPolling(
|
||||||
|
botToken,
|
||||||
|
CoroutineScope(Dispatchers.IO),
|
||||||
|
testServer = isTestServer,
|
||||||
|
) {
|
||||||
|
val me = getMe()
|
||||||
|
println("Bot info: $me")
|
||||||
|
|
||||||
|
// community_chat_added: the chat was added to a community
|
||||||
|
onCommunityChatAdded { message ->
|
||||||
|
val community = message.chatEvent.community
|
||||||
|
println("Chat ${message.chat.id} was added to community '${community.name}' (id=${community.id.long})")
|
||||||
|
send(message.chat.id, "This chat has joined the community: ${community.name}")
|
||||||
|
|
||||||
|
// community is exposed on ExtendedChat itself (ChatFullInfo.community) — no cast needed
|
||||||
|
val extended = getChat(message.chat.id)
|
||||||
|
println("getChat().community = ${extended.community?.name} / ${extended.community?.id?.long}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// community_chat_removed: a fieldless event — the chat left its community
|
||||||
|
onCommunityChatRemoved { message ->
|
||||||
|
println("Chat ${message.chat.id} was removed from its community")
|
||||||
|
send(message.chat.id, "This chat has left its community")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inspect the current chat's community on demand
|
||||||
|
onCommand("community") {
|
||||||
|
val community = getChat(it.chat.id).community
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
if (community != null) {
|
||||||
|
"Community: ${community.name} (id=${community.id.long})"
|
||||||
|
} else {
|
||||||
|
"This chat is not part of any community"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitCommunityChatAdded expectation: suspend until this chat is added to a community
|
||||||
|
onCommand("wait_community") {
|
||||||
|
reply(it, "Waiting for this chat to be added to a community...")
|
||||||
|
val event = waitCommunityChatAdded().first()
|
||||||
|
reply(it, "Chat added to community: ${event.community.name} (id=${event.community.id.long})")
|
||||||
|
}
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
13
EphemeralMessagesBot/README.md
Normal file
13
EphemeralMessagesBot/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# EphemeralMessagesBot
|
||||||
|
|
||||||
|
Demonstrates Ephemeral Messages support introduced in Telegram Bot API 10.2.
|
||||||
|
|
||||||
|
Add the bot to a group and send `/ephemeral`. Tapping the button makes the bot send a message that only
|
||||||
|
you can see (an ephemeral message), then edit and delete it. The bot also detects incoming ephemeral
|
||||||
|
messages and replies to them ephemerally.
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew :EphemeralMessagesBot:run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
EphemeralMessagesBot/build.gradle
Normal file
21
EphemeralMessagesBot/build.gradle
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
mainClassName="EphemeralMessagesBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
138
EphemeralMessagesBot/src/main/kotlin/EphemeralMessagesBot.kt
Normal file
138
EphemeralMessagesBot/src/main/kotlin/EphemeralMessagesBot.kt
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
|
import dev.inmo.kslog.common.LogLevel
|
||||||
|
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||||
|
import dev.inmo.kslog.common.setDefaultKSLog
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.deleteEphemeralMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.text.editEphemeralMessageText
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyToEphemeral
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
||||||
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyEphemeralMessage
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot demonstrates Ephemeral Messages support introduced in Telegram Bot API 10.2.
|
||||||
|
*
|
||||||
|
* An ephemeral message lives inside a group chat but is shown to exactly one user (its `receiver`).
|
||||||
|
* It is addressed not by a normal message id, but by a per-receiver [dev.inmo.tgbotapi.types.EphemeralMessageId]
|
||||||
|
* together with that receiver's [dev.inmo.tgbotapi.types.UserId]. Bots typically send ephemeral messages in
|
||||||
|
* response to a callback query (so a `callbackQueryId` is available) or reply ephemerally to an ephemeral
|
||||||
|
* message the bot itself received.
|
||||||
|
*
|
||||||
|
* Key concepts demonstrated:
|
||||||
|
* - [sendTextMessage] with `receiverUserId` + `callbackQueryId` — sends the outgoing message as ephemeral,
|
||||||
|
* visible only to `receiverUserId` in the group chat (one of the 13 ephemeral-capable send requests)
|
||||||
|
* - [PossiblyEphemeralMessage] — the marker interface (`receiverUser` / `ephemeralMessageId`) implemented by
|
||||||
|
* the group-family `Common*ContentMessage` types; the way to detect that a message is ephemeral
|
||||||
|
* - [editEphemeralMessageText] / [deleteEphemeralMessage] — edit / delete an ephemeral message addressed by
|
||||||
|
* `chatId` + `receiverUserId` + [dev.inmo.tgbotapi.types.EphemeralMessageId] ([deleteEphemeralMessage] also
|
||||||
|
* accepts a [PossiblyEphemeralMessage] directly)
|
||||||
|
* - [reply] smart-branch — replying to an ephemeral message automatically sends the reply ephemeral to the
|
||||||
|
* same receiver (see [dev.inmo.tgbotapi.types.ephemeralReplyParametersOrNull])
|
||||||
|
* - [replyToEphemeral] — the explicit form: reply to an ephemeral message by `chatId` + `receiverUserId` +
|
||||||
|
* `ephemeralMessageId` without needing the original [PossiblyEphemeralMessage] object
|
||||||
|
* - [BotCommand.isEphemeral] — the new command flag marking a command whose response is ephemeral
|
||||||
|
*/
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
val isDebug = args.any { it == "debug" }
|
||||||
|
val isTestServer = args.any { it == "testServer" }
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
telegramBotWithBehaviourAndLongPolling(
|
||||||
|
botToken,
|
||||||
|
CoroutineScope(Dispatchers.IO),
|
||||||
|
testServer = isTestServer,
|
||||||
|
) {
|
||||||
|
val me = getMe()
|
||||||
|
println("Bot info: $me")
|
||||||
|
|
||||||
|
// Post (in a group) a message with an inline button. Tapping it triggers an ephemeral reply that is
|
||||||
|
// visible only to the user who tapped.
|
||||||
|
onCommand("ephemeral") {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
"Tap the button — the reply will be ephemeral (visible only to you).",
|
||||||
|
replyMarkup = flatInlineKeyboard {
|
||||||
|
dataButton("Reveal a secret", "reveal")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send an ephemeral message in response to a callback query. `receiverUserId` + `callbackQueryId`
|
||||||
|
// make the outgoing message ephemeral — Telegram shows it only to the querying user (and this also
|
||||||
|
// serves as the answer to the callback query).
|
||||||
|
onMessageDataCallbackQuery(Regex("reveal")) { query ->
|
||||||
|
val chatId = query.message.chat.id
|
||||||
|
val receiverUserId = query.from.id
|
||||||
|
|
||||||
|
val sent = sendTextMessage(
|
||||||
|
chatId,
|
||||||
|
"🔒 ${query.from.firstName}, here is your personal secret: 42",
|
||||||
|
receiverUserId = receiverUserId,
|
||||||
|
callbackQueryId = query.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Only the group-family Common*ContentMessage types implement PossiblyEphemeralMessage, so the
|
||||||
|
// sent ephemeral message exposes its ephemeralMessageId through that interface.
|
||||||
|
val ephemeralMessageId = (sent as? PossiblyEphemeralMessage)?.ephemeralMessageId
|
||||||
|
if (ephemeralMessageId != null) {
|
||||||
|
delay(3000)
|
||||||
|
// editEphemeralMessageText: address the ephemeral message by chatId + receiverUserId + ephemeralMessageId
|
||||||
|
editEphemeralMessageText(chatId, receiverUserId, ephemeralMessageId, "🔓 Revealed: the answer is 42")
|
||||||
|
delay(3000)
|
||||||
|
// deleteEphemeralMessage: same addressing (there is also a PossiblyEphemeralMessage overload)
|
||||||
|
deleteEphemeralMessage(chatId, receiverUserId, ephemeralMessageId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Incoming ephemeral messages: detect them via PossiblyEphemeralMessage, then answer them.
|
||||||
|
onContentMessage { message ->
|
||||||
|
val ephemeral = (message as? PossiblyEphemeralMessage)?.takeIf { it.ephemeralMessageId != null }
|
||||||
|
?: return@onContentMessage
|
||||||
|
|
||||||
|
// reply smart-branch: because `message` is ephemeral, this reply is sent ephemeral to the same
|
||||||
|
// receiver automatically — no ephemeral parameters needed here.
|
||||||
|
reply(message, "Got your ephemeral message — I am replying ephemerally too.")
|
||||||
|
|
||||||
|
// The explicit equivalent, addressing the ephemeral message by hand:
|
||||||
|
val receiverUserId = ephemeral.receiverUser?.id
|
||||||
|
if (receiverUserId != null) {
|
||||||
|
replyToEphemeral(
|
||||||
|
message.chat.id,
|
||||||
|
receiverUserId,
|
||||||
|
ephemeral.ephemeralMessageId!!,
|
||||||
|
"Explicit ephemeral reply via replyToEphemeral",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setMyCommands(
|
||||||
|
// isEphemeral marks a command whose response is an ephemeral (personal) message
|
||||||
|
BotCommand("ephemeral", "Post a button that reveals an ephemeral (personal) message", isEphemeral = true),
|
||||||
|
)
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAn
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGuestRequestMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGuestRequestMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPhoto
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onRichMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onRichMessage
|
||||||
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
|
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.contentMessageOrNull
|
import dev.inmo.tgbotapi.extensions.utils.contentMessageOrNull
|
||||||
@@ -25,8 +26,11 @@ import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputRichMessag
|
|||||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
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.types.message.textsources.BotCommandTextSource
|
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||||
|
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
||||||
|
import dev.inmo.tgbotapi.types.rich.InputRichMessageBlocks
|
||||||
import dev.inmo.tgbotapi.types.rich.InputRichMessageHTML
|
import dev.inmo.tgbotapi.types.rich.InputRichMessageHTML
|
||||||
import dev.inmo.tgbotapi.types.rich.InputRichMessageMarkdown
|
import dev.inmo.tgbotapi.types.rich.InputRichMessageMarkdown
|
||||||
|
import dev.inmo.tgbotapi.types.rich.InputRichMessageMedia
|
||||||
import dev.inmo.tgbotapi.types.toChatId
|
import dev.inmo.tgbotapi.types.toChatId
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -52,6 +56,14 @@ import kotlinx.coroutines.flow.mapNotNull
|
|||||||
* - [waitRichMessage] — expectation for a rich message
|
* - [waitRichMessage] — expectation for a rich message
|
||||||
* - [onlyRichMessageContentMessages] — flow filter keeping only rich message content
|
* - [onlyRichMessageContentMessages] — flow filter keeping only rich message content
|
||||||
* - [InputRichMessageContent] — usable as InputMessageContent in inline query results
|
* - [InputRichMessageContent] — usable as InputMessageContent in inline query results
|
||||||
|
*
|
||||||
|
* Telegram Bot API 10.2 additions demonstrated below:
|
||||||
|
* - [InputRichMessageBlocks] — build a rich message from a typed [dev.inmo.tgbotapi.types.rich.InputRichBlock]
|
||||||
|
* tree via the InputRichBlocks DSL instead of an HTML/Markdown string (exactly one of html/markdown/blocks)
|
||||||
|
* - the draft-only `thinking()` block, streamed through [sendRichMessageDraft]
|
||||||
|
* - [InputRichMessageMedia] — media referenced from the rich message via `tg://photo?id=` / `tg://video?id=` /
|
||||||
|
* `tg://audio?id=`, plus first-class media blocks (photo/video/...) inside the blocks tree; new files are
|
||||||
|
* uploaded as `attach://` automatically by [dev.inmo.tgbotapi.requests.send.SendRichMessage]
|
||||||
*/
|
*/
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
@@ -444,6 +456,103 @@ suspend fun main(vararg args: String) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === Bots API 10.2 additions: InputRichBlocks DSL + rich message media ===
|
||||||
|
|
||||||
|
// InputRichMessageBlocks { } — build a rich message from a typed InputRichBlock tree instead
|
||||||
|
// of an HTML/Markdown string (exactly one of html/markdown/blocks may be used). The lambda is an
|
||||||
|
// InputRichBlocksBuilder; buildInputRichBlocks { } returns the raw List<InputRichBlock> the same way.
|
||||||
|
onCommand("rich_blocks") {
|
||||||
|
sendRichMessage(
|
||||||
|
it.chat.id,
|
||||||
|
InputRichMessageBlocks {
|
||||||
|
heading("Rich blocks (Bots API 10.2)", level = 1)
|
||||||
|
paragraph {
|
||||||
|
plain("This message is built from ")
|
||||||
|
bold("structured InputRichBlocks")
|
||||||
|
plain(" — no HTML or Markdown string is involved.")
|
||||||
|
}
|
||||||
|
|
||||||
|
heading("Lists", level = 2)
|
||||||
|
list {
|
||||||
|
item("A plain list item")
|
||||||
|
item(hasCheckbox = true, isChecked = true) { paragraph("A completed task item") }
|
||||||
|
item(hasCheckbox = true, isChecked = false) { paragraph("A pending task item") }
|
||||||
|
item(value = 7, labelType = "1") { paragraph("An ordered item explicitly starting at 7") }
|
||||||
|
}
|
||||||
|
|
||||||
|
divider()
|
||||||
|
|
||||||
|
heading("Code", level = 2)
|
||||||
|
preformatted("val answer = 42", language = "kotlin")
|
||||||
|
|
||||||
|
heading("Quotation", level = 2)
|
||||||
|
blockQuotation {
|
||||||
|
paragraph {
|
||||||
|
plain("Quotations are themselves made of nested blocks — ")
|
||||||
|
italic("including inline formatting")
|
||||||
|
plain(".")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendRichMessageDraft with blocks: the thinking() block is only valid inside a draft and is used
|
||||||
|
// to stream a model's reasoning before the finalized rich message is sent via sendRichMessage.
|
||||||
|
onCommand("rich_blocks_draft") {
|
||||||
|
val chatId = it.chat.id.toChatId()
|
||||||
|
val draftId = 2L
|
||||||
|
listOf("Analyzing your request", "Composing a structured answer").forEach { step ->
|
||||||
|
sendRichMessageDraft(
|
||||||
|
chatId,
|
||||||
|
draftId,
|
||||||
|
InputRichMessageBlocks { thinking(step) }
|
||||||
|
)
|
||||||
|
delay(1000)
|
||||||
|
}
|
||||||
|
// finalize the streamed draft with the real (non-thinking) blocks
|
||||||
|
sendRichMessage(
|
||||||
|
chatId,
|
||||||
|
InputRichMessageBlocks {
|
||||||
|
heading("Answer", level = 2)
|
||||||
|
paragraph("Here is the finalized, structured reply.")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rich message media: send me a photo and it gets embedded into a rich message two ways.
|
||||||
|
onPhoto { message ->
|
||||||
|
// reuse the received file by its fileId (no upload). To upload a brand-new file instead,
|
||||||
|
// build the TelegramMedia from file.asMultipartFile() — SendRichMessage collects any
|
||||||
|
// MultipartFile inside the rich message and uploads it as attach://<id> automatically.
|
||||||
|
val photoMedia = TelegramMediaPhoto(message.content.media.fileId)
|
||||||
|
|
||||||
|
// (1) referenced from HTML via tg://photo?id=<id>, resolved through InputRichMessage.media
|
||||||
|
sendRichMessage(
|
||||||
|
message.chat.id,
|
||||||
|
InputRichMessageHTML(
|
||||||
|
"""
|
||||||
|
<h2>Your photo, referenced from HTML</h2>
|
||||||
|
<p>Below is your photo, referenced via <code>tg://photo?id=userphoto</code>:</p>
|
||||||
|
<img src="tg://photo?id=userphoto"/>
|
||||||
|
""".trimIndent(),
|
||||||
|
media = listOf(
|
||||||
|
InputRichMessageMedia(id = "userphoto", media = photoMedia)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// (2) as a first-class media block inside an InputRichBlocks tree
|
||||||
|
sendRichMessage(
|
||||||
|
message.chat.id,
|
||||||
|
InputRichMessageBlocks {
|
||||||
|
heading("Your photo, as a media block", level = 2)
|
||||||
|
paragraph("The same photo, this time a photo() block inside the blocks tree:")
|
||||||
|
photo(photoMedia)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// waitRichMessage expectation: wait for the user to send a rich message
|
// waitRichMessage expectation: wait for the user to send a rich message
|
||||||
onCommand("wait_rich") {
|
onCommand("wait_rich") {
|
||||||
reply(it, "Send me a rich message now")
|
reply(it, "Send me a rich message now")
|
||||||
@@ -528,7 +637,9 @@ suspend fun main(vararg args: String) {
|
|||||||
setMyCommands(
|
setMyCommands(
|
||||||
BotCommand("rich_html", "Send a rich message described with HTML"),
|
BotCommand("rich_html", "Send a rich message described with HTML"),
|
||||||
BotCommand("rich_markdown", "Send a rich message described with Markdown"),
|
BotCommand("rich_markdown", "Send a rich message described with Markdown"),
|
||||||
|
BotCommand("rich_blocks", "Send a rich message built from the InputRichBlocks DSL"),
|
||||||
BotCommand("rich_draft", "Stream a rich message draft, then finalize it"),
|
BotCommand("rich_draft", "Stream a rich message draft, then finalize it"),
|
||||||
|
BotCommand("rich_blocks_draft", "Stream a blocks draft with thinking(), then finalize it"),
|
||||||
BotCommand("rich_edit", "Send a rich message and edit it with new rich content"),
|
BotCommand("rich_edit", "Send a rich message and edit it with new rich content"),
|
||||||
BotCommand("wait_rich", "Wait for you to send a rich message"),
|
BotCommand("wait_rich", "Wait for you to send a rich message"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=2.3.20
|
kotlin_version=2.3.20
|
||||||
telegram_bot_api_version=35.0.0
|
telegram_bot_api_version=36.0.0
|
||||||
micro_utils_version=0.29.1
|
micro_utils_version=0.29.1
|
||||||
serialization_version=1.10.0
|
serialization_version=1.10.0
|
||||||
ktor_version=3.4.1
|
ktor_version=3.4.1
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
6
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,9 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip
|
|
||||||
networkTimeout=10000
|
|
||||||
retries=0
|
|
||||||
retryBackOffMs=500
|
|
||||||
validateDistributionUrl=true
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
|
|||||||
308
gradlew
vendored
308
gradlew
vendored
@@ -1,128 +1,78 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright © 2015 the original authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
##
|
||||||
# gradlew start up script for POSIX generated by Gradle.
|
## Gradle start up script for UN*X
|
||||||
#
|
##
|
||||||
# Important for running:
|
|
||||||
#
|
|
||||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
||||||
# noncompliant, but you have some other compliant shell such as ksh or
|
|
||||||
# bash, then to run this script, type that shell name before the whole
|
|
||||||
# command line, like:
|
|
||||||
#
|
|
||||||
# ksh gradlew
|
|
||||||
#
|
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
|
||||||
# requires all of these POSIX shell features:
|
|
||||||
# * functions;
|
|
||||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
||||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
||||||
# * compound commands having a testable exit status, especially «case»;
|
|
||||||
# * various built-in commands including «command», «set», and «ulimit».
|
|
||||||
#
|
|
||||||
# Important for patching:
|
|
||||||
#
|
|
||||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
||||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
||||||
#
|
|
||||||
# The "traditional" practice of packing multiple parameters into a
|
|
||||||
# space-separated string is a well documented source of bugs and security
|
|
||||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
||||||
# options in "$@", and eventually passing that to Java.
|
|
||||||
#
|
|
||||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
||||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
||||||
# see the in-line comments for details.
|
|
||||||
#
|
|
||||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
||||||
# Darwin, MinGW, and NonStop.
|
|
||||||
#
|
|
||||||
# (3) This script is generated from the Groovy template
|
|
||||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
||||||
# within the Gradle project.
|
|
||||||
#
|
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
||||||
#
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
app_path=$0
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
# Need this for daisy-chained symlinks.
|
while [ -h "$PRG" ] ; do
|
||||||
while
|
ls=`ls -ld "$PRG"`
|
||||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
[ -h "$app_path" ]
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
do
|
PRG="$link"
|
||||||
ls=$( ls -ld "$app_path" )
|
else
|
||||||
link=${ls#*' -> '}
|
PRG=`dirname "$PRG"`"/$link"
|
||||||
case $link in #(
|
fi
|
||||||
/*) app_path=$link ;; #(
|
|
||||||
*) app_path=$APP_HOME$link ;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
# This is normally unused
|
APP_NAME="Gradle"
|
||||||
# shellcheck disable=SC2034
|
APP_BASE_NAME=`basename "$0"`
|
||||||
APP_BASE_NAME=${0##*/}
|
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
DEFAULT_JVM_OPTS=""
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD="maximum"
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
} >&2
|
}
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
} >&2
|
}
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "$( uname )" in #(
|
case "`uname`" in
|
||||||
CYGWIN* ) cygwin=true ;; #(
|
CYGWIN* )
|
||||||
Darwin* ) darwin=true ;; #(
|
cygwin=true
|
||||||
MSYS* | MINGW* ) msys=true ;; #(
|
;;
|
||||||
NONSTOP* ) nonstop=true ;;
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
NONSTOP* )
|
||||||
|
nonstop=true
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
else
|
else
|
||||||
JAVACMD=$JAVA_HOME/bin/java
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
@@ -131,118 +81,92 @@ Please set the JAVA_HOME variable in your environment to match the
|
|||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD="java"
|
||||||
if ! command -v java >/dev/null 2>&1
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
then
|
|
||||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
case $MAX_FD in #(
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
max*)
|
if [ $? -eq 0 ] ; then
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
# shellcheck disable=SC2039,SC3045
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
|
||||||
warn "Could not query maximum file descriptor limit"
|
|
||||||
esac
|
|
||||||
case $MAX_FD in #(
|
|
||||||
'' | soft) :;; #(
|
|
||||||
*)
|
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
ulimit -n "$MAX_FD" ||
|
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, stacking in reverse order:
|
|
||||||
# * args from the command line
|
|
||||||
# * the main class name
|
|
||||||
# * -classpath
|
|
||||||
# * -D...appname settings
|
|
||||||
# * --module-path (only if needed)
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if "$cygwin" || "$msys" ; then
|
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
|
||||||
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
for arg do
|
|
||||||
if
|
|
||||||
case $arg in #(
|
|
||||||
-*) false ;; # don't mess with options #(
|
|
||||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
|
||||||
[ -e "$t" ] ;; #(
|
|
||||||
*) false ;;
|
|
||||||
esac
|
|
||||||
then
|
|
||||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
||||||
fi
|
fi
|
||||||
# Roll the args list around exactly as many times as the number of
|
ulimit -n $MAX_FD
|
||||||
# args, so each arg winds up back in the position where it started, but
|
if [ $? -ne 0 ] ; then
|
||||||
# possibly modified.
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
#
|
fi
|
||||||
# NB: a `for` loop captures its iteration list before it begins, so
|
else
|
||||||
# changing the positional parameters here affects neither the number of
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
# iterations, nor the values presented in `arg`.
|
fi
|
||||||
shift # remove old arg
|
fi
|
||||||
set -- "$@" "$arg" # push replacement arg
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
|
if $darwin; then
|
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
|
if $cygwin ; then
|
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
SEP=""
|
||||||
|
for dir in $ROOTDIRSRAW ; do
|
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
|
SEP="|"
|
||||||
done
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
(0) set -- ;;
|
||||||
|
(1) set -- "$args0" ;;
|
||||||
|
(2) set -- "$args0" "$args1" ;;
|
||||||
|
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Escape application args
|
||||||
|
save () {
|
||||||
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
|
echo " "
|
||||||
|
}
|
||||||
|
APP_ARGS=$(save "$@")
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||||
# and any embedded shellness will be escaped.
|
cd "$(dirname "$0")"
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
|
||||||
# treated as '${Hostname}' itself on the command line.
|
|
||||||
|
|
||||||
set -- \
|
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
|
||||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
|
||||||
"$@"
|
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
|
||||||
if ! command -v xargs >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "xargs is not available"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
|
||||||
#
|
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
||||||
#
|
|
||||||
# In Bash we could simply go:
|
|
||||||
#
|
|
||||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
||||||
# set -- "${ARGS[@]}" "$@"
|
|
||||||
#
|
|
||||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
||||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
||||||
# character that might be a shell metacharacter, then use eval to reverse
|
|
||||||
# that process (while maintaining the separation between arguments), and wrap
|
|
||||||
# the whole thing up as a single "set" statement.
|
|
||||||
#
|
|
||||||
# This will of course break if any of these variables contains a newline or
|
|
||||||
# an unmatched quote.
|
|
||||||
#
|
|
||||||
|
|
||||||
eval "set -- $(
|
|
||||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
||||||
xargs -n1 |
|
|
||||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
||||||
tr '\n' ' '
|
|
||||||
)" '"$@"'
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
|||||||
100
gradlew.bat
vendored
100
gradlew.bat
vendored
@@ -1,82 +1,84 @@
|
|||||||
@rem
|
@if "%DEBUG%" == "" @echo off
|
||||||
@rem Copyright 2015 the original author or authors.
|
|
||||||
@rem
|
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
@rem you may not use this file except in compliance with the License.
|
|
||||||
@rem You may obtain a copy of the License at
|
|
||||||
@rem
|
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@rem
|
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
@rem See the License for the specific language governing permissions and
|
|
||||||
@rem limitations under the License.
|
|
||||||
@rem
|
|
||||||
@rem SPDX-License-Identifier: Apache-2.0
|
|
||||||
@rem
|
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem gradlew startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@rem
|
@rem
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|
||||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
@rem Set local scope for the variables with windows NT shell
|
||||||
setlocal EnableExtensions
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
@rem This is normally unused
|
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
||||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
@rem Find java.exe
|
@rem Find java.exe
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
echo. 1>&2
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
echo. 1>&2
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation. 1>&2
|
echo location of your Java installation.
|
||||||
|
|
||||||
"%COMSPEC%" /c exit 1
|
goto fail
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
:findJavaFromJavaHome
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
echo. 1>&2
|
echo.
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
echo. 1>&2
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation. 1>&2
|
echo location of your Java installation.
|
||||||
|
|
||||||
"%COMSPEC%" /c exit 1
|
goto fail
|
||||||
|
|
||||||
|
:init
|
||||||
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
|
||||||
|
:win9xME_args
|
||||||
|
@rem Slurp the command line arguments.
|
||||||
|
set CMD_LINE_ARGS=
|
||||||
|
set _SKIP=2
|
||||||
|
|
||||||
|
:win9xME_args_slurp
|
||||||
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
@rem Execute gradlew
|
:end
|
||||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
@rem End local scope for the variables with windows NT shell
|
||||||
@rem which allows us to clear the local environment before executing the java command
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
|
||||||
|
|
||||||
:exitWithErrorLevel
|
:fail
|
||||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
|
|||||||
@@ -81,3 +81,9 @@ include ":ChatManagementBot"
|
|||||||
include ":RichMessagesBot"
|
include ":RichMessagesBot"
|
||||||
|
|
||||||
include ":JoinRequestQueriesBot"
|
include ":JoinRequestQueriesBot"
|
||||||
|
|
||||||
|
include ":EphemeralMessagesBot"
|
||||||
|
|
||||||
|
include ":CommunitiesBot"
|
||||||
|
|
||||||
|
include ":BotSubscriptionsBot"
|
||||||
|
|||||||
Reference in New Issue
Block a user