mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-01-07 05:49:20 +00:00
Compare commits
19 Commits
0.38.9
...
602f15c206
| Author | SHA1 | Date | |
|---|---|---|---|
| 602f15c206 | |||
| c2f40534e6 | |||
| 5693d4d808 | |||
| 9fe55aa6ef | |||
| 8f817f1492 | |||
| 0fd146655d | |||
| 94e5f74a90 | |||
| b9bffbb71b | |||
| 5ec5c3bdfd | |||
| a5ed2a82bb | |||
| 1b7dd11e75 | |||
| 8d0307fb7f | |||
| c500f0a281 | |||
| b3abeaa5ae | |||
| 8930a66134 | |||
| 76a2a2ca74 | |||
| 7dff8af460 | |||
| 5261ab1cf0 | |||
| f45c653fca |
2
.github/workflows/kdocs.yml
vendored
2
.github/workflows/kdocs.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-java@v1
|
- uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
java-version: 11
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./gradlew dokkaHtml
|
run: ./gradlew dokkaHtml
|
||||||
- name: Publish KDocs
|
- name: Publish KDocs
|
||||||
|
|||||||
7
.github/workflows/packages_publishing.yml
vendored
7
.github/workflows/packages_publishing.yml
vendored
@@ -7,10 +7,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-java@v1
|
- uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
java-version: 11
|
||||||
- name: Fix android 31.0.0 dx
|
|
||||||
continue-on-error: true
|
|
||||||
run: cd /usr/local/lib/android/sdk/build-tools/31.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
|
|
||||||
- name: Rewrite version
|
- name: Rewrite version
|
||||||
run: |
|
run: |
|
||||||
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
||||||
@@ -21,7 +18,7 @@ jobs:
|
|||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
- name: Publish
|
- name: Publish
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication
|
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel
|
||||||
env:
|
env:
|
||||||
GITHUBPACKAGES_USER: ${{ github.actor }}
|
GITHUBPACKAGES_USER: ${{ github.actor }}
|
||||||
GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,5 +1,26 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 0.38.11
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `Version`:
|
||||||
|
* `MicroUtils`: `0.9.16` -> `0.9.17`
|
||||||
|
* `Klock`: `2.6.3` -> `2.7.0`
|
||||||
|
* `Core`:
|
||||||
|
* Fixes in `TextSourcesList` creating in from `RawMessageEntities`
|
||||||
|
* Old ways to create keyboards (`matrix` and `row`) have been deprecated
|
||||||
|
* `API`:
|
||||||
|
* Add ability to `reply` with `Poll`
|
||||||
|
* Add ability to `reply` with any `MessageContent`
|
||||||
|
* Add ability to `reply` with any `TelegramMediaFile`
|
||||||
|
|
||||||
|
## 0.38.10
|
||||||
|
|
||||||
|
* `API`:
|
||||||
|
* All `with*Action` extensions got a contracts which declare that `block` will be called once
|
||||||
|
* Add several extensions `TelegramBot#sendPhoto` with `PhotoSize`
|
||||||
|
* Add several extensions `TelegramBot#reply` with `PhotoSize`
|
||||||
|
|
||||||
## 0.38.9
|
## 0.38.9
|
||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# TelegramBotAPI [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [](https://core.telegram.org/bots/api-changelog#january-31-2022)
|
# TelegramBotAPI [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [](https://core.telegram.org/bots/api-changelog#january-31-2022)
|
||||||
|
|
||||||
| [](https://github.com/KotlinBy/awesome-kotlin) [](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [](https://forms.gle/2Hex2ynbHWHhi1KY7) [](https://t.me/InMoTelegramBotAPI) |
|
| [](https://github.com/KotlinBy/awesome-kotlin) [](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) [](https://t.me/InMoTelegramBotAPI) |
|
||||||
|:---:|
|
|:---:|
|
||||||
| [](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) [](https://tgbotapi.inmo.dev/index.html) [](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|
| [](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) [](https://tgbotapi.inmo.dev/index.html) [](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|
||||||
|
|
||||||
Hello! This is a set of libraries for working with Telegram Bot API.
|
Hello! This is a set of libraries for working with Telegram Bot API.
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ kotlin.incremental.js=true
|
|||||||
kotlin_version=1.6.10
|
kotlin_version=1.6.10
|
||||||
kotlin_coroutines_version=1.6.0
|
kotlin_coroutines_version=1.6.0
|
||||||
kotlin_serialisation_runtime_version=1.3.2
|
kotlin_serialisation_runtime_version=1.3.2
|
||||||
klock_version=2.6.3
|
klock_version=2.7.0
|
||||||
uuid_version=0.4.0
|
uuid_version=0.4.0
|
||||||
ktor_version=1.6.8
|
ktor_version=1.6.8
|
||||||
|
|
||||||
micro_utils_version=0.9.16
|
micro_utils_version=0.9.17
|
||||||
|
|
||||||
javax_activation_version=1.1.1
|
javax_activation_version=1.1.1
|
||||||
|
|
||||||
@@ -20,6 +20,6 @@ javax_activation_version=1.1.1
|
|||||||
dokka_version=1.6.10
|
dokka_version=1.6.10
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=0.38.9
|
library_version=0.38.11
|
||||||
|
|
||||||
github_release_plugin_version=2.2.12
|
github_release_plugin_version=2.2.12
|
||||||
|
|||||||
@@ -17,10 +17,14 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
|||||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
import dev.inmo.tgbotapi.types.dice.DiceAnimationType
|
import dev.inmo.tgbotapi.types.dice.DiceAnimationType
|
||||||
import dev.inmo.tgbotapi.types.files.*
|
import dev.inmo.tgbotapi.types.files.*
|
||||||
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
import dev.inmo.tgbotapi.types.files.sticker.Sticker
|
import dev.inmo.tgbotapi.types.files.sticker.Sticker
|
||||||
import dev.inmo.tgbotapi.types.games.Game
|
import dev.inmo.tgbotapi.types.games.Game
|
||||||
import dev.inmo.tgbotapi.types.location.StaticLocation
|
import dev.inmo.tgbotapi.types.location.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile
|
||||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||||
import dev.inmo.tgbotapi.types.polls.*
|
import dev.inmo.tgbotapi.types.polls.*
|
||||||
@@ -118,6 +122,7 @@ suspend inline fun TelegramBot.reply(
|
|||||||
longitude: Double,
|
longitude: Double,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(
|
) = sendLocation(
|
||||||
to.chat,
|
to.chat,
|
||||||
@@ -125,6 +130,7 @@ suspend inline fun TelegramBot.reply(
|
|||||||
longitude,
|
longitude,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
protectContent,
|
protectContent,
|
||||||
|
allowSendingWithoutReply,
|
||||||
to.messageId,
|
to.messageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
@@ -138,12 +144,14 @@ suspend inline fun TelegramBot.reply(
|
|||||||
location: StaticLocation,
|
location: StaticLocation,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(
|
) = sendLocation(
|
||||||
to.chat,
|
to.chat,
|
||||||
location,
|
location,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
protectContent,
|
protectContent,
|
||||||
|
allowSendingWithoutReply,
|
||||||
to.messageId,
|
to.messageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
@@ -571,6 +579,17 @@ suspend inline fun TelegramBot.reply(
|
|||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
suspend inline fun TelegramBot.reply(
|
||||||
|
to: Message,
|
||||||
|
photoSize: PhotoSize,
|
||||||
|
text: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendPhoto(to.chat, photoSize, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
|
||||||
suspend inline fun TelegramBot.replyWithPhoto(
|
suspend inline fun TelegramBot.replyWithPhoto(
|
||||||
to: Message,
|
to: Message,
|
||||||
@@ -592,6 +611,16 @@ suspend inline fun TelegramBot.reply(
|
|||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendPhoto(to.chat, photo, entities, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
) = sendPhoto(to.chat, photo, entities, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
suspend inline fun TelegramBot.reply(
|
||||||
|
to: Message,
|
||||||
|
photoSize: PhotoSize,
|
||||||
|
entities: TextSourcesList,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendPhoto(to.chat, photoSize, entities, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
|
||||||
// Sticker
|
// Sticker
|
||||||
|
|
||||||
@@ -866,6 +895,52 @@ suspend inline fun TelegramBot.reply(
|
|||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
|
||||||
|
suspend inline fun TelegramBot.reply(
|
||||||
|
to: Message,
|
||||||
|
poll: Poll,
|
||||||
|
isClosed: Boolean = false,
|
||||||
|
question: String = poll.question,
|
||||||
|
options: List<String> = poll.options.map { it.text },
|
||||||
|
isAnonymous: Boolean = poll.isAnonymous,
|
||||||
|
closeInfo: ScheduledCloseInfo? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = when (poll) {
|
||||||
|
is RegularPoll -> reply(
|
||||||
|
to = to,
|
||||||
|
poll = poll,
|
||||||
|
isClosed = isClosed,
|
||||||
|
question = question,
|
||||||
|
options = options,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
allowMultipleAnswers = isAnonymous,
|
||||||
|
closeInfo = closeInfo,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
is UnknownPollType -> error("Unable to send poll with unknown type ($poll)")
|
||||||
|
is QuizPoll -> reply(
|
||||||
|
to = to,
|
||||||
|
quizPoll = poll,
|
||||||
|
entities = poll.textSources,
|
||||||
|
isClosed = isClosed,
|
||||||
|
question = question,
|
||||||
|
options = options,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
closeInfo = closeInfo,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
suspend inline fun TelegramBot.reply(
|
suspend inline fun TelegramBot.reply(
|
||||||
to: Message,
|
to: Message,
|
||||||
fromChatId: ChatIdentifier,
|
fromChatId: ChatIdentifier,
|
||||||
@@ -900,3 +975,99 @@ suspend inline fun TelegramBot.reply(
|
|||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = reply(to, copy.chat.id, copy.messageId, text, parseMode, disableNotification, protectContent, allowSendingWithoutReply, replyMarkup)
|
) = reply(to, copy.chat.id, copy.messageId, text, parseMode, disableNotification, protectContent, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.reply(
|
||||||
|
to: Message,
|
||||||
|
content: MessageContent,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) {
|
||||||
|
execute(
|
||||||
|
content.createResend(
|
||||||
|
to.chat.id,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
to.messageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun TelegramBot.reply(
|
||||||
|
to: Message,
|
||||||
|
mediaFile: TelegramMediaFile,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) {
|
||||||
|
when (mediaFile) {
|
||||||
|
is AudioFile -> reply(
|
||||||
|
to = to,
|
||||||
|
audio = mediaFile,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
is AnimationFile -> reply(
|
||||||
|
to = to,
|
||||||
|
animation = mediaFile,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
is VoiceFile -> reply(
|
||||||
|
to = to,
|
||||||
|
voice = mediaFile,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
is VideoFile -> reply(
|
||||||
|
to = to,
|
||||||
|
video = mediaFile,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
is VideoNoteFile -> reply(
|
||||||
|
to = to,
|
||||||
|
videoNote = mediaFile,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
is DocumentFile -> reply(
|
||||||
|
to = to,
|
||||||
|
document = mediaFile,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
is Sticker -> reply(
|
||||||
|
to = to,
|
||||||
|
sticker = mediaFile,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
else -> reply(
|
||||||
|
to = to,
|
||||||
|
document = mediaFile.asDocumentFile(),
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,15 +8,20 @@ import dev.inmo.tgbotapi.types.*
|
|||||||
import dev.inmo.tgbotapi.types.actions.*
|
import dev.inmo.tgbotapi.types.actions.*
|
||||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlin.contracts.*
|
||||||
import kotlin.coroutines.coroutineContext
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L
|
private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L
|
||||||
typealias TelegramBotActionCallback<T> = suspend TelegramBot.() -> T
|
typealias TelegramBotActionCallback<T> = suspend TelegramBot.() -> T
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
suspend fun <T> TelegramBot.withAction(
|
suspend fun <T> TelegramBot.withAction(
|
||||||
actionRequest: SendAction,
|
actionRequest: SendAction,
|
||||||
block: TelegramBotActionCallback<T>
|
block: TelegramBotActionCallback<T>
|
||||||
): T {
|
): T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
val botActionJob = CoroutineScope(coroutineContext).launch {
|
val botActionJob = CoroutineScope(coroutineContext).launch {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(refreshTime)
|
delay(refreshTime)
|
||||||
@@ -30,46 +35,190 @@ suspend fun <T> TelegramBot.withAction(
|
|||||||
return result.getOrThrow()
|
return result.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
suspend fun <T> TelegramBot.withAction(
|
suspend fun <T> TelegramBot.withAction(
|
||||||
chatId: ChatId,
|
chatId: ChatId,
|
||||||
action: BotAction,
|
action: BotAction,
|
||||||
block: TelegramBotActionCallback<T>
|
block: TelegramBotActionCallback<T>
|
||||||
) = withAction(
|
): T {
|
||||||
SendAction(chatId, action),
|
contract {
|
||||||
block
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
)
|
}
|
||||||
|
return withAction(
|
||||||
|
SendAction(chatId, action),
|
||||||
|
block
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
suspend fun <T> TelegramBot.withAction(
|
suspend fun <T> TelegramBot.withAction(
|
||||||
chat: Chat,
|
chat: Chat,
|
||||||
action: BotAction,
|
action: BotAction,
|
||||||
block: TelegramBotActionCallback<T>
|
block: TelegramBotActionCallback<T>
|
||||||
) = withAction(
|
): T {
|
||||||
chat.id,
|
contract {
|
||||||
action,
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
block
|
}
|
||||||
)
|
return withAction(
|
||||||
|
chat.id,
|
||||||
|
action,
|
||||||
|
block
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun <T> TelegramBot.withTypingAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, TypingAction, block)
|
@OptIn(ExperimentalContracts::class)
|
||||||
suspend fun <T> TelegramBot.withUploadPhotoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadPhotoAction, block)
|
suspend fun <T> TelegramBot.withTypingAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
suspend fun <T> TelegramBot.withRecordVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVideoAction, block)
|
contract {
|
||||||
suspend fun <T> TelegramBot.withUploadVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVideoAction, block)
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
suspend fun <T> TelegramBot.withRecordVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVoiceAction, block)
|
}
|
||||||
suspend fun <T> TelegramBot.withUploadVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVoiceAction, block)
|
return withAction(chatId, TypingAction, block)
|
||||||
suspend fun <T> TelegramBot.withUploadDocumentAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadDocumentAction, block)
|
}
|
||||||
suspend fun <T> TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, FindLocationAction, block)
|
@OptIn(ExperimentalContracts::class)
|
||||||
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVideoNoteAction, block)
|
suspend fun <T> TelegramBot.withUploadPhotoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVideoNoteAction, block)
|
contract {
|
||||||
suspend fun <T> TelegramBot.withChooseStickerAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, ChooseStickerAction, block)
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, UploadPhotoAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, RecordVideoAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, UploadVideoAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, RecordVoiceAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, UploadVoiceAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadDocumentAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, UploadDocumentAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, FindLocationAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, RecordVideoNoteAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, UploadVideoNoteAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withChooseStickerAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chatId, ChooseStickerAction, block)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
suspend fun <T> TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, TypingAction, block)
|
@OptIn(ExperimentalContracts::class)
|
||||||
suspend fun <T> TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadPhotoAction, block)
|
suspend fun <T> TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
suspend fun <T> TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVideoAction, block)
|
contract {
|
||||||
suspend fun <T> TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVideoAction, block)
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
suspend fun <T> TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVoiceAction, block)
|
}
|
||||||
suspend fun <T> TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVoiceAction, block)
|
return withAction(chat, TypingAction, block)
|
||||||
suspend fun <T> TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadDocumentAction, block)
|
}
|
||||||
suspend fun <T> TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, FindLocationAction, block)
|
@OptIn(ExperimentalContracts::class)
|
||||||
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVideoNoteAction, block)
|
suspend fun <T> TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVideoNoteAction, block)
|
contract {
|
||||||
suspend fun <T> TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, ChooseStickerAction, block)
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, UploadPhotoAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, RecordVideoAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, UploadVideoAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, RecordVoiceAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, UploadVoiceAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, UploadDocumentAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, FindLocationAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, RecordVideoNoteAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, UploadVideoNoteAction, block)
|
||||||
|
}
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
suspend fun <T> TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
|
||||||
|
contract {
|
||||||
|
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
return withAction(chat, ChooseStickerAction, block)
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
longitude: Double,
|
longitude: Double,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
@@ -27,6 +28,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
longitude,
|
longitude,
|
||||||
disableNotification = disableNotification,
|
disableNotification = disableNotification,
|
||||||
protectContent = protectContent,
|
protectContent = protectContent,
|
||||||
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
replyToMessageId = replyToMessageId,
|
replyToMessageId = replyToMessageId,
|
||||||
replyMarkup = replyMarkup
|
replyMarkup = replyMarkup
|
||||||
)
|
)
|
||||||
@@ -41,6 +43,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
location: StaticLocation,
|
location: StaticLocation,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(
|
) = sendLocation(
|
||||||
@@ -49,6 +52,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
location.longitude,
|
location.longitude,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
protectContent,
|
protectContent,
|
||||||
|
allowSendingWithoutReply,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
@@ -63,6 +67,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
longitude: Double,
|
longitude: Double,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(
|
) = sendLocation(
|
||||||
@@ -71,6 +76,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
longitude,
|
longitude,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
protectContent,
|
protectContent,
|
||||||
|
allowSendingWithoutReply,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
@@ -84,6 +90,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
location: StaticLocation,
|
location: StaticLocation,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(
|
) = sendLocation(
|
||||||
@@ -92,6 +99,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
location.longitude,
|
location.longitude,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
protectContent,
|
protectContent,
|
||||||
|
allowSendingWithoutReply,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
@@ -106,9 +114,10 @@ suspend fun TelegramBot.sendStaticLocation(
|
|||||||
longitude: Double,
|
longitude: Double,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(chatId, latitude, longitude, disableNotification, protectContent, replyToMessageId, replyMarkup)
|
) = sendLocation(chatId, latitude, longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
@@ -119,9 +128,10 @@ suspend fun TelegramBot.sendStaticLocation(
|
|||||||
location: StaticLocation,
|
location: StaticLocation,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, protectContent, replyToMessageId, replyMarkup)
|
) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
@@ -133,9 +143,10 @@ suspend fun TelegramBot.sendStaticLocation(
|
|||||||
longitude: Double,
|
longitude: Double,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(chat.id, latitude, longitude, disableNotification, protectContent, replyToMessageId, replyMarkup)
|
) = sendLocation(chat.id, latitude, longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
@@ -146,6 +157,7 @@ suspend fun TelegramBot.sendStaticLocation(
|
|||||||
location: StaticLocation,
|
location: StaticLocation,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, protectContent, replyToMessageId, replyMarkup)
|
) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import dev.inmo.tgbotapi.types.MessageIdentifier
|
|||||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
import dev.inmo.tgbotapi.types.files.Photo
|
import dev.inmo.tgbotapi.types.files.*
|
||||||
import dev.inmo.tgbotapi.types.files.biggest
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
@@ -88,6 +87,38 @@ suspend fun TelegramBot.sendPhoto(
|
|||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendPhoto(chat.id, photo, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
) = sendPhoto(chat.id, photo, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendPhoto(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
photoSize: PhotoSize,
|
||||||
|
text: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendPhoto(chatId, photoSize.fileId, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendPhoto(
|
||||||
|
chat: Chat,
|
||||||
|
photoSize: PhotoSize,
|
||||||
|
text: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendPhoto(chat.id, photoSize, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
@@ -159,3 +190,33 @@ suspend inline fun TelegramBot.sendPhoto(
|
|||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendPhoto(chat.id, photo, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
) = sendPhoto(chat.id, photo, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.sendPhoto(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
photoSize: PhotoSize,
|
||||||
|
entities: TextSourcesList,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendPhoto(chatId, photoSize.fileId, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.sendPhoto(
|
||||||
|
chat: Chat,
|
||||||
|
photoSize: PhotoSize,
|
||||||
|
entities: TextSourcesList,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendPhoto(chat.id, photoSize, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ internal data class RawMessageEntity(
|
|||||||
|
|
||||||
internal fun RawMessageEntity.asTextSource(
|
internal fun RawMessageEntity.asTextSource(
|
||||||
source: String,
|
source: String,
|
||||||
subParts: TextSourcesList
|
subParts: List<Pair<Int, TextSource>>
|
||||||
): TextSource {
|
): TextSource {
|
||||||
val sourceSubstring: String = source.substring(range)
|
val sourceSubstring: String = source.substring(range)
|
||||||
val subPartsWithRegulars by lazy {
|
val subPartsWithRegulars by lazy {
|
||||||
subParts.fillWithRegulars(sourceSubstring)
|
subParts.map { (it.first - offset) to it.second }.fillWithRegulars(sourceSubstring)
|
||||||
}
|
}
|
||||||
return when (type) {
|
return when (type) {
|
||||||
"mention" -> MentionTextSource(sourceSubstring, subPartsWithRegulars)
|
"mention" -> MentionTextSource(sourceSubstring, subPartsWithRegulars)
|
||||||
@@ -58,16 +58,14 @@ private inline operator fun <T : Comparable<T>> ClosedRange<T>.contains(other: C
|
|||||||
return start <= other.start && endInclusive >= other.endInclusive
|
return start <= other.start && endInclusive >= other.endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun TextSourcesList.fillWithRegulars(source: String): TextSourcesList {
|
internal fun List<Pair<Int, TextSource>>.fillWithRegulars(source: String): TextSourcesList {
|
||||||
var index = 0
|
var index = 0
|
||||||
val result = mutableListOf<TextSource>()
|
val result = mutableListOf<TextSource>()
|
||||||
for (i in 0 until size) {
|
for (i in indices) {
|
||||||
val textSource = get(i)
|
val (offset, textSource) = get(i)
|
||||||
val thisSourceInStart = source.startsWith(textSource.source, index)
|
if (offset - index > 0) {
|
||||||
if (!thisSourceInStart) {
|
result.add(regular(source.substring(index, offset)))
|
||||||
val regularEndIndex = source.indexOf(textSource.source, index)
|
index = offset
|
||||||
result.add(regular(source.substring(index, regularEndIndex)))
|
|
||||||
index = regularEndIndex
|
|
||||||
}
|
}
|
||||||
result.add(textSource)
|
result.add(textSource)
|
||||||
index += textSource.source.length
|
index += textSource.source.length
|
||||||
@@ -83,9 +81,9 @@ internal fun TextSourcesList.fillWithRegulars(source: String): TextSourcesList {
|
|||||||
private fun createTextSources(
|
private fun createTextSources(
|
||||||
originalFullString: String,
|
originalFullString: String,
|
||||||
entities: RawMessageEntities
|
entities: RawMessageEntities
|
||||||
): TextSourcesList {
|
): List<Pair<Int, TextSource>> {
|
||||||
val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } }
|
val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } }
|
||||||
val resultList = mutableListOf<TextSource>()
|
val resultList = mutableListOf<Pair<Int, TextSource>>()
|
||||||
|
|
||||||
while (mutableEntities.isNotEmpty()) {
|
while (mutableEntities.isNotEmpty()) {
|
||||||
var parent = mutableEntities.removeFirst()
|
var parent = mutableEntities.removeFirst()
|
||||||
@@ -129,7 +127,7 @@ private fun createTextSources(
|
|||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
resultList.add(
|
resultList.add(
|
||||||
parent.asTextSource(
|
parent.offset to parent.asTextSource(
|
||||||
originalFullString,
|
originalFullString,
|
||||||
subtextSources
|
subtextSources
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,34 +2,69 @@ package dev.inmo.tgbotapi.utils
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.Matrix
|
import dev.inmo.tgbotapi.types.buttons.Matrix
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
|
||||||
|
*/
|
||||||
|
@Deprecated("This functionality will be removed soon")
|
||||||
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> {
|
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> {
|
||||||
return RowBuilder<T>().also(block).row
|
return RowBuilder<T>().also(block).row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
|
||||||
|
*/
|
||||||
|
@Deprecated("This functionality will be removed soon")
|
||||||
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
|
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
|
||||||
add(RowBuilder<T>().also(block).row)
|
add(RowBuilder<T>().also(block).row)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
|
||||||
|
*/
|
||||||
|
@Deprecated("This functionality will be removed soon")
|
||||||
fun <T> MatrixBuilder<T>.row(vararg elements: T) {
|
fun <T> MatrixBuilder<T>.row(vararg elements: T) {
|
||||||
add(elements.toList())
|
add(elements.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
|
||||||
|
*/
|
||||||
|
@Deprecated("This functionality will be removed soon")
|
||||||
fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
|
fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
|
||||||
return MatrixBuilder<T>().also(block).matrix
|
return MatrixBuilder<T>().also(block).matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
|
||||||
|
*/
|
||||||
|
@Deprecated("This functionality will be removed soon")
|
||||||
fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
|
fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
|
||||||
return MatrixBuilder<T>().apply {
|
return MatrixBuilder<T>().apply {
|
||||||
row(block)
|
row(block)
|
||||||
}.matrix
|
}.matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
|
||||||
|
*/
|
||||||
|
@Deprecated("This functionality will be removed soon")
|
||||||
fun <T> flatMatrix(vararg elements: T): Matrix<T> {
|
fun <T> flatMatrix(vararg elements: T): Matrix<T> {
|
||||||
return MatrixBuilder<T>().apply {
|
return MatrixBuilder<T>().apply {
|
||||||
row { elements.forEach { +it } }
|
row { elements.forEach { +it } }
|
||||||
}.matrix
|
}.matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
|
||||||
|
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
|
||||||
|
*/
|
||||||
|
@Deprecated("This functionality will be removed soon")
|
||||||
operator fun <T> RowBuilder<T>.plus(t: T) = add(t)
|
operator fun <T> RowBuilder<T>.plus(t: T) = add(t)
|
||||||
|
|
||||||
open class RowBuilder<T> {
|
open class RowBuilder<T> {
|
||||||
|
|||||||
@@ -3,43 +3,43 @@ package dev.inmo.tgbotapi.types.MessageEntity
|
|||||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
const val testText = "It is simple hello world with #tag and @mention"
|
const val testText = "It (is?) is simple hello world with #tag and @mention"
|
||||||
const val formattedV2Text = "It *_is_ ~__simple__~* ||hello world|| with \\#tag and @mention"
|
const val formattedV2Text = "It \\(is?\\) *_is_ ~__simple__~* ||hello world|| with \\#tag and @mention"
|
||||||
const val formattedHtmlText = "It <b><i>is</i> <s><u>simple</u></s></b> <span class=\"tg-spoiler\">hello world</span> with #tag and @mention"
|
const val formattedHtmlText = "It (is?) <b><i>is</i> <s><u>simple</u></s></b> <span class=\"tg-spoiler\">hello world</span> with #tag and @mention"
|
||||||
internal val testTextEntities = listOf(
|
internal val testTextEntities = listOf(
|
||||||
RawMessageEntity(
|
RawMessageEntity(
|
||||||
"bold",
|
"bold",
|
||||||
3,
|
9,
|
||||||
9
|
9
|
||||||
),
|
),
|
||||||
RawMessageEntity(
|
RawMessageEntity(
|
||||||
"italic",
|
"italic",
|
||||||
3,
|
9,
|
||||||
2
|
2
|
||||||
),
|
),
|
||||||
RawMessageEntity(
|
RawMessageEntity(
|
||||||
"strikethrough",
|
"strikethrough",
|
||||||
6,
|
12,
|
||||||
6
|
6
|
||||||
),
|
),
|
||||||
RawMessageEntity(
|
RawMessageEntity(
|
||||||
"underline",
|
"underline",
|
||||||
6,
|
12,
|
||||||
6
|
6
|
||||||
),
|
),
|
||||||
RawMessageEntity(
|
RawMessageEntity(
|
||||||
"spoiler",
|
"spoiler",
|
||||||
13,
|
19,
|
||||||
11
|
11
|
||||||
),
|
),
|
||||||
RawMessageEntity(
|
RawMessageEntity(
|
||||||
"hashtag",
|
"hashtag",
|
||||||
30,
|
36,
|
||||||
4
|
4
|
||||||
),
|
),
|
||||||
RawMessageEntity(
|
RawMessageEntity(
|
||||||
"mention",
|
"mention",
|
||||||
39,
|
45,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.types.MessageEntity
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
||||||
import kotlin.test.Test
|
import kotlin.test.*
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class StringFormattingTests {
|
class StringFormattingTests {
|
||||||
@Test
|
@Test
|
||||||
@@ -38,7 +37,7 @@ class StringFormattingTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() {
|
fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() {
|
||||||
val sources: TextSourcesList = regular("It ") +
|
val sources: TextSourcesList = regular("It (is?) ") +
|
||||||
bold(italic("is") +
|
bold(italic("is") +
|
||||||
" " +
|
" " +
|
||||||
strikethrough(underline("simple"))) +
|
strikethrough(underline("simple"))) +
|
||||||
@@ -53,4 +52,43 @@ class StringFormattingTests {
|
|||||||
assertEquals(formattedV2Text, sources.toMarkdownV2Texts().first())
|
assertEquals(formattedV2Text, sources.toMarkdownV2Texts().first())
|
||||||
assertEquals(formattedHtmlText, sources.toHtmlTexts().first())
|
assertEquals(formattedHtmlText, sources.toHtmlTexts().first())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testForRepeatingWordsInOneSentenceWithTheSecondOneFormatted() {
|
||||||
|
val sourceText = "link link"
|
||||||
|
val messageEntities = listOf(
|
||||||
|
RawMessageEntity("bold", 5, 4),
|
||||||
|
RawMessageEntity("text_link", 6, 2, "google.com")
|
||||||
|
)
|
||||||
|
val textSources = messageEntities.asTextSources(sourceText)
|
||||||
|
val (regular, bold) = textSources
|
||||||
|
assertTrue(regular is RegularTextSource)
|
||||||
|
assertTrue(bold is BoldTextSource)
|
||||||
|
assertTrue(regular.source == "link ")
|
||||||
|
assertTrue(bold.source == "link")
|
||||||
|
assertTrue((bold.subsources[0] as? RegularTextSource) ?.source == "l")
|
||||||
|
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.source == "in")
|
||||||
|
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.url == "google.com")
|
||||||
|
assertTrue((bold.subsources[2] as? RegularTextSource) ?.source == "k")
|
||||||
|
assertTrue(bold.subsources.size == 3)
|
||||||
|
assertTrue(textSources.size == 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testForRepeatingWordsInOneSentenceWithTheSecondOneFormattedInsideOfFormatting() {
|
||||||
|
val sourceText = "text"
|
||||||
|
val messageEntities = listOf(
|
||||||
|
RawMessageEntity("bold", 0, 4),
|
||||||
|
RawMessageEntity("text_link", 3, 1, "google.com")
|
||||||
|
)
|
||||||
|
val textSources = messageEntities.asTextSources(sourceText)
|
||||||
|
val (bold) = textSources
|
||||||
|
assertTrue(bold is BoldTextSource)
|
||||||
|
assertTrue(bold.source == "text")
|
||||||
|
assertTrue((bold.subsources[0] as? RegularTextSource) ?.source == "tex")
|
||||||
|
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.source == "t")
|
||||||
|
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.url == "google.com")
|
||||||
|
assertTrue(bold.subsources.size == 2)
|
||||||
|
assertTrue(textSources.size == 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user