1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-11-17 04:20:13 +00:00

Compare commits

..

45 Commits

Author SHA1 Message Date
fb8cfed382 hotfix 2021-12-20 14:07:45 +06:00
2de22a08a3 Merge pull request #506 from InsanusMokrassar/0.37.2
0.37.2
2021-12-20 13:00:07 +06:00
e8022a2ded add kdocs to the requests 2021-12-20 12:50:06 +06:00
d6cef5984b filling of changelog and several fixes 2021-12-20 12:47:55 +06:00
49bea1bcef update gradle wrapper 2021-12-20 12:32:21 +06:00
85a4459072 Update RawMessage.kt 2021-12-19 00:46:06 +06:00
ce74631580 actualizing of readmes 2021-12-18 23:19:05 +06:00
1e5ce6bb5c add ContentMessage#hasProtectedContent 2021-12-18 23:12:12 +06:00
dc89e914a1 support of has_protected_content field 2021-12-18 23:11:28 +06:00
ee815c7335 update micro_utils 2021-12-18 22:29:25 +06:00
69f4033807 add support of is_automatic_forward 2021-12-18 22:28:01 +06:00
0581587adf add support of has_private_forwards 2021-12-10 12:53:00 +06:00
23f93075a4 update microutils and add banChatSenderChat and unbanChatSenderChat support 2021-12-10 12:49:13 +06:00
6c3425d5f9 Update CHANGELOG.md 2021-12-04 21:23:34 +06:00
d285590348 Update gradle-wrapper.properties 2021-12-04 21:12:12 +06:00
2e0ad6dd3c Merge pull request #505 from InsanusMokrassar/fix/linkln
Fix of linkln
2021-12-04 21:08:46 +06:00
96a5e55894 Merge pull request #499 from InsanusMokrassar/renovate/micro_utils_version
Update micro_utils_version to v0.8.5
2021-12-04 21:08:06 +06:00
4e3b085cdb start 0.37.2 2021-12-04 21:07:00 +06:00
8baa601af7 Fix of linkln 2021-12-04 12:51:55 +06:00
Renovate Bot
facd732fa8 Update micro_utils_version to v0.8.5 2021-11-27 17:38:58 +00:00
e19561367e Merge pull request #500 from InsanusMokrassar/0.37.1
0.37.1
2021-11-14 20:03:57 +06:00
249efeee7e update scripts 2021-11-14 19:42:03 +06:00
b8cc2421b6 update dependencies 2021-11-14 19:15:09 +06:00
2fa1a064ec start 0.37.1 2021-11-14 19:14:06 +06:00
63e864741e update changelog and several kdocs 2021-11-11 12:24:10 +06:00
e4f35c0eba update KDocs 2021-11-11 12:11:58 +06:00
944fe6d820 Update CHANGELOG.md 2021-11-11 11:14:05 +06:00
8ea50f36aa Merge pull request #493 from InsanusMokrassar/0.37.0
0.37.0
2021-11-10 14:48:53 +06:00
17308a6d99 update gradle distro 2021-11-10 13:06:43 +06:00
6eabea2529 Update CHANGELOG.md 2021-11-09 19:23:41 +06:00
ffe9166fee Update gradle.properties 2021-11-09 19:23:27 +06:00
f1be3e2819 Update README.md 2021-11-09 14:09:20 +06:00
c4c016c438 update common readme 2021-11-09 13:40:38 +06:00
a85e7d7387 fixes 2021-11-09 00:32:04 +06:00
fc59ab0cdd add class casts for ChatInviteLink 2021-11-08 19:15:58 +06:00
9ed7ded967 fix texts of bot actions 2021-11-08 19:07:02 +06:00
a76a7ae630 add choose_sticker 2021-11-08 18:36:17 +06:00
4715eb424f add support of join request approving/declining 2021-11-08 18:33:24 +06:00
c24d536d4c add ChatJoinRequest 2021-11-08 18:21:55 +06:00
c969d88bf0 update invite links and add name field 2021-11-08 18:00:43 +06:00
44e9dc9253 remove deprecations 2021-11-08 17:33:02 +06:00
10c62bf2c7 chat invite links update 2021-11-08 17:27:15 +06:00
20b1645935 start migrate fsm part 2021-11-06 21:21:49 +06:00
c5bf9ab1a2 Update CHANGELOG.md 2021-11-05 22:04:55 +06:00
cd6d108a9a Update gradle.properties 2021-11-05 22:03:42 +06:00
72 changed files with 1532 additions and 385 deletions

View File

@@ -1,12 +1,84 @@
# TelegramBotAPI changelog
## 0.36.1
## 0.37.3 Hotfix of 0.37.3
* `Core`:
* Fixes in hierarchy (and creating) of messages from channels
---
`0.37.2` changelog:
* `Common`:
* `Version`:
* `MicroUtils`: `0.8.2` -> `0.8.7`
* `Core`:
* New request type: `ChatSenderRequest`
* New request `BanChatSenderChat`
* New request `UnbanChatSenderChat`
* `ExtendedPrivateChat` got new properties: `hasPrivateForwards` and `allowCreateUserIdLink` (same as `hasPrivateForwards`)
* All `ContentMessage` got field `forwardable` (old constructors marked as `Deprecated`)
* `FromChannelGroupContentMessage` has been divided for two interfaces (and corresponding classes):
* `ConnectedFromChannelGroupContentMessage` (and `ConnectedFromChannelGroupContentMessageImpl`) for connected to the group channels messages
* `UnconnectedFromChannelGroupContentMessage` (and `UnconnectedFromChannelGroupContentMessageImpl`) for unconnected channels
* `API`:
* New extensions `TelegramBot#banChatSenderChat`
* New extensions `TelegramBot#unbanChatSenderChat`
* `Utils`:
* Fix of `EntitiesBuilder#linkln`
## 0.37.2 Telegram Bot API 5.5
* `Common`:
* `Version`:
* `MicroUtils`: `0.8.2` -> `0.8.7`
* `Core`:
* New request type: `ChatSenderRequest`
* New request `BanChatSenderChat`
* New request `UnbanChatSenderChat`
* `ExtendedPrivateChat` got new properties: `hasPrivateForwards` and `allowCreateUserIdLink` (same as `hasPrivateForwards`)
* All `ContentMessage` got field `forwardable` (old constructors marked as `Deprecated`)
* `ChannelContentMessage` has been divided for two interfaces (and corresponding classes):
* `ConnectedChannelContentMessage` (and `ConnectedChannelContentMessageImpl`) for connected to the group channels messages
* `UnconnectedChannelContentMessage` (and `UnconnectedChannelContentMessageImpl`) for unconnected channels
* `API`:
* New extensions `TelegramBot#banChatSenderChat`
* New extensions `TelegramBot#unbanChatSenderChat`
* `Utils`:
* Fix of `EntitiesBuilder#linkln`
## 0.37.1
* `Common`:
* `Version`:
* `Serialization`: `1.3.0` -> `1.3.1`
* `Klock`: `2.4.7` -> `2.4.8`
* `MicroUtils`: `0.8.1` -> `0.8.2`
## 0.37.0 Telegram Bot API 5.4
**ALL DEPRECATIONS WERE REMOVED**
* `Common`:
* `Version`:
* `Klock`: `2.4.6` -> `2.4.7`
* `Ktor`: `1.6.4` -> `1.6.5`
* `MicroUtils`: `0.7.3` -> `0.7.5`
* `MicroUtils`: `0.7.3` -> `0.8.1`
* `Core`:
* Replacement of simple `CreateChatInviteLink` and `EditChatInviteLink` with several new:
* `CreateChatInviteLinkSimple`
* `CreateChatInviteLinkWithLimitedMembers`
* `CreateChatInviteLinkWithJoinRequest`
* `EditChatInviteLinkSimple`
* `EditChatInviteLinkWithLimitedMembers`
* `EditChatInviteLinkWithJoinRequest`
* New `BotAction`: `ChooseStickerAction`
* Now requester will throw exceptions related to responses decoding directly instead of wrapping in
`RequestException`
*
* `BehaviourBuilder FSM`:
* **Incompatible changes** (now generics are used in state machines)
* `strictlyOn` and `onStateOrSubstate` now are part of `BehaviourContextWithFSMBuilder`
## 0.36.1

View File

@@ -1,28 +1,11 @@
[Participate in our common survey ☺](https://forms.gle/q6Xf8K3fD1pPsYUw9)
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-5.5-blue)](https://core.telegram.org/bots/api-changelog#december-7-2021)
# TelegramBotAPI
- [TelegramBotAPI](#telegrambotapi)
* [Examples](#examples)
+ [Most common example](#most-common-example)
+ [Handling only last messages](#handling-only-last-messages)
+ [Build a little bit more complex behaviour](#build-a-little-bit-more-complex-behaviour)
+ [More examples](#more-examples)
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
| [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue)](https://forms.gle/2Hex2ynbHWHhi1KY7) [![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue)](https://t.me/InMoTelegramBotAPI) |
|:---:|
| [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
Hello! This is a set of libraries for working with Telegram Bot API.
| Common info | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Useful links | [![Chat in Telegram](https://img.shields.io/static/v1?label=Talk&message=Telegram&color=blue)](https://t.me/InMoTelegramBotAPI) [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![KDocs](https://img.shields.io/static/v1?label=Open&message=kdocs&color=blue)](https://tgbotapi.inmo.dev/index.html) [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/), [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
| TelegramBotAPI Core status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) |
| TelegramBotAPI API Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.api) |
| TelegramBotAPI Util Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.utils) |
| TelegramBotAPI Behaviour Builder Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.behaviour_builder/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.behaviour_builder) |
| TelegramBotAPI Behaviour Builder FSM Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.behaviour_builder.fsm/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.behaviour_builder.fsm) |
| TelegramBotAPI All status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) |
## Examples
There are several things you need to do to launch examples below:

View File

@@ -23,7 +23,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -91,3 +97,8 @@ Object callback = {
tasks.dokkaGfm(callback)
tasks.dokkaHtml(callback)
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -7,16 +7,16 @@ kotlin.incremental.js=true
kotlin_version=1.5.31
kotlin_coroutines_version=1.5.2
kotlin_serialisation_runtime_version=1.3.0
klock_version=2.4.7
kotlin_serialisation_runtime_version=1.3.1
klock_version=2.4.8
uuid_version=0.3.1
ktor_version=1.6.5
micro_utils_version=0.7.5
micro_utils_version=0.8.7
javax_activation_version=1.1.1
library_group=dev.inmo
library_version=0.36.2
library_version=0.37.3
github_release_plugin_version=2.2.12

View File

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -43,8 +49,7 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -0,0 +1,39 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.ApproveChatJoinRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
suspend fun TelegramBot.approveChatJoinRequest(
chatId: ChatIdentifier,
userId: UserId
) = execute(ApproveChatJoinRequest(chatId, userId))
suspend fun TelegramBot.approveChatJoinRequest(
chat: PublicChat,
userId: UserId
) = approveChatJoinRequest(chat.id, userId)
suspend fun TelegramBot.approveChatJoinRequest(
chatId: ChatIdentifier,
user: User
) = approveChatJoinRequest(chatId, user.id)
suspend fun TelegramBot.approveChatJoinRequest(
chat: PublicChat,
user: User
) = approveChatJoinRequest(chat.id, user.id)
suspend fun TelegramBot.approveChatJoinRequest(
chatJoinRequest: ChatJoinRequest
) = approveChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user)
suspend fun TelegramBot.approve(
chatJoinRequest: ChatJoinRequest
) = approveChatJoinRequest(chatJoinRequest)
suspend fun TelegramBot.approveChatJoinRequest(
chatJoinRequestUpdate: ChatJoinRequestUpdate
) = approveChatJoinRequest(chatJoinRequestUpdate.data)

View File

@@ -6,26 +6,78 @@ import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
suspend fun TelegramBot.createChatInviteLink(
suspend fun TelegramBot.createChatInviteLinkUnlimited(
chatId: ChatIdentifier,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = execute(CreateChatInviteLink(chatId, expiration, membersLimit))
name: String? = null,
expiration: TelegramDate? = null
) = execute(CreateChatInviteLink.unlimited(chatId, name, expiration))
suspend fun TelegramBot.createChatInviteLink(
suspend fun TelegramBot.createChatInviteLinkUnlimited(
chat: PublicChat,
name: String? = null,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = createChatInviteLink(chat.id, expiration, membersLimit)
) = createChatInviteLinkUnlimited(chat.id, name, expiration)
suspend fun TelegramBot.createChatInviteLink(
suspend fun TelegramBot.createChatInviteLinkUnlimited(
chatId: ChatIdentifier,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = createChatInviteLink(chatId, expiration.toTelegramDate(), membersLimit)
name: String? = null,
) = createChatInviteLinkUnlimited(chatId, name, expiration.toTelegramDate())
suspend fun TelegramBot.createChatInviteLink(
suspend fun TelegramBot.createChatInviteLinkUnlimited(
chat: PublicChat,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = createChatInviteLink(chat.id, expiration.toTelegramDate(), membersLimit)
name: String? = null
) = createChatInviteLinkUnlimited(chat.id, name, expiration.toTelegramDate())
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier,
membersLimit: MembersLimit,
name: String? = null,
expiration: TelegramDate? = null
) = execute(CreateChatInviteLink.withLimitedMembers(chatId, membersLimit, name, expiration))
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chat: PublicChat,
membersLimit: MembersLimit,
name: String? = null,
expiration: TelegramDate? = null,
) = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, name, expiration)
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier,
membersLimit: MembersLimit,
expiration: DateTime,
name: String? = null,
) = createChatInviteLinkWithLimitedMembers(chatId, membersLimit, name, expiration.toTelegramDate())
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chat: PublicChat,
membersLimit: MembersLimit,
expiration: DateTime,
name: String? = null,
) = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, name, expiration.toTelegramDate())
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier,
name: String? = null,
expiration: TelegramDate? = null
) = execute(CreateChatInviteLink.withJoinRequest(chatId, name, expiration))
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chat: PublicChat,
name: String? = null,
expiration: TelegramDate? = null,
) = createChatInviteLinkWithJoinRequest(chat.id, name, expiration)
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier,
expiration: DateTime,
name: String? = null,
) = createChatInviteLinkWithJoinRequest(chatId, name, expiration.toTelegramDate())
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chat: PublicChat,
expiration: DateTime,
name: String? = null,
) = createChatInviteLinkWithJoinRequest(chat.id, name, expiration.toTelegramDate())

View File

@@ -0,0 +1,40 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.ApproveChatJoinRequest
import dev.inmo.tgbotapi.requests.chat.invite_links.DeclineChatJoinRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
suspend fun TelegramBot.declineChatJoinRequest(
chatId: ChatIdentifier,
userId: UserId
) = execute(DeclineChatJoinRequest(chatId, userId))
suspend fun TelegramBot.declineChatJoinRequest(
chat: PublicChat,
userId: UserId
) = declineChatJoinRequest(chat.id, userId)
suspend fun TelegramBot.declineChatJoinRequest(
chatId: ChatIdentifier,
user: User
) = declineChatJoinRequest(chatId, user.id)
suspend fun TelegramBot.declineChatJoinRequest(
chat: PublicChat,
user: User
) = declineChatJoinRequest(chat.id, user.id)
suspend fun TelegramBot.declineChatJoinRequest(
chatJoinRequest: ChatJoinRequest
) = declineChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user)
suspend fun TelegramBot.decline(
chatJoinRequest: ChatJoinRequest
) = declineChatJoinRequest(chatJoinRequest)
suspend fun TelegramBot.declineChatJoinRequest(
chatJoinRequestUpdate: ChatJoinRequestUpdate
) = declineChatJoinRequest(chatJoinRequestUpdate.data)

View File

@@ -6,58 +6,178 @@ import dev.inmo.tgbotapi.requests.chat.invite_links.EditChatInviteLink
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
suspend fun TelegramBot.editChatInviteLink(
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier,
previousLink: String,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = execute(EditChatInviteLink(chatId, previousLink, expiration, membersLimit))
name: String? = null,
expiration: TelegramDate? = null
) = execute(EditChatInviteLink.unlimited(chatId, previousLink, name, expiration))
suspend fun TelegramBot.editChatInviteLink(
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat,
previousLink: String,
name: String? = null,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = editChatInviteLink(chat.id, previousLink, expiration, membersLimit)
) = editChatInviteLinkUnlimited(chat.id, previousLink, name, expiration)
suspend fun TelegramBot.editChatInviteLink(
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier,
previousLink: String,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = editChatInviteLink(chatId, previousLink, expiration.toTelegramDate(), membersLimit)
name: String? = null,
) = editChatInviteLinkUnlimited(chatId, previousLink, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLink(
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat,
previousLink: String,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = editChatInviteLink(chat.id, previousLink, expiration.toTelegramDate(), membersLimit)
name: String? = null,
) = editChatInviteLinkUnlimited(chat.id, previousLink, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLink(
chat: ChatIdentifier,
previousLink: ChatInviteLink,
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier,
previousLink: String,
membersLimit: MembersLimit,
name: String? = null,
expiration: TelegramDate? = null
) = execute(EditChatInviteLink.withLimitedMembers(chatId, previousLink, membersLimit, name, expiration))
suspend fun TelegramBot.editChatInviteLink(
chat: ChatIdentifier,
previousLink: ChatInviteLink,
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat,
previousLink: String,
membersLimit: MembersLimit,
name: String? = null,
expiration: TelegramDate? = null,
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name, expiration)
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier,
previousLink: String,
membersLimit: MembersLimit,
expiration: DateTime,
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
name: String? = null,
) = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLink(
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat,
previousLink: String,
membersLimit: MembersLimit,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier,
previousLink: String,
name: String? = null,
expiration: TelegramDate? = null
) = execute(EditChatInviteLink.withJoinRequest(chatId, previousLink, name, expiration))
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat,
previousLink: String,
name: String? = null,
expiration: TelegramDate? = null,
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name, expiration)
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier,
previousLink: String,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkWithJoinRequest(chatId, previousLink, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat,
previousLink: String,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier,
previousLink: ChatInviteLink,
name: String? = null,
expiration: TelegramDate? = null
) = editChatInviteLinkUnlimited(chatId, previousLink.inviteLink, name, expiration)
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat,
previousLink: ChatInviteLink,
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
name: String? = null,
expiration: TelegramDate? = null,
) = editChatInviteLinkUnlimited(chat.id, previousLink, name, expiration)
suspend fun TelegramBot.editChatInviteLink(
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier,
previousLink: ChatInviteLink,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkUnlimited(chatId, previousLink, name, expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat,
previousLink: ChatInviteLink,
expiration: DateTime,
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
name: String? = null,
) = editChatInviteLinkUnlimited(chat.id, previousLink, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier,
previousLink: ChatInviteLink,
membersLimit: MembersLimit,
name: String? = null,
expiration: TelegramDate? = null
) = editChatInviteLinkWithLimitedMembers(chatId, previousLink.inviteLink, membersLimit, name, expiration)
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat,
previousLink: ChatInviteLink,
membersLimit: MembersLimit,
name: String? = null,
expiration: TelegramDate? = null,
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name, expiration)
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier,
previousLink: ChatInviteLink,
membersLimit: MembersLimit,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat,
previousLink: ChatInviteLink,
membersLimit: MembersLimit,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier,
previousLink: ChatInviteLink,
name: String? = null,
expiration: TelegramDate? = null
) = editChatInviteLinkWithJoinRequest(chatId, previousLink.inviteLink, name, expiration)
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat,
previousLink: ChatInviteLink,
name: String? = null,
expiration: TelegramDate? = null,
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name, expiration)
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier,
previousLink: ChatInviteLink,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkWithJoinRequest(chatId, previousLink, name , expiration.toTelegramDate())
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat,
previousLink: ChatInviteLink,
expiration: DateTime,
name: String? = null,
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name , expiration.toTelegramDate())

View File

@@ -0,0 +1,27 @@
package dev.inmo.tgbotapi.extensions.api.chat.members
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.members.BanChatMember
import dev.inmo.tgbotapi.requests.chat.members.BanChatSenderChat
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
suspend fun TelegramBot.banChatSenderChat(
chatId: ChatIdentifier,
senderChatId: ChatId
) = execute(BanChatSenderChat(chatId, senderChatId))
suspend fun TelegramBot.banChatSenderChat(
chat: PublicChat,
senderChatId: ChatId
) = banChatSenderChat(chat.id, senderChatId)
suspend fun TelegramBot.banChatSenderChat(
chatId: ChatId,
senderChat: PublicChat
) = banChatSenderChat(chatId, senderChat.id)
suspend fun TelegramBot.banChatSenderChat(
chat: PublicChat,
senderChat: PublicChat,
) = banChatSenderChat(chat.id, senderChat)

View File

@@ -0,0 +1,26 @@
package dev.inmo.tgbotapi.extensions.api.chat.members
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.members.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
suspend fun TelegramBot.unbanChatSenderChat(
chatId: ChatIdentifier,
senderChatId: ChatId
) = execute(UnbanChatSenderChat(chatId, senderChatId))
suspend fun TelegramBot.unbanChatSenderChat(
chat: PublicChat,
senderChatId: ChatId
) = unbanChatSenderChat(chat.id, senderChatId)
suspend fun TelegramBot.unbanChatSenderChat(
chatId: ChatId,
senderChat: PublicChat
) = unbanChatSenderChat(chatId, senderChat.id)
suspend fun TelegramBot.unbanChatSenderChat(
chat: PublicChat,
senderChat: PublicChat,
) = unbanChatSenderChat(chat.id, senderChat)

View File

@@ -100,3 +100,7 @@ suspend fun TelegramBot.sendActionUploadVideoNote(
chat: Chat
) = sendBotAction(chat, UploadVideoNoteAction)
suspend fun TelegramBot.sendActionChooseStickerAction(
chat: Chat
) = sendBotAction(chat, ChooseStickerAction)

View File

@@ -59,6 +59,7 @@ suspend fun <T> TelegramBot.withUploadDocumentAction(chatId: ChatId, block: Tele
suspend fun <T> TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, FindLocationAction, block)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVideoNoteAction, block)
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVideoNoteAction, block)
suspend fun <T> TelegramBot.withChooseStickerAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, ChooseStickerAction, block)
suspend fun <T> TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, TypingAction, block)
@@ -71,3 +72,4 @@ suspend fun <T> TelegramBot.withUploadDocumentAction(chat: Chat, block: Telegram
suspend fun <T> TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, FindLocationAction, block)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVideoNoteAction, block)
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVideoNoteAction, block)
suspend fun <T> TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, ChooseStickerAction, block)

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -44,7 +50,6 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -10,16 +10,6 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.*
private suspend fun <I : State> BehaviourContextWithFSM.launchStateHandling(
state: State,
contextUpdatesFlow: Flow<Update>,
handlers: List<BehaviourWithFSMStateHandlerHolder<out I>>
): State? {
return handlers.firstOrNull { it.checkHandleable(state) } ?.run {
handleState(contextUpdatesFlow, state)
}
}
/**
* Interface which combine [BehaviourContext] and [StatesMachine]. Subcontext of triggers and states contexts must have
* one common flow of updates and must not lose updates between updates
@@ -27,9 +17,19 @@ private suspend fun <I : State> BehaviourContextWithFSM.launchStateHandling(
* @see DefaultBehaviourContextWithFSM
* @see buildBehaviourWithFSM
*/
interface BehaviourContextWithFSM : BehaviourContext, StatesMachine {
interface BehaviourContextWithFSM<T : State> : BehaviourContext, StatesMachine<T> {
suspend fun start() = start(this)
suspend fun launchStateHandling(
state: T,
contextUpdatesFlow: Flow<Update>,
handlers: List<BehaviourWithFSMStateHandlerHolder<*, T>>
): T? {
return handlers.firstOrNull { it.checkHandleable(state) } ?.run {
handleState(contextUpdatesFlow, state)
}
}
override fun copy(
bot: TelegramBot,
scope: CoroutineScope,
@@ -37,14 +37,14 @@ interface BehaviourContextWithFSM : BehaviourContext, StatesMachine {
onBufferOverflow: BufferOverflow,
upstreamUpdatesFlow: Flow<Update>?,
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
): BehaviourContextWithFSM
): BehaviourContextWithFSM<T>
companion object {
operator fun invoke(
operator fun <T : State> invoke(
behaviourContext: BehaviourContext,
handlers: List<BehaviourWithFSMStateHandlerHolder<*>>,
statesManager: StatesManager
) = DefaultBehaviourContextWithFSM(behaviourContext, statesManager, handlers)
handlers: List<BehaviourWithFSMStateHandlerHolder<*, T>>,
statesManager: StatesManager<T>
) = DefaultBehaviourContextWithFSM<T>(behaviourContext, statesManager, handlers)
}
}
@@ -52,23 +52,24 @@ interface BehaviourContextWithFSM : BehaviourContext, StatesMachine {
* Default realization of [BehaviourContextWithFSM]. It uses [behaviourContext] as a base for this object as
* [BehaviourContext], but managing substates contexts updates for avoiding of updates lost between states
*/
class DefaultBehaviourContextWithFSM(
class DefaultBehaviourContextWithFSM<T : State>(
private val behaviourContext: BehaviourContext,
private val statesManager: StatesManager,
private val handlers: List<BehaviourWithFSMStateHandlerHolder<*>>
) : BehaviourContext by behaviourContext, BehaviourContextWithFSM {
private val statesManager: StatesManager<T>,
private val handlers: List<BehaviourWithFSMStateHandlerHolder<*, T>>
) : BehaviourContext by behaviourContext, BehaviourContextWithFSM<T> {
private val updatesFlows = mutableMapOf<Any, Flow<Update>>()
private fun getContextUpdatesFlow(context: Any) = updatesFlows.getOrPut(context) {
allUpdatesFlow.accumulatorFlow(scope)
}
override suspend fun StatesMachine.handleState(state: State): State? = launchStateHandling(
override suspend fun StatesMachine<in T>.handleState(state: T): T? = launchStateHandling(
state,
allUpdatesFlow,
handlers
)
override fun start(scope: CoroutineScope): Job = scope.launchSafelyWithoutExceptions {
val statePerformer: suspend (State) -> Unit = { state: State ->
val statePerformer: suspend (T) -> Unit = { state: T ->
val newState = launchStateHandling(state, getContextUpdatesFlow(state.context), handlers)
if (newState != null) {
statesManager.update(state, newState)
@@ -94,7 +95,7 @@ class DefaultBehaviourContextWithFSM(
}
}
override suspend fun startChain(state: State) {
override suspend fun startChain(state: T) {
statesManager.startChain(state)
}
@@ -105,7 +106,7 @@ class DefaultBehaviourContextWithFSM(
onBufferOverflow: BufferOverflow,
upstreamUpdatesFlow: Flow<Update>?,
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
): BehaviourContextWithFSM = BehaviourContextWithFSM(
): BehaviourContextWithFSM<T> = BehaviourContextWithFSM(
behaviourContext.copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter),
handlers,
statesManager

View File

@@ -14,14 +14,14 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlin.reflect.KClass
class BehaviourContextWithFSMBuilder internal constructor(
private val resultBehaviourContext: BehaviourContextWithFSM,
private val handlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>>
) : BehaviourContextWithFSM by resultBehaviourContext {
class BehaviourContextWithFSMBuilder<T : State> internal constructor(
private val resultBehaviourContext: BehaviourContextWithFSM<T>,
private val handlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>>
) : BehaviourContextWithFSM<T> by resultBehaviourContext {
internal constructor(
baseBehaviourContext: BehaviourContext,
statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
handlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf()
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
handlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf()
) : this(DefaultBehaviourContextWithFSM(baseBehaviourContext, statesManager, handlers), handlers)
/**
@@ -31,7 +31,7 @@ class BehaviourContextWithFSMBuilder internal constructor(
* @see BehaviourWithFSMStateHandlerHolder
* @see onStateOrSubstate
*/
fun <I : State> add(kClass: KClass<I>, handler: BehaviourWithFSMStateHandler<I>) {
fun <I : T> add(kClass: KClass<I>, handler: BehaviourWithFSMStateHandler<I, T>) {
handlers.add(BehaviourWithFSMStateHandlerHolder(kClass, false, handler))
}
@@ -43,7 +43,7 @@ class BehaviourContextWithFSMBuilder internal constructor(
* @see BehaviourWithFSMStateHandlerHolder
* @see strictlyOn
*/
fun <I : State> addStrict(kClass: KClass<I>, handler: BehaviourWithFSMStateHandler<I>) {
fun <I : T> addStrict(kClass: KClass<I>, handler: BehaviourWithFSMStateHandler<I, T>) {
handlers.add(BehaviourWithFSMStateHandlerHolder(kClass, true, handler))
}
@@ -56,7 +56,7 @@ class BehaviourContextWithFSMBuilder internal constructor(
* @see BehaviourContextWithFSMBuilder.add
*/
@Suppress("MemberVisibilityCanBePrivate")
inline fun <reified I : State> onStateOrSubstate(handler: BehaviourWithFSMStateHandler<I>) {
inline fun <reified I : T> onStateOrSubstate(handler: BehaviourWithFSMStateHandler<I, T>) {
add(I::class, handler)
}
@@ -69,7 +69,7 @@ class BehaviourContextWithFSMBuilder internal constructor(
* @see BehaviourContextWithFSMBuilder.addStrict
*/
@Suppress("MemberVisibilityCanBePrivate")
inline fun <reified I : State> strictlyOn(handler: BehaviourWithFSMStateHandler<I>) {
inline fun <reified I : T> strictlyOn(handler: BehaviourWithFSMStateHandler<I, T>) {
addStrict(I::class, handler)
}
@@ -89,14 +89,14 @@ class BehaviourContextWithFSMBuilder internal constructor(
* start any updates retrieving. See [buildBehaviourWithFSMAndStartLongPolling] or
* [telegramBotWithBehaviourAndFSMAndStartLongPolling] in case you wish to start [longPolling] automatically
*/
suspend fun TelegramBot.buildBehaviourWithFSM(
suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(
upstreamUpdatesFlow: Flow<Update>? = null,
scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>
): BehaviourContextWithFSM = BehaviourContextWithFSMBuilder(
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder<T>, Unit>
): BehaviourContextWithFSM<T> = BehaviourContextWithFSMBuilder(
DefaultBehaviourContext(
this,
defaultExceptionsHandler ?.let { scope + ContextSafelyExceptionHandler(it) } ?: scope,
@@ -111,14 +111,14 @@ suspend fun TelegramBot.buildBehaviourWithFSM(
* using [longPolling]. For [longPolling] will be used result [BehaviourContextWithFSM] for both parameters
* flowsUpdatesFilter and scope
*/
suspend fun TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
upstreamUpdatesFlow: Flow<Update>? = null,
scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>
): Pair<BehaviourContextWithFSM, Job> = buildBehaviourWithFSM(
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder<T>, Unit>
): Pair<BehaviourContextWithFSM<T>, Job> = buildBehaviourWithFSM(
upstreamUpdatesFlow,
scope,
defaultExceptionsHandler,
@@ -151,14 +151,14 @@ suspend fun TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
* @see BehaviourContextWithFSMBuilder.onStateOrSubstate
*/
@PreviewFeature
suspend fun TelegramBot.buildBehaviourWithFSM(
suspend fun <T : State> TelegramBot.buildBehaviourWithFSM(
flowUpdatesFilter: FlowsUpdatesFilter,
scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>
): BehaviourContextWithFSM = BehaviourContextWithFSMBuilder(
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder<T>, Unit>
): BehaviourContextWithFSM<T> = BehaviourContextWithFSMBuilder(
DefaultBehaviourContext(
this,
defaultExceptionsHandler ?.let { scope + ContextSafelyExceptionHandler(it) } ?: scope,
@@ -180,12 +180,12 @@ suspend fun TelegramBot.buildBehaviourWithFSM(
* @see BehaviourContextWithFSMBuilder.onStateOrSubstate
*/
@PreviewFeature
suspend fun TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
suspend fun <T : State> TelegramBot.buildBehaviourWithFSMAndStartLongPolling(
scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder<T>, Unit>
) = FlowsUpdatesFilter().let {
buildBehaviourWithFSM(
it,

View File

@@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder
import dev.inmo.micro_utils.fsm.common.*
fun interface BehaviourWithFSMStateHandler<T : State> {
suspend fun BehaviourContextWithFSM.handleState(state: T): State?
fun interface BehaviourWithFSMStateHandler<I : O, O : State> {
suspend fun BehaviourContextWithFSM<in O>.handleState(state: I): O?
}

View File

@@ -19,10 +19,10 @@ import kotlin.reflect.KClass
* @param delegateTo This handler will be called in case [checkHandleable] returns true with class caster incoming
* [State] in [handleState]
*/
class BehaviourWithFSMStateHandlerHolder<I : State>(
class BehaviourWithFSMStateHandlerHolder<I : O, O : State>(
private val inputKlass: KClass<I>,
private val strict: Boolean = false,
private val delegateTo: BehaviourWithFSMStateHandler<I>
private val delegateTo: BehaviourWithFSMStateHandler<I, O>
) {
/**
* Check ability of [delegateTo] to handle this [state]
@@ -30,7 +30,7 @@ class BehaviourWithFSMStateHandlerHolder<I : State>(
* @return When [state]::class exactly equals to [inputKlass] will always return true. Otherwise when [strict]
* mode is disabled, will be used [KClass.isInstance] of [inputKlass] for checking
*/
fun checkHandleable(state: State) = state::class == inputKlass || (!strict && inputKlass.isInstance(state))
fun checkHandleable(state: O): Boolean = state::class == inputKlass || (!strict && inputKlass.isInstance(state))
/**
* Handling of state :)
@@ -38,10 +38,10 @@ class BehaviourWithFSMStateHandlerHolder<I : State>(
* @param contextUpdatesFlow This [Flow] will be used as source of updates. By contract, this [Flow] must be common
* for all [State]s of incoming [state] [State.context] and for the whole chain inside of [BehaviourContextWithFSM]
*/
suspend fun BehaviourContextWithFSM.handleState(
suspend fun BehaviourContextWithFSM<in O>.handleState(
contextUpdatesFlow: Flow<Update>,
state: State
): State? {
state: O
): O? {
val subscope = scope.LinkedSupervisorScope()
return with(copy(scope = subscope, upstreamUpdatesFlow = contextUpdatesFlow)) {
with(delegateTo) {
@@ -50,3 +50,8 @@ class BehaviourWithFSMStateHandlerHolder<I : State>(
}
}
}
inline fun <reified I : O, O : State> BehaviourWithFSMStateHandlerHolder(
strict: Boolean = false,
delegateTo: BehaviourWithFSMStateHandler<I, O>
) = BehaviourWithFSMStateHandlerHolder(I::class, strict, delegateTo)

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder
import dev.inmo.micro_utils.coroutines.ExceptionHandler
import dev.inmo.micro_utils.fsm.common.State
import dev.inmo.micro_utils.fsm.common.StatesManager
import dev.inmo.micro_utils.fsm.common.managers.DefaultStatesManager
import dev.inmo.micro_utils.fsm.common.managers.InMemoryDefaultStatesManagerRepo
@@ -28,16 +29,16 @@ import kotlin.coroutines.coroutineContext
* @see [buildBehaviourWithFSM]
* @see startGettingOfUpdatesByLongPolling
*/
suspend fun telegramBotWithBehaviourAndFSM(
suspend fun <T : State> telegramBotWithBehaviourAndFSM(
token: String,
flowsUpdatesFilter: FlowsUpdatesFilter,
scope: CoroutineScope? = null,
apiUrl: String = telegramBotAPIDefaultUrl,
builder: KtorRequestsExecutorBuilder.() -> Unit = {},
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder<T>, Unit>
): TelegramBot = telegramBot(
token,
apiUrl,
@@ -64,15 +65,15 @@ suspend fun telegramBotWithBehaviourAndFSM(
* @see buildBehaviourWithFSMAndStartLongPolling
* @see startGettingOfUpdatesByLongPolling
*/
suspend fun telegramBotWithBehaviourAndFSMAndStartLongPolling(
suspend fun <T : State> telegramBotWithBehaviourAndFSMAndStartLongPolling(
token: String,
scope: CoroutineScope? = null,
apiUrl: String = telegramBotAPIDefaultUrl,
builder: KtorRequestsExecutorBuilder.() -> Unit = {},
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder, Unit>
statesManager: StatesManager<T> = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()),
presetHandlers: MutableList<BehaviourWithFSMStateHandlerHolder<*, T>> = mutableListOf(),
block: CustomBehaviourContextReceiver<BehaviourContextWithFSMBuilder<T>, Unit>
): Pair<TelegramBot, Job> {
return telegramBot(
token,

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -43,7 +49,6 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -27,7 +27,7 @@ expect var defaultCoroutineScopeProvider: () -> CoroutineScope
*/
@PreviewFeature
suspend fun TelegramBot.buildBehaviour(
flowUpdatesFilter: FlowsUpdatesFilter,
flowUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(),
scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
block: BehaviourContextReceiver<Unit>
@@ -70,11 +70,3 @@ suspend fun TelegramBot.buildBehaviourWithLongPolling(
scope = scope
)
}
@PreviewFeature
@Deprecated("Renamed to buildBehaviourWithLongPolling")
suspend fun TelegramBot.buildBehaviour(
scope: CoroutineScope = defaultCoroutineScopeProvider(),
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
block: BehaviourContextReceiver<Unit>
) = buildBehaviourWithLongPolling(scope, defaultExceptionsHandler, block)

View File

@@ -55,13 +55,6 @@ interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope {
upstreamUpdatesFlow: Flow<Update>? = null,
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null
): BehaviourContext
@Deprecated("This method is not recommended to use and will be removed in near release")
fun copy(
bot: TelegramBot,
scope: CoroutineScope = this.scope,
flowsUpdatesFilter: FlowsUpdatesFilter = this.flowsUpdatesFilter
): BehaviourContext = copy(upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow)
}
class DefaultBehaviourContext(
@@ -113,30 +106,6 @@ inline fun <T> BehaviourContext(
crossinline block: BehaviourContext.() -> T
) = DefaultBehaviourContext(bot, scope, upstreamUpdatesFlow = flowsUpdatesFilter.allUpdatesFlow).run(block)
/**
* Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [newFlowsUpdatesFilterSetUp] is provided and
* [CoroutineScope] as new [BehaviourContext.scope]. You must do all subscription/running of longPolling manually.
*
* @param newFlowsUpdatesFilterSetUp As a parameter receives [FlowsUpdatesFilter] from old [this] [BehaviourContext.flowsUpdatesFilter]
*/
@RiskFeature("It is recommended to use doInSubContextWithUpdatesFilter instead. " +
"This method is low level and should not be used in case you are not pretty sure you need it.")
@Deprecated("This method is useless and will not be used in future")
suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithFlowsUpdatesFilterSetup(
newFlowsUpdatesFilterSetUp: CustomBehaviourContextAndTypeReceiver<BC, Unit, FlowsUpdatesFilter>?,
stopOnCompletion: Boolean = true,
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
): T = (copy(
scope = LinkedSupervisorScope(),
) as BC).run {
withContext(coroutineContext) {
newFlowsUpdatesFilterSetUp ?.let {
it.apply { invoke(this@run, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) }
}
behaviourContextReceiver().also { if (stopOnCompletion) stop() }
}
}
/**
* Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [updatesFilter] is provided and
* [CoroutineScope] as new [BehaviourContext.scope]

View File

@@ -25,7 +25,7 @@ import kotlin.coroutines.coroutineContext
*/
suspend fun telegramBotWithBehaviour(
token: String,
flowsUpdatesFilter: FlowsUpdatesFilter,
flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter(),
scope: CoroutineScope? = null,
apiUrl: String = telegramBotAPIDefaultUrl,
builder: KtorRequestsExecutorBuilder.() -> Unit = {},
@@ -77,13 +77,3 @@ suspend fun telegramBotWithBehaviourAndLongPolling(
)
}
}
@Deprecated("Renamed to telegramBotWithBehaviourAndLongPolling")
suspend fun telegramBotWithBehaviour(
token: String,
scope: CoroutineScope? = null,
apiUrl: String = telegramBotAPIDefaultUrl,
builder: KtorRequestsExecutorBuilder.() -> Unit = {},
defaultExceptionsHandler: ExceptionHandler<Unit>? = null,
block: BehaviourContextReceiver<Unit>
) = telegramBotWithBehaviourAndLongPolling(token, scope, apiUrl, builder, defaultExceptionsHandler, block)

View File

@@ -0,0 +1,51 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
import dev.inmo.tgbotapi.types.payments.ShippingQuery
import kotlinx.coroutines.flow.toList
typealias ChatJoinRequestsMapper = suspend ChatJoinRequest.() -> ChatJoinRequest?
private suspend fun <O> BehaviourContext.waitChatJoinRequests(
count: Int = 1,
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
filter: SimpleFilter<ChatJoinRequest>? = null,
mapper: suspend ChatJoinRequest.() -> O?
): List<O> = expectFlow(
initRequest,
count,
errorFactory
) {
val data = it.asChatJoinRequestUpdate() ?.data
if (data != null && (filter == null || filter(data))) {
data.mapper().let(::listOfNotNull)
} else {
emptyList()
}
}.toList().toList()
suspend fun BehaviourContext.waitChatJoinRequests(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
count: Int = 1,
filter: SimpleFilter<ChatJoinRequest>? = null,
mapper: ChatJoinRequestsMapper? = null
) : List<ChatJoinRequest> = waitChatJoinRequests(
count,
initRequest,
errorFactory,
filter
) {
if (mapper == null) {
this
} else {
mapper(this)
}
}

View File

@@ -119,14 +119,6 @@ suspend fun BehaviourContext.waitEditedStaticLocation(
filter: SimpleFilter<CommonMessage<StaticLocationContent>>? = null,
mapper: CommonMessageToContentMapper<StaticLocationContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
@Deprecated("Potentially, this trigger will never be used. Use `waitPollUpdates` instead")
suspend fun BehaviourContext.waitEditedPoll(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
count: Int = 1,
filter: SimpleFilter<CommonMessage<PollContent>>? = null,
mapper: CommonMessageToContentMapper<PollContent>? = null
) = waitEditedContent(count, initRequest, false, errorFactory, filter, mapper)
suspend fun BehaviourContext.waitEditedText(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },

View File

@@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.types.ChatMemberUpdated
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
import dev.inmo.tgbotapi.types.message.abstracts.Message
@@ -54,3 +55,9 @@ val InlineQueryFilterByUser: BehaviourContextAndTwoTypesReceiver<Boolean, Inline
val ChatMemberUpdatedFilterByChat: BehaviourContextAndTwoTypesReceiver<Boolean, ChatMemberUpdated, Update> = { updated, update ->
update.sourceChat() ?.id == updated.chat.id
}
/**
* Allow only events from the same chat as base [ChatMemberUpdated]
*/
val ChatJoinRequestFilterByChat: BehaviourContextAndTwoTypesReceiver<Boolean, ChatJoinRequest, Update> = { updated, update ->
update.sourceChat() ?.id == updated.chat.id
}

View File

@@ -0,0 +1,34 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.*
import dev.inmo.tgbotapi.extensions.utils.asChatJoinRequestUpdate
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.types.payments.ShippingQuery
import dev.inmo.tgbotapi.types.update.abstracts.Update
/**
* Please, remember that your bot must have `can_invite_users` to receive these requests
*
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onChatJoinRequest(
initialFilter: SimpleFilter<ChatJoinRequest>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatJoinRequest, Update>? = ChatJoinRequestFilterByChat,
markerFactory: MarkerFactory<in ChatJoinRequest, Any> = ByChatChatJoinRequestMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatJoinRequest>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
(it.asChatJoinRequestUpdate() ?.data) ?.let(::listOfNotNull)
}

View File

@@ -166,19 +166,6 @@ suspend fun <BC : BehaviourContext> BC.onEditedLocation(
scenarioReceiver
)
@Deprecated("Potentially, this trigger will never be used. Use `onPollUpdated` instead")
suspend fun <BC : BehaviourContext> BC.onEditedPoll(
initialFilter: CommonMessageFilter<PollContent>? = CommonMessageFilterExcludeMediaGroups,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PollContent>, Update> = MessageFilterByChat,
markerFactory: MarkerFactory<in CommonMessage<PollContent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PollContent>>
)= onEditedContent(
initialFilter,
subcontextUpdatesFilter,
markerFactory,
scenarioReceiver
)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
import dev.inmo.tgbotapi.types.payments.ShippingQuery
@@ -8,6 +9,10 @@ object ByUserCallbackQueryMarkerFactory : MarkerFactory<CallbackQuery, Any> {
override suspend fun invoke(data: CallbackQuery) = data.user
}
object ByChatChatJoinRequestMarkerFactory : MarkerFactory<ChatJoinRequest, Any> {
override suspend fun invoke(data: ChatJoinRequest) = data.chat
}
object ByUserShippingQueryMarkerFactory : MarkerFactory<ShippingQuery, Any> {
override suspend fun invoke(data: ShippingQuery) = data.user
}

View File

@@ -21,18 +21,14 @@
Library for Object-Oriented and type-safe work with Telegram Bot API. Most part of some specific solves or unuseful
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
## Compatibility
This version compatible with [25th of June 2021 update of TelegramBotAPI (version 5.3)](https://core.telegram.org/bots/api-changelog#june-25-2021).
## How to implement library?
Common ways to implement this library are presented here. In some cases it will require additional steps
like inserting of additional libraries (like `kotlin stdlib`). In the examples will be used variable
`telegrambotapi.version`, which must be set up by developer. Available versions are presented on
[bintray](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core), next version is last published:
maven central, next version is last published:
[![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi.core/images/download.svg) ](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core/_latestVersion)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core)
Currently, last versions of library can be available from the Maven repository with errors (for the reason difficult in publishing
of signed artifacts in Bintray). You can:

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -94,7 +100,6 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.bot.Ktor.base
import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.micro_utils.coroutines.safelyWithResult
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
import dev.inmo.tgbotapi.requests.GetUpdates
@@ -57,7 +58,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
val content = response.receive<String>()
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
return safely {
return safelyWithResult {
(responseObject.result?.let {
jsonFormatter.decodeFromJsonElement(request.resultDeserializer, it)
} ?: response.let {
@@ -67,7 +68,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
"Can't get result object from $content"
)
})
}
}.getOrThrow()
}
}
@@ -76,4 +77,4 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
urlsKeeper: TelegramAPIUrlsKeeper,
request: Request<T>
): Any?
}
}

View File

@@ -5,16 +5,27 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.DeserializationStrategy
interface ChatInviteLinkRequest : SimpleRequest<CommonInviteLink> {
interface ChatInviteLinkRequest<R : SecondaryChatInviteLink> : SimpleRequest<R> {
val chatId: ChatIdentifier
override val resultDeserializer: DeserializationStrategy<CommonInviteLink>
get() = CommonInviteLink.serializer()
}
interface KnownChatInviteLinkRequest : ChatInviteLinkRequest {
interface KnownChatInviteLinkRequest<R : SecondaryChatInviteLink> : ChatInviteLinkRequest<R> {
val inviteLink: String
}
interface EditChatInviteLinkRequest : ChatInviteLinkRequest {
val expireDate: DateTime?
val membersLimit: MembersLimit?
interface LimitedMembersChatInviteLinkRequest : ChatInviteLinkRequest<ChatInviteLinkWithLimitedMembers> {
val membersLimit: MembersLimit
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkWithLimitedMembers>
get() = ChatInviteLinkWithLimitedMembers.serializer()
}
interface WithJoinRequestChatInviteLinkRequest : ChatInviteLinkRequest<ChatInviteLinkWithJoinRequest> {
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkWithJoinRequest>
get() = ChatInviteLinkWithJoinRequest.serializer()
}
interface EditChatInviteLinkRequest<R : SecondaryChatInviteLink> : ChatInviteLinkRequest<R> {
val expireDate: DateTime?
val name: String?
}

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.requests.chat.abstracts
import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.UserId
interface ChatSenderRequest : ChatRequest, SimpleRequest<Boolean> {
val senderChatId: ChatId
}

View File

@@ -0,0 +1,51 @@
package dev.inmo.tgbotapi.requests.chat.invite_links
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
/**
* Represent a join request answer. See inheritors for more info
*/
sealed interface ChatJoinRequestAnswer : SimpleRequest<Boolean> {
val chatId: ChatIdentifier
val userId: UserId
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
}
/**
* Represent [approve](https://core.telegram.org/bots/api#approvechatjoinrequest) [ChatJoinRequestAnswer]. You may approve
* the requests retrieved in with [ChatJoinRequest] (in [dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate])
*/
@Serializable
data class ApproveChatJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(userIdField)
override val userId: UserId
) : ChatJoinRequestAnswer {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "approveChatJoinRequest"
}
/**
* Represent [decline](https://core.telegram.org/bots/api#declinechatjoinrequest) [ChatJoinRequestAnswer]. You may approve
* the requests retrieved in with [ChatJoinRequest] (in [dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate])
*/
@Serializable
data class DeclineChatJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(userIdField)
override val userId: UserId
) : ChatJoinRequestAnswer {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "declineChatJoinRequest"
}

View File

@@ -1,31 +1,120 @@
package dev.inmo.tgbotapi.requests.chat.invite_links
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.requests.chat.abstracts.*
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
@Serializable
data class CreateChatInviteLink(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(expireDateField)
private val expirationUnixTimeStamp: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : EditChatInviteLinkRequest {
sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInviteLinkRequest<R> {
val expirationUnixTimeStamp: TelegramDate?
override val expireDate: DateTime?
get() = expirationUnixTimeStamp ?.asDate
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "createChatInviteLink"
companion object {
fun unlimited(
chatId: ChatIdentifier,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
) = CreateChatInviteLinkUnlimited(chatId, name, expirationUnixTimeStamp)
fun withLimitedMembers(
chatId: ChatIdentifier,
membersLimit: MembersLimit,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
) = CreateChatInviteLinkWithLimitedMembers(chatId, membersLimit, name, expirationUnixTimeStamp)
fun withJoinRequest(
chatId: ChatIdentifier,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
) = CreateChatInviteLinkWithJoinRequest(chatId, name, expirationUnixTimeStamp)
fun unlimited(
chatId: ChatIdentifier,
expiration: DateTime,
name: String? = null,
) = unlimited(chatId, name, expiration.toTelegramDate())
fun withLimitedMembers(
chatId: ChatIdentifier,
membersLimit: MembersLimit,
expiration: DateTime,
name: String? = null,
) = withLimitedMembers(chatId, membersLimit, name, expiration.toTelegramDate())
fun withJoinRequest(
chatId: ChatIdentifier,
expiration: DateTime,
name: String? = null,
) = withJoinRequest(chatId, name, expiration.toTelegramDate())
}
}
fun CreateChatInviteLink(
chatId: ChatId,
expireDate: DateTime,
membersLimit: MembersLimit? = null
): CreateChatInviteLink = CreateChatInviteLink(
chatId, expireDate.toTelegramDate(), membersLimit
)
/**
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITHOUT `member_limit`
* and `creates_join_request`
*
* @see CreateChatInviteLink.unlimited
* @see CreateChatInviteLinkWithLimitedMembers
* @see CreateChatInviteLinkWithJoinRequest
*/
@Serializable
data class CreateChatInviteLinkUnlimited(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(nameField)
override val name: String? = null,
@SerialName(expireDateField)
override val expirationUnixTimeStamp: TelegramDate? = null,
) : CreateChatInviteLink<ChatInviteLinkUnlimited> {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkUnlimited>
get() = ChatInviteLinkUnlimited.serializer()
}
/**
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITH `member_limit`
* and WITHOUT `creates_join_request`
*
* @see CreateChatInviteLink.withLimitedMembers
* @see CreateChatInviteLinkUnlimited
* @see CreateChatInviteLinkWithJoinRequest
*/
@Serializable
data class CreateChatInviteLinkWithLimitedMembers(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit,
@SerialName(nameField)
override val name: String? = null,
@SerialName(expireDateField)
override val expirationUnixTimeStamp: TelegramDate? = null,
) : CreateChatInviteLink<ChatInviteLinkWithLimitedMembers>, LimitedMembersChatInviteLinkRequest {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
/**
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITHOUT `member_limit`
* and WITH `creates_join_request`
*
* @see CreateChatInviteLink.withJoinRequest
* @see CreateChatInviteLinkUnlimited
* @see CreateChatInviteLinkWithLimitedMembers
*/
@Serializable
data class CreateChatInviteLinkWithJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(nameField)
override val name: String? = null,
@SerialName(expireDateField)
override val expirationUnixTimeStamp: TelegramDate? = null,
) : CreateChatInviteLink<ChatInviteLinkWithJoinRequest>, WithJoinRequestChatInviteLinkRequest {
@Required
@SerialName(createsJoinRequestField)
private val createsJoinRequest: Boolean = true
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -1,35 +1,134 @@
package dev.inmo.tgbotapi.requests.chat.invite_links
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest
import dev.inmo.tgbotapi.requests.chat.abstracts.KnownChatInviteLinkRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.requests.chat.abstracts.*
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
sealed interface EditChatInviteLink<R : SecondaryChatInviteLink> : EditChatInviteLinkRequest<R>, KnownChatInviteLinkRequest<R> {
val expirationUnixTimeStamp: TelegramDate?
override val expireDate: DateTime?
get() = expirationUnixTimeStamp ?.asDate
override fun method(): String = "editChatInviteLink"
companion object {
fun unlimited(
chatId: ChatIdentifier,
inviteLink: String,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
) = EditChatInviteLinkUnlimited(chatId, inviteLink, name, expirationUnixTimeStamp)
fun withLimitedMembers(
chatId: ChatIdentifier,
inviteLink: String,
membersLimit: MembersLimit,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
) = EditChatInviteLinkWithLimitedMembers(chatId, inviteLink, membersLimit, name, expirationUnixTimeStamp)
fun withJoinRequest(
chatId: ChatIdentifier,
inviteLink: String,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
) = EditChatInviteLinkWithJoinRequest(chatId, inviteLink, name, expirationUnixTimeStamp)
fun unlimited(
chatId: ChatIdentifier,
inviteLink: String,
expiration: DateTime,
name: String? = null,
) = unlimited(chatId, inviteLink, name, expiration.toTelegramDate())
fun withLimitedMembers(
chatId: ChatIdentifier,
inviteLink: String,
membersLimit: MembersLimit,
expiration: DateTime,
name: String? = null,
) = withLimitedMembers(chatId, inviteLink, membersLimit, name, expiration.toTelegramDate())
fun withJoinRequest(
chatId: ChatIdentifier,
inviteLink: String,
expiration: DateTime,
name: String? = null,
) = withJoinRequest(chatId, inviteLink, name, expiration.toTelegramDate())
}
}
/**
* Represent [https://core.telegram.org/bots/api#editchatinvitelink] request WITHOUT `member_limit`
* and `creates_join_request`
*
* @see EditChatInviteLink.unlimited
* @see EditChatInviteLinkWithLimitedMembers
* @see EditChatInviteLinkWithJoinRequest
*/
@Serializable
data class EditChatInviteLink(
data class EditChatInviteLinkUnlimited(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(nameField)
override val name: String? = null,
@SerialName(expireDateField)
private val expirationUnixTimeStamp: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : EditChatInviteLinkRequest, KnownChatInviteLinkRequest {
override val expireDate: DateTime?
get() = expirationUnixTimeStamp ?.asDate
override val expirationUnixTimeStamp: TelegramDate? = null,
) : EditChatInviteLink<ChatInviteLinkUnlimited> {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "editChatInviteLink"
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkUnlimited>
get() = ChatInviteLinkUnlimited.serializer()
}
fun EditChatInviteLink(
chatId: ChatIdentifier,
inviteLink: String,
expireDate: DateTime,
membersLimit: MembersLimit? = null
): EditChatInviteLink = EditChatInviteLink(
chatId, inviteLink, expireDate.toTelegramDate(), membersLimit
)
/**
* Represent [https://core.telegram.org/bots/api#editchatinvitelink] request WITH `member_limit`
* and WITHOUT `creates_join_request`
*
* @see EditChatInviteLink.withLimitedMembers
* @see EditChatInviteLinkUnlimited
* @see EditChatInviteLinkWithJoinRequest
*/
@Serializable
data class EditChatInviteLinkWithLimitedMembers(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit,
@SerialName(nameField)
override val name: String? = null,
@SerialName(expireDateField)
override val expirationUnixTimeStamp: TelegramDate? = null,
) : EditChatInviteLink<ChatInviteLinkWithLimitedMembers>,
LimitedMembersChatInviteLinkRequest {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
/**
* Represent [https://core.telegram.org/bots/api#editchatinvitelink] request WITHOUT `member_limit`
* and WITH `creates_join_request`
*
* @see EditChatInviteLink.withJoinRequest
* @see EditChatInviteLinkUnlimited
* @see EditChatInviteLinkWithLimitedMembers
*/
@Serializable
data class EditChatInviteLinkWithJoinRequest(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(nameField)
override val name: String? = null,
@SerialName(expireDateField)
override val expirationUnixTimeStamp: TelegramDate? = null,
) : EditChatInviteLink<ChatInviteLinkWithJoinRequest>,
WithJoinRequestChatInviteLinkRequest {
@Required
@SerialName(createsJoinRequestField)
private val createsJoinRequest: Boolean = true
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -10,9 +10,11 @@ data class RevokeChatInviteLink(
override val chatId: ChatIdentifier,
@SerialName(inviteLinkField)
override val inviteLink: String
) : KnownChatInviteLinkRequest {
) : KnownChatInviteLinkRequest<SecondaryChatInviteLink> {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<SecondaryChatInviteLink>
get() = SecondaryChatInviteLink.serializer()
override fun method(): String = "revokeChatInviteLink"
}

View File

@@ -0,0 +1,23 @@
package dev.inmo.tgbotapi.requests.chat.members
import dev.inmo.tgbotapi.requests.chat.abstracts.ChatSenderRequest
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
/**
* Representation of [banChatSenderChat](https://core.telegram.org/bots/api#banchatsenderchat) request
*/
@Serializable
data class BanChatSenderChat(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(senderChatIdField)
override val senderChatId: ChatId
) : ChatSenderRequest {
override fun method(): String = "banChatSenderChat"
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -0,0 +1,23 @@
package dev.inmo.tgbotapi.requests.chat.members
import dev.inmo.tgbotapi.requests.chat.abstracts.ChatSenderRequest
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
/**
* Representation of [unbanChatSenderChat](https://core.telegram.org/bots/api#unbanchatsenderchat) request
*/
@Serializable
data class UnbanChatSenderChat(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(senderChatIdField)
override val senderChatId: ChatId
) : ChatSenderRequest {
override fun method(): String = "unbanChatSenderChat"
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.CommonAbstracts.WithUser
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
@@ -17,10 +18,16 @@ private data class RawChatInviteLink(
val isPrimary: Boolean,
@SerialName(isRevokedField)
val isRevoked: Boolean,
@SerialName(nameField)
val name: String? = null,
@SerialName(expireDateField)
val expirationDateTime: TelegramDate? = null,
@SerialName(memberLimitField)
val membersLimit: MembersLimit ?= null
val membersLimit: MembersLimit ?= null,
@SerialName(createsJoinRequestField)
val createsJoinRequest: Boolean? = null,
@SerialName(pendingJoinRequestCountField)
val pendingJoinRequestCount: MembersLimit ?= null
)
private fun ChatInviteLink.toRawChatInviteLink() = RawChatInviteLink(
@@ -28,20 +35,50 @@ private fun ChatInviteLink.toRawChatInviteLink() = RawChatInviteLink(
creator,
isPrimary,
isRevoked,
(this as? SecondaryChatInviteLink) ?.name,
expirationDateTime ?.toTelegramDate(),
membersLimit
(this as? ChatInviteLinkWithLimitedMembers) ?.membersLimit,
this is ChatInviteLinkWithJoinRequest,
(this as? ChatInviteLinkWithJoinRequest) ?.leftToReview
)
/**
* Base interface for all chat invite links. See inheritors for more info or official [docs](https://core.telegram.org/bots/api#chatinvitelink)
*/
@Serializable(ChatInviteLinkSerializer::class)
sealed class ChatInviteLink {
abstract val inviteLink: String
abstract val creator: User
abstract val isPrimary: Boolean
abstract val isRevoked: Boolean
abstract val expirationDateTime: DateTime?
abstract val membersLimit: MembersLimit?
sealed interface ChatInviteLink : WithUser {
val inviteLink: String
val creator: User
val isPrimary: Boolean
get() = this is PrimaryInviteLink
val isRevoked: Boolean
val expirationDateTime: DateTime?
val name: String?
override val user: User
get() = creator
companion object {
fun serializer(): KSerializer<ChatInviteLink> = ChatInviteLinkSerializer
}
}
/**
* Base interface for all [ChatInviteLink]s which are NOT [PrimaryInviteLink]
*/
@Serializable(ChatInviteLinkSerializer::class)
sealed interface SecondaryChatInviteLink : ChatInviteLink {
override val isPrimary: Boolean
get() = false
companion object {
fun serializer(): KSerializer<SecondaryChatInviteLink> = ChatInviteLinkSerializer as KSerializer<SecondaryChatInviteLink>
}
}
/**
* Primary invite link in the chat for this bot
*/
@Serializable
data class PrimaryInviteLink(
@SerialName(inviteLinkField)
@@ -52,30 +89,77 @@ data class PrimaryInviteLink(
override val isRevoked: Boolean = false,
@SerialName(expireDateField)
private val expireDate: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : ChatInviteLink() {
override val isPrimary: Boolean
get() = true
) : ChatInviteLink {
override val expirationDateTime: DateTime?
get() = expireDate ?.asDate
override val name: String?
get() = null
}
/**
* Represent [SecondaryChatInviteLink] which will require an aprovement from one of the administrators
*
* @see ChatJoinRequest
* @see dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
*/
@Serializable
data class CommonInviteLink(
data class ChatInviteLinkWithJoinRequest(
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(creatorField)
override val creator: User,
@SerialName(nameField)
override val name: String? = null,
@SerialName(pendingJoinRequestCountField)
val leftToReview: Int = 0,
@SerialName(isRevokedField)
override val isRevoked: Boolean = false,
@SerialName(expireDateField)
private val expireDate: TelegramDate? = null
) : SecondaryChatInviteLink {
override val expirationDateTime: DateTime?
get() = expireDate ?.asDate
}
/**
* Represent [SecondaryChatInviteLink] which will have limitation for the amount of chat members to join
*/
@Serializable
data class ChatInviteLinkWithLimitedMembers(
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(creatorField)
override val creator: User,
@SerialName(nameField)
override val name: String? = null,
@SerialName(memberLimitField)
val membersLimit: MembersLimit,
@SerialName(isRevokedField)
override val isRevoked: Boolean = false,
@SerialName(expireDateField)
private val expireDate: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : ChatInviteLink() {
override val isPrimary: Boolean
get() = false
) : SecondaryChatInviteLink {
override val expirationDateTime: DateTime?
get() = expireDate ?.asDate
}
/**
* Represent [SecondaryChatInviteLink] which have no any restrictions like [ChatInviteLinkWithJoinRequest] or
* [ChatInviteLinkWithLimitedMembers]
*/
@Serializable
data class ChatInviteLinkUnlimited(
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(creatorField)
override val creator: User,
@SerialName(nameField)
override val name: String? = null,
@SerialName(isRevokedField)
override val isRevoked: Boolean = false,
@SerialName(expireDateField)
private val expireDate: TelegramDate? = null,
) : SecondaryChatInviteLink {
override val expirationDateTime: DateTime?
get() = expireDate ?.asDate
}
@@ -89,11 +173,21 @@ object ChatInviteLinkSerializer : KSerializer<ChatInviteLink> {
val deserializedRaw = RawChatInviteLink.serializer().deserialize(decoder)
return deserializedRaw.run {
when {
deserializedRaw.isPrimary -> PrimaryInviteLink(
inviteLink, creator, isRevoked, expirationDateTime, membersLimit
isPrimary -> PrimaryInviteLink(
inviteLink, creator, isRevoked, expirationDateTime
)
else -> CommonInviteLink(
inviteLink, creator, isRevoked, expirationDateTime, membersLimit
createsJoinRequest == true -> {
ChatInviteLinkWithJoinRequest(
inviteLink, creator, name, pendingJoinRequestCount ?: 0, isRevoked, expirationDateTime
)
}
membersLimit != null -> {
ChatInviteLinkWithLimitedMembers(
inviteLink, creator, name, membersLimit, isRevoked, expirationDateTime
)
}
else -> ChatInviteLinkUnlimited(
inviteLink, creator, name, isRevoked, expirationDateTime
)
}
}

View File

@@ -0,0 +1,23 @@
package dev.inmo.tgbotapi.types
import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
/**
* Represent a [ChatJoinRequest](https://core.telegram.org/bots/api#chatjoinrequest)
*/
@Serializable
data class ChatJoinRequest(
@SerialName(chatField)
val chat: PublicChat,
@SerialName(fromField)
override val from: User,
@SerialName(dateField)
val date: TelegramDate,
@SerialName(inviteLinkField)
val inviteLink: ChatInviteLink,
@SerialName(bioField)
val bio: String? = null
) : FromUser

View File

@@ -96,6 +96,7 @@ val telegramInlineModeGifPermittedMimeTypes by lazy {
}
const val chatIdField = "chat_id"
const val senderChatIdField = "sender_chat_id"
const val messageIdField = "message_id"
const val updateIdField = "update_id"
const val fromChatIdField = "from_chat_id"
@@ -112,6 +113,7 @@ const val isBotField = "is_bot"
const val firstNameField = "first_name"
const val lastNameField = "last_name"
const val languageCodeField = "language_code"
const val hasPrivateForwardsField = "has_private_forwards"
const val canJoinGroupsField = "can_join_groups"
const val canReadAllGroupMessagesField = "can_read_all_group_messages"
const val supportInlineQueriesField = "supports_inline_queries"
@@ -177,6 +179,8 @@ const val messageAutoDeleteTimeField = "message_auto_delete_time"
const val isPrimaryField = "is_primary"
const val isRevokedField = "is_revoked"
const val expireDateField = "expire_date"
const val createsJoinRequestField = "creates_join_request"
const val pendingJoinRequestCountField = "pending_join_request_count"
const val memberLimitField = "member_limit"
const val requestContactField = "request_contact"

View File

@@ -13,6 +13,7 @@ const val UPDATE_POLL = "poll"
const val UPDATE_POLL_ANSWER = "poll_answer"
const val MY_CHAT_MEMBER = "my_chat_member"
const val CHAT_MEMBER = "chat_member"
const val CHAT_JOIN_REQUEST = "chat_join_request"
val ALL_UPDATES_LIST = listOf(
UPDATE_MESSAGE,
@@ -27,5 +28,6 @@ val ALL_UPDATES_LIST = listOf(
UPDATE_POLL,
UPDATE_POLL_ANSWER,
MY_CHAT_MEMBER,
CHAT_MEMBER
CHAT_MEMBER,
CHAT_JOIN_REQUEST
)

View File

@@ -36,6 +36,7 @@ object BotActionSerializer: KSerializer<BotAction> {
FindLocationAction.actionName -> FindLocationAction
RecordVideoNoteAction.actionName -> RecordVideoNoteAction
UploadVideoNoteAction.actionName -> UploadVideoNoteAction
ChooseStickerAction.actionName -> ChooseStickerAction
else -> CustomBotAction(actionName)
}
}
@@ -151,6 +152,17 @@ inline val uploadVideoNote
get() = UploadVideoNoteAction
inline fun BotAction.asUploadVideoNote() = this as? UploadVideoNoteAction
/**
* Will notify user that bot is uploading video note
*/
@Serializable(BotActionSerializer::class)
object ChooseStickerAction : BotAction {
override val actionName: String = "choose_sticker"
}
inline val chooseSticker
get() = ChooseStickerAction
inline fun BotAction.asChooseStickerAction() = this as? ChooseStickerAction
@Serializable(BotActionSerializer::class)
@Warning("Use this action only in case you are pretty sure that there are no other action for your needs")
class CustomBotAction @RiskFeature("Usage of this action may lead to errors") constructor(

View File

@@ -26,10 +26,7 @@ data class UnknownInlineKeyboardButton internal constructor(
*/
@Serializable
data class PayInlineKeyboardButton(
override val text: String,
@Deprecated("Don't use this button due to removing of this in near release")
@Transient
val pay: Boolean = true
override val text: String
) : InlineKeyboardButton {
@ExperimentalSerializationApi
@EncodeDefault

View File

@@ -7,4 +7,8 @@ import kotlinx.serialization.Serializable
@Serializable(ExtendedChatSerializer::class)
interface ExtendedPrivateChat : PrivateChat, ExtendedChat {
val bio: String
val hasPrivateForwards: Boolean
val allowCreateUserIdLink: Boolean
get() = hasPrivateForwards
}

View File

@@ -18,5 +18,7 @@ data class ExtendedPrivateChatImpl(
@SerialName(lastNameField)
override val lastName: String = "",
@SerialName(bioField)
override val bio: String = ""
override val bio: String = "",
@SerialName(hasPrivateForwardsField)
override val hasPrivateForwards: Boolean = false
) : ExtendedPrivateChat

View File

@@ -4,8 +4,7 @@ import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
data class ChannelContentMessageImpl<T: MessageContent>(
@@ -14,9 +13,24 @@ data class ChannelContentMessageImpl<T: MessageContent>(
override val content: T,
override val date: DateTime,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : ChannelContentMessage<T>
) : ChannelContentMessage<T> {
@Deprecated("Use the constructor with forwardable field")
constructor(
messageId: MessageIdentifier,
chat: ChannelChat,
content: T,
date: DateTime,
editDate: DateTime?,
forwardInfo: ForwardInfo?,
replyTo: Message?,
replyMarkup: InlineKeyboardMarkup?,
senderBot: CommonBot?,
authorSignature: AuthorSignature?
) : this(messageId, chat, content, date, editDate, true, forwardInfo, replyTo, replyMarkup, senderBot, authorSignature)
}

View File

@@ -16,7 +16,21 @@ data class ChannelMediaGroupMessage<T : MediaGroupContent>(
override val mediaGroupId: MediaGroupIdentifier,
override val content: T,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage<T>
) : MediaGroupMessage<T> {
@Deprecated("Use the constructor with forwardable field")
constructor(
messageId: MessageIdentifier,
chat: Chat,
date: DateTime,
mediaGroupId: MediaGroupIdentifier,
content: T,
editDate: DateTime?,
forwardInfo: ForwardInfo?,
replyTo: Message?,
replyMarkup: InlineKeyboardMarkup?
) : this(messageId, chat, date, mediaGroupId, content, editDate, true, forwardInfo, replyTo, replyMarkup)
}

View File

@@ -15,7 +15,22 @@ data class CommonMediaGroupMessage<T : MediaGroupContent>(
override val mediaGroupId: MediaGroupIdentifier,
override val content: T,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage<T>, FromUserMessage
) : MediaGroupMessage<T>, FromUserMessage {
@Deprecated("Use the constructor with forwardable field")
constructor(
messageId: MessageIdentifier,
from: User,
chat: Chat,
date: DateTime,
mediaGroupId: MediaGroupIdentifier,
content: T,
editDate: DateTime?,
forwardInfo: ForwardInfo?,
replyTo: Message?,
replyMarkup: InlineKeyboardMarkup?
) : this(messageId, from, chat, date, mediaGroupId, content, editDate, true, forwardInfo, replyTo, replyMarkup)
}

View File

@@ -8,19 +8,53 @@ import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
data class FromChannelGroupContentMessageImpl<T : MessageContent>(
data class ConnectedFromChannelGroupContentMessageImpl<T : MessageContent>(
override val chat: GroupChat,
override val channel: ChannelChat,
override val messageId: MessageIdentifier,
override val date: DateTime,
override val forwardInfo: ForwardInfo?,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : FromChannelGroupContentMessage<T>
) : ConnectedFromChannelGroupContentMessage<T> {
@Deprecated("Use the constructor with forwardable field")
constructor(
chat: GroupChat,
channel: ChannelChat,
messageId: MessageIdentifier,
date: DateTime,
forwardInfo: ForwardInfo?,
editDate: DateTime?,
replyTo: Message?,
replyMarkup: InlineKeyboardMarkup?,
content: T,
senderBot: CommonBot?,
authorSignature: AuthorSignature?
) : this(chat, channel, messageId, date, forwardInfo, editDate, true, replyTo, replyMarkup, content, senderBot, authorSignature)
}
@Deprecated("Renamed", ReplaceWith("ConnectedFromChannelGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl"))
typealias FromChannelGroupContentMessageImpl<T> = ConnectedFromChannelGroupContentMessageImpl<T>
data class UnconnectedFromChannelGroupContentMessageImpl<T: MessageContent>(
override val chat: GroupChat,
override val channel: ChannelChat,
override val messageId: MessageIdentifier,
override val date: DateTime,
override val forwardInfo: ForwardInfo?,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : UnconnectedFromChannelGroupContentMessage<T>
data class AnonymousGroupContentMessageImpl<T : MessageContent>(
override val chat: GroupChat,
@@ -28,12 +62,27 @@ data class AnonymousGroupContentMessageImpl<T : MessageContent>(
override val date: DateTime,
override val forwardInfo: ForwardInfo?,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : AnonymousGroupContentMessage<T>
) : AnonymousGroupContentMessage<T> {
@Deprecated("Use the constructor with forwardable field")
constructor(
chat: GroupChat,
messageId: MessageIdentifier,
date: DateTime,
forwardInfo: ForwardInfo?,
editDate: DateTime?,
replyTo: Message?,
replyMarkup: InlineKeyboardMarkup?,
content: T,
senderBot: CommonBot?,
authorSignature: AuthorSignature?
) : this(chat, messageId, date, forwardInfo, editDate, true, replyTo, replyMarkup, content, senderBot, authorSignature)
}
data class CommonGroupContentMessageImpl<T : MessageContent>(
override val chat: GroupChat,
@@ -42,8 +91,23 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
override val date: DateTime,
override val forwardInfo: ForwardInfo?,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val content: T,
override val senderBot: CommonBot?
) : CommonGroupContentMessage<T>
) : CommonGroupContentMessage<T> {
@Deprecated("Use the constructor with forwardable field")
constructor(
chat: GroupChat,
messageId: MessageIdentifier,
from: User,
date: DateTime,
forwardInfo: ForwardInfo?,
editDate: DateTime?,
replyTo: Message?,
replyMarkup: InlineKeyboardMarkup?,
content: T,
senderBot: CommonBot?
) : this(chat, messageId, from, date, forwardInfo, editDate, true, replyTo, replyMarkup, content, senderBot)
}

View File

@@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
data class PrivateContentMessageImpl<T: MessageContent>(
override val messageId: MessageIdentifier,
@@ -16,11 +15,23 @@ data class PrivateContentMessageImpl<T: MessageContent>(
override val content: T,
override val date: DateTime,
override val editDate: DateTime?,
override val forwardable: Boolean,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?,
override val senderBot: CommonBot?
) : PrivateContentMessage<T> {
@Deprecated("This value will always be null. You may get SuccessfulPayment as one of ChatEvents")
val paymentInfo: SuccessfulPaymentEvent? = null
@Deprecated("Use the constructor with forwardable field")
constructor(
messageId: MessageIdentifier,
from: User,
chat: Chat,
content: T,
date: DateTime,
editDate: DateTime?,
forwardInfo: ForwardInfo?,
replyTo: Message?,
replyMarkup: InlineKeyboardMarkup?,
senderBot: CommonBot?
) : this(messageId, from, chat, content, date, editDate, true, forwardInfo, replyTo, replyMarkup, senderBot)
}

View File

@@ -12,8 +12,7 @@ import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.content.media.*
@@ -42,9 +41,11 @@ internal data class RawMessage(
private val forward_signature: ForwardSignature? = null,
private val forward_sender_name: ForwardSenderName? = null,
private val forward_date: TelegramDate? = null,
private val is_automatic_forward: Boolean? = null,
private val reply_to_message: RawMessage? = null,
private val via_bot: CommonBot? = null,
private val edit_date: TelegramDate? = null,
private val has_protected_content: Boolean? = null,
private val media_group_id: MediaGroupIdentifier? = null,
private val author_signature: AuthorSignature? = null,
private val text: String? = null,
@@ -250,6 +251,7 @@ internal data class RawMessage(
it,
checkedContent,
edit_date?.asDate,
has_protected_content != true,
forwarded,
reply_to_message?.asMessage,
reply_markup
@@ -262,6 +264,7 @@ internal data class RawMessage(
it,
checkedContent,
edit_date?.asDate,
has_protected_content != true,
forwarded,
reply_to_message?.asMessage,
reply_markup
@@ -275,6 +278,7 @@ internal data class RawMessage(
content,
date.asDate,
edit_date?.asDate,
has_protected_content != true,
forwarded,
reply_to_message?.asMessage,
reply_markup,
@@ -282,25 +286,44 @@ internal data class RawMessage(
author_signature
)
is GroupChat -> when (sender_chat) {
is ChannelChat -> FromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
date.asDate,
forwarded,
edit_date ?.asDate,
reply_to_message ?.asMessage,
reply_markup,
content,
via_bot,
author_signature
)
is ChannelChat -> if (is_automatic_forward == true) {
ConnectedFromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
date.asDate,
forwarded,
edit_date ?.asDate,
has_protected_content != true,
reply_to_message ?.asMessage,
reply_markup,
content,
via_bot,
author_signature
)
} else {
UnconnectedFromChannelGroupContentMessageImpl(
chat,
sender_chat,
messageId,
date.asDate,
forwarded,
edit_date ?.asDate,
has_protected_content != true,
reply_to_message ?.asMessage,
reply_markup,
content,
via_bot,
author_signature
)
}
is GroupChat -> AnonymousGroupContentMessageImpl(
chat,
messageId,
date.asDate,
forwarded,
edit_date ?.asDate,
has_protected_content != true,
reply_to_message ?.asMessage,
reply_markup,
content,
@@ -314,6 +337,7 @@ internal data class RawMessage(
date.asDate,
forwarded,
edit_date ?.asDate,
has_protected_content != true,
reply_to_message ?.asMessage,
reply_markup,
content,
@@ -330,6 +354,7 @@ internal data class RawMessage(
content,
date.asDate,
edit_date?.asDate,
has_protected_content != true,
forwarded,
reply_to_message?.asMessage,
reply_markup,

View File

@@ -3,5 +3,9 @@ package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
interface ContentMessage<T: MessageContent>: Message {
val forwardable: Boolean
val content: T
val hasProtectedContent: Boolean
get() = !forwardable
}

View File

@@ -15,6 +15,9 @@ interface FromChannelGroupContentMessage<T : MessageContent> : GroupContentMessa
get() = channel
}
interface ConnectedFromChannelGroupContentMessage<T: MessageContent> : FromChannelGroupContentMessage<T>
interface UnconnectedFromChannelGroupContentMessage<T: MessageContent> : FromChannelGroupContentMessage<T>
interface AnonymousGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, SignedMessage, WithSenderChatMessage {
override val senderChat: GroupChat
get() = chat

View File

@@ -4,8 +4,6 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
import dev.inmo.tgbotapi.types.message.payments.abstracts.PaymentInfo
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
@Deprecated("Renamed", ReplaceWith("SuccessfulPaymentEvent", "dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent"))
typealias SuccessfulPaymentInfo = SuccessfulPaymentEvent
data class SuccessfulPaymentEvent(
val payment: SuccessfulPayment
) : PaymentInfo, CommonEvent

View File

@@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.update.abstracts.Update
data class ChatJoinRequestUpdate(
override val updateId: UpdateIdentifier,
override val data: ChatJoinRequest
) : Update

View File

@@ -35,7 +35,8 @@ internal data class RawUpdate constructor(
private val poll: Poll? = null,
private val poll_answer: PollAnswer? = null,
private val my_chat_member: ChatMemberUpdated? = null,
private val chat_member: ChatMemberUpdated? = null
private val chat_member: ChatMemberUpdated? = null,
private val chat_join_request: ChatJoinRequest? = null
) {
private var initedUpdate: Update? = null
/**
@@ -61,6 +62,7 @@ internal data class RawUpdate constructor(
poll_answer != null -> PollAnswerUpdate(updateId, poll_answer)
my_chat_member != null -> MyChatMemberUpdatedUpdate(updateId, my_chat_member)
chat_member != null -> CommonChatMemberUpdatedUpdate(updateId, chat_member)
chat_join_request != null -> ChatJoinRequestUpdate(updateId, chat_join_request)
else -> UnknownUpdate(
updateId,
raw.toString(),

View File

@@ -32,6 +32,7 @@ interface FlowsUpdatesFilter : UpdatesFilter {
val pollAnswersFlow: Flow<PollAnswerUpdate>
val chatMemberUpdatesFlow: Flow<CommonChatMemberUpdatedUpdate>
val myChatMemberUpdatesFlow: Flow<MyChatMemberUpdatedUpdate>
val chatJoinRequestUpdateFlow: Flow<ChatJoinRequestUpdate>
val unknownUpdatesFlow: Flow<UnknownUpdate>
}
@@ -62,6 +63,7 @@ abstract class AbstractFlowsUpdatesFilter : FlowsUpdatesFilter {
override val pollAnswersFlow: Flow<PollAnswerUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val chatMemberUpdatesFlow: Flow<CommonChatMemberUpdatedUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val myChatMemberUpdatesFlow: Flow<MyChatMemberUpdatedUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val chatJoinRequestUpdateFlow: Flow<ChatJoinRequestUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
override val unknownUpdatesFlow: Flow<UnknownUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
}

View File

@@ -27,6 +27,7 @@ class BotActionTests {
FindLocationAction -> example.botAction.actionName
RecordVideoNoteAction -> example.botAction.actionName
UploadVideoNoteAction -> example.botAction.actionName
ChooseStickerAction -> example.botAction.actionName
is CustomBotAction -> example.botAction.actionName
}
)
@@ -56,7 +57,8 @@ class BotActionTests {
UploadDocumentAction.example(),
FindLocationAction.example(),
RecordVideoNoteAction.example(),
UploadVideoNoteAction.example()
UploadVideoNoteAction.example(),
ChooseStickerAction.example(),
).forEach {
checkBotActionSerializeDeserialize(it)
}

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -43,8 +49,7 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -43,8 +43,7 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -43,8 +49,7 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -43,8 +49,7 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -61,7 +67,6 @@ kotlin {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -915,15 +915,15 @@ inline fun Message.requireAnonymousGroupContentMessageImpl(): AnonymousGroupCont
this as AnonymousGroupContentMessageImpl<MessageContent>
@PreviewFeature
inline fun <T> Message.whenChannelContentMessageImpl(block: (ChannelContentMessageImpl<MessageContent>) -> T) = asChannelContentMessageImpl() ?.let(block)
inline fun <T> Message.whenChannelContentMessageImpl(block: (UnconnectedFromChannelGroupContentMessageImpl<MessageContent>) -> T) = asChannelContentMessageImpl() ?.let(block)
@PreviewFeature
inline fun Message.asChannelContentMessageImpl(): ChannelContentMessageImpl<MessageContent>? =
this as? ChannelContentMessageImpl<MessageContent>
inline fun Message.asChannelContentMessageImpl(): UnconnectedFromChannelGroupContentMessageImpl<MessageContent>? =
this as? UnconnectedFromChannelGroupContentMessageImpl<MessageContent>
@PreviewFeature
inline fun Message.requireChannelContentMessageImpl(): ChannelContentMessageImpl<MessageContent> =
this as ChannelContentMessageImpl<MessageContent>
inline fun Message.requireChannelContentMessageImpl(): UnconnectedFromChannelGroupContentMessageImpl<MessageContent> =
this as UnconnectedFromChannelGroupContentMessageImpl<MessageContent>
@PreviewFeature
inline fun <T> Message.whenFromChannelGroupContentMessageImpl(block: (FromChannelGroupContentMessageImpl<MessageContent>) -> T) = asFromChannelGroupContentMessageImpl() ?.let(block)
@@ -1027,11 +1027,33 @@ inline fun <T> Message.whenChannelContentMessage(block: (ChannelContentMessage<M
@PreviewFeature
inline fun Message.asChannelContentMessage(): ChannelContentMessage<MessageContent>? =
this as? ChannelContentMessageImpl<MessageContent>
this as? ChannelContentMessage<MessageContent>
@PreviewFeature
inline fun Message.requireChannelContentMessage(): ChannelContentMessageImpl<MessageContent> =
this as ChannelContentMessageImpl<MessageContent>
inline fun Message.requireChannelContentMessage(): ChannelContentMessage<MessageContent> =
this as ChannelContentMessage<MessageContent>
@PreviewFeature
inline fun <T> Message.whenConnectedFromChannelGroupContentMessage(block: (ConnectedFromChannelGroupContentMessage<MessageContent>) -> T) = asConnectedFromChannelGroupContentMessage() ?.let(block)
@PreviewFeature
inline fun Message.asConnectedFromChannelGroupContentMessage(): ConnectedFromChannelGroupContentMessage<MessageContent>? =
this as? ConnectedFromChannelGroupContentMessageImpl<MessageContent>
@PreviewFeature
inline fun Message.requireConnectedFromChannelGroupContentMessage(): ConnectedFromChannelGroupContentMessage<MessageContent> =
this as ConnectedFromChannelGroupContentMessage<MessageContent>
@PreviewFeature
inline fun <T> Message.whenUnconnectedFromChannelGroupContentMessage(block: (UnconnectedFromChannelGroupContentMessage<MessageContent>) -> T) = asUnconnectedFromChannelGroupContentMessage() ?.let(block)
@PreviewFeature
inline fun Message.asUnconnectedFromChannelGroupContentMessage(): UnconnectedFromChannelGroupContentMessage<MessageContent>? =
this as? UnconnectedFromChannelGroupContentMessage<MessageContent>
@PreviewFeature
inline fun Message.requireUnconnectedFromChannelGroupContentMessage(): UnconnectedFromChannelGroupContentMessage<MessageContent> =
this as UnconnectedFromChannelGroupContentMessage<MessageContent>
@PreviewFeature
inline fun <T> Message.whenChatEventMessage(block: (ChatEventMessage<ChatEvent>) -> T) = asChatEventMessage() ?.let(block)
@@ -1274,6 +1296,15 @@ inline fun BotAction.asTypingAction(): TypingAction? = this as? TypingAction
@PreviewFeature
inline fun BotAction.requireTypingAction(): TypingAction = this as TypingAction
@PreviewFeature
inline fun <T> BotAction.whenChooseStickerAction(block: (ChooseStickerAction) -> T) = asChooseStickerAction() ?.let(block)
@PreviewFeature
inline fun BotAction.asChooseStickerAction(): ChooseStickerAction? = this as? ChooseStickerAction
@PreviewFeature
inline fun BotAction.requireChooseStickerAction(): ChooseStickerAction = this as ChooseStickerAction
@PreviewFeature
inline fun <T> BotAction.whenUploadVoiceAction(block: (UploadVoiceAction) -> T) = asUploadVoiceAction() ?.let(block)
@@ -2204,6 +2235,15 @@ inline fun Update.asChatMemberUpdatedUpdate(): ChatMemberUpdatedUpdate? = this a
@PreviewFeature
inline fun Update.requireChatMemberUpdatedUpdate(): ChatMemberUpdatedUpdate = this as ChatMemberUpdatedUpdate
@PreviewFeature
inline fun <T> Update.whenChatJoinRequestUpdate(block: (ChatJoinRequestUpdate) -> T) = asChatJoinRequestUpdate() ?.let(block)
@PreviewFeature
inline fun Update.asChatJoinRequestUpdate(): ChatJoinRequestUpdate? = this as? ChatJoinRequestUpdate
@PreviewFeature
inline fun Update.requireChatJoinRequestUpdate(): ChatJoinRequestUpdate = this as ChatJoinRequestUpdate
@PreviewFeature
inline fun <T> TelegramMediaFile.whenAnimationFile(block: (AnimationFile) -> T) = asAnimationFile() ?.let(block)
@@ -3188,3 +3228,48 @@ inline fun Location.asLiveLocation(): LiveLocation? = this as? LiveLocation
@PreviewFeature
inline fun Location.requireLiveLocation(): LiveLocation = this as LiveLocation
@PreviewFeature
inline fun <T> ChatInviteLink.whenPrimaryInviteLink(block: (PrimaryInviteLink) -> T) = asPrimaryInviteLink() ?.let(block)
@PreviewFeature
inline fun ChatInviteLink.asPrimaryInviteLink(): PrimaryInviteLink? = this as? PrimaryInviteLink
@PreviewFeature
inline fun ChatInviteLink.requirePrimaryInviteLink(): PrimaryInviteLink = this as PrimaryInviteLink
@PreviewFeature
inline fun <T> ChatInviteLink.whenSecondaryChatInviteLink(block: (SecondaryChatInviteLink) -> T) = asSecondaryChatInviteLink() ?.let(block)
@PreviewFeature
inline fun ChatInviteLink.asSecondaryChatInviteLink(): SecondaryChatInviteLink? = this as? SecondaryChatInviteLink
@PreviewFeature
inline fun ChatInviteLink.requireSecondaryChatInviteLink(): SecondaryChatInviteLink = this as SecondaryChatInviteLink
@PreviewFeature
inline fun <T> ChatInviteLink.whenChatInviteLinkWithJoinRequest(block: (ChatInviteLinkWithJoinRequest) -> T) = asChatInviteLinkWithJoinRequest() ?.let(block)
@PreviewFeature
inline fun ChatInviteLink.asChatInviteLinkWithJoinRequest(): ChatInviteLinkWithJoinRequest? = this as? ChatInviteLinkWithJoinRequest
@PreviewFeature
inline fun ChatInviteLink.requireChatInviteLinkWithJoinRequest(): ChatInviteLinkWithJoinRequest = this as ChatInviteLinkWithJoinRequest
@PreviewFeature
inline fun <T> ChatInviteLink.whenChatInviteLinkWithLimitedMembers(block: (ChatInviteLinkWithLimitedMembers) -> T) = asChatInviteLinkWithLimitedMembers() ?.let(block)
@PreviewFeature
inline fun ChatInviteLink.asChatInviteLinkWithLimitedMembers(): ChatInviteLinkWithLimitedMembers? = this as? ChatInviteLinkWithLimitedMembers
@PreviewFeature
inline fun ChatInviteLink.requireChatInviteLinkWithLimitedMembers(): ChatInviteLinkWithLimitedMembers = this as ChatInviteLinkWithLimitedMembers
@PreviewFeature
inline fun <T> ChatInviteLink.whenChatInviteLinkUnlimited(block: (ChatInviteLinkUnlimited) -> T) = asChatInviteLinkUnlimited() ?.let(block)
@PreviewFeature
inline fun ChatInviteLink.asChatInviteLinkUnlimited(): ChatInviteLinkUnlimited? = this as? ChatInviteLinkUnlimited
@PreviewFeature
inline fun ChatInviteLink.requireChatInviteLinkUnlimited(): ChatInviteLinkUnlimited = this as ChatInviteLinkUnlimited

View File

@@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.CommonAbstracts.WithUser
import dev.inmo.tgbotapi.extensions.utils.asFromUser
import dev.inmo.tgbotapi.extensions.utils.asUser
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.update.*
@@ -14,12 +15,13 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.utils.PreviewFeature
@PreviewFeature
fun Update.sourceChat(): Chat? = when {
this is MediaGroupUpdate -> when (this) {
fun Update.sourceChat(): Chat? = when (this) {
is MediaGroupUpdate -> when (this) {
is SentMediaGroupUpdate -> data.chat
is EditMediaGroupUpdate -> data.chat
}
this is BaseMessageUpdate -> data.chat
is BaseMessageUpdate -> data.chat
is ChatJoinRequestUpdate -> data.chat
else -> {
when (val data = data) {
is FromUser -> data.from

View File

@@ -429,7 +429,7 @@ inline fun EntitiesBuilder.link(text: String, url: String) = add(dev.inmo.tgbota
/**
* Version of [EntitiesBuilder.link] with new line at the end
*/
inline fun EntitiesBuilder.linkln(text: String, url: String) = link(text) + newLine
inline fun EntitiesBuilder.linkln(text: String, url: String) = link(text, url) + newLine
/**
* Add link using [EntitiesBuilder.add] with [dev.inmo.tgbotapi.types.MessageEntity.textsources.link]
*/

View File

@@ -26,7 +26,13 @@ repositories {
}
kotlin {
jvm()
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
@@ -46,10 +52,8 @@ kotlin {
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}