mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-12-29 09:29:23 +00:00
Compare commits
5 Commits
0f5bce592b
...
d70c7fdbdf
| Author | SHA1 | Date | |
|---|---|---|---|
| d70c7fdbdf | |||
| f14885a541 | |||
| 0013e91f6e | |||
| aa315f6fec | |||
| 9425380002 |
@@ -16,6 +16,9 @@ kotlin {
|
||||
api project(":tgbotapi.core")
|
||||
}
|
||||
}
|
||||
configureEach {
|
||||
languageSettings.optIn("kotlinx.serialization.ExperimentalSerializationApi")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.DeleteMessages
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
suspend fun TelegramBot.deleteMessages(
|
||||
chatId: ChatIdentifier,
|
||||
@@ -35,14 +37,19 @@ suspend fun TelegramBot.deleteMessages(
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.deleteMessages(
|
||||
messages: List<AccessibleMessage>
|
||||
) = messages.groupBy { it.chat }.map { (chat, messages) ->
|
||||
messagesMetas: List<Message.MetaInfo>
|
||||
) = messagesMetas.groupBy { it.chatId }.map { (chatId, messages) ->
|
||||
deleteMessages(
|
||||
chatId = chat.id,
|
||||
chatId = chatId,
|
||||
messageIds = messages.map { it.messageId }
|
||||
)
|
||||
}.all { it }
|
||||
|
||||
@JvmName("deleteMessagesWithMessages")
|
||||
suspend fun TelegramBot.deleteMessages(
|
||||
messages: List<AccessibleMessage>
|
||||
) = deleteMessages(messages.map { it.metaInfo })
|
||||
|
||||
suspend fun TelegramBot.delete(
|
||||
chatId: ChatIdentifier,
|
||||
messageIds: List<MessageId>
|
||||
@@ -60,6 +67,12 @@ suspend fun TelegramBot.delete(
|
||||
vararg messageIds: MessageId
|
||||
) = deleteMessages(chatId = chatId, messageIds = (listOf(firstMessageId, secondMessageId) + messageIds.toList()))
|
||||
|
||||
|
||||
suspend fun TelegramBot.delete(
|
||||
messagesMetas: List<Message.MetaInfo>
|
||||
) = deleteMessages(messagesMetas)
|
||||
|
||||
@JvmName("deleteWithMessages")
|
||||
suspend fun TelegramBot.delete(
|
||||
messages: List<AccessibleMessage>
|
||||
) = deleteMessages(messages)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package dev.inmo.tgbotapi.extensions.api
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.send.copyMessages
|
||||
import dev.inmo.tgbotapi.requests.ForwardMessages
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
suspend fun TelegramBot.forwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
@@ -66,15 +69,15 @@ suspend fun TelegramBot.forwardMessages(
|
||||
|
||||
suspend fun TelegramBot.forwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = messages.groupBy { it.chat }.flatMap { (chat, messages) ->
|
||||
) = messagesMetas.groupBy { it.chatId }.flatMap { (chatId, messages) ->
|
||||
forwardMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = chat.id,
|
||||
fromChatId = chatId,
|
||||
messageIds = messages.map { it.messageId },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
@@ -83,6 +86,23 @@ suspend fun TelegramBot.forwardMessages(
|
||||
)
|
||||
}
|
||||
|
||||
@JvmName("forwardMessagesWithMessages")
|
||||
suspend fun TelegramBot.forwardMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = forwardMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messages.map { it.metaInfo },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.forward(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
@@ -139,6 +159,23 @@ suspend fun TelegramBot.forward(
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.forward(
|
||||
toChatId: ChatIdentifier,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = forwardMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messagesMetas,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
@JvmName("forwardWithMessages")
|
||||
suspend fun TelegramBot.forward(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
|
||||
@@ -4,6 +4,8 @@ import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.send.CopyMessages
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
suspend fun TelegramBot.copyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
@@ -66,15 +68,15 @@ suspend fun TelegramBot.copyMessages(
|
||||
|
||||
suspend fun TelegramBot.copyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = messages.groupBy { it.chat }.flatMap { (chat, messages) ->
|
||||
) = messagesMetas.groupBy { it.chatId }.flatMap { (chatId, messages) ->
|
||||
copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = chat.id,
|
||||
fromChatId = chatId,
|
||||
messageIds = messages.map { it.messageId },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
@@ -82,3 +84,109 @@ suspend fun TelegramBot.copyMessages(
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
}
|
||||
|
||||
@JvmName("copyMessagesWithMessages")
|
||||
suspend fun TelegramBot.copyMessages(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messages.map { it.metaInfo },
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageIds: List<MessageId>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = messageIds,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
messageIds: Array<MessageId>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
messageIds = messageIds,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
fromChatId: ChatIdentifier,
|
||||
firstMessageId: MessageId,
|
||||
vararg messageIds: MessageId,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
fromChatId = fromChatId,
|
||||
firstMessageId = firstMessageId,
|
||||
messageIds = messageIds,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
messagesMetas: List<Message.MetaInfo>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
messagesMetas = messagesMetas,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
@JvmName("copyWithMessages")
|
||||
suspend fun TelegramBot.copy(
|
||||
toChatId: ChatIdentifier,
|
||||
messages: List<AccessibleMessage>,
|
||||
threadId: MessageThreadId? = toChatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
removeCaption: Boolean = false
|
||||
) = copyMessages(
|
||||
toChatId = toChatId,
|
||||
messages = messages,
|
||||
threadId = threadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
removeCaption = removeCaption
|
||||
)
|
||||
|
||||
@@ -23,6 +23,7 @@ import dev.inmo.tgbotapi.types.request.UsersShared
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
|
||||
typealias EventMessageToEventMapper<T> = suspend ChatEventMessage<T>.() -> T?
|
||||
|
||||
@@ -199,11 +200,16 @@ suspend fun BehaviourContext.waitChatSharedRequest(
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<ChatSharedRequest>(initRequest, errorFactory)
|
||||
|
||||
suspend fun BehaviourContext.waitUserShared(
|
||||
suspend fun BehaviourContext.waitUsersShared(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<UsersShared>(initRequest, errorFactory)
|
||||
|
||||
suspend fun BehaviourContext.waitUserShared(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitUsersShared(initRequest, errorFactory).filter { it.userIds.size == 1 }
|
||||
|
||||
suspend fun BehaviourContext.waitChatShared(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
|
||||
@@ -23,6 +23,7 @@ import dev.inmo.tgbotapi.types.request.UsersShared
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEventsMessages(
|
||||
@@ -193,11 +194,16 @@ suspend fun BehaviourContext.waitChatSharedRequestEventsMessages(
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<ChatSharedRequest>(initRequest, errorFactory)
|
||||
|
||||
suspend fun BehaviourContext.waitUserSharedEventsMessages(
|
||||
suspend fun BehaviourContext.waitUsersSharedEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<UsersShared>(initRequest, errorFactory)
|
||||
|
||||
suspend fun BehaviourContext.waitUserSharedEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitUsersSharedEventsMessages(initRequest, errorFactory).filter { it.chatEvent.userIds.size == 1 }
|
||||
|
||||
suspend fun BehaviourContext.waitChatSharedEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByCha
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.chatEventMessageOrNull
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
@@ -775,7 +776,7 @@ suspend fun <BC : BehaviourContext> BC.onChatSharedRequest(
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onUserShared(
|
||||
suspend fun <BC : BehaviourContext> BC.onUsersShared(
|
||||
initialFilter: SimpleFilter<PrivateEventMessage<UsersShared>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PrivateEventMessage<UsersShared>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<UsersShared>, Any> = ByChatMessageMarkerFactory,
|
||||
@@ -783,6 +784,26 @@ suspend fun <BC : BehaviourContext> BC.onUserShared(
|
||||
) = onEventWithCustomChatEventMessage(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,
|
||||
* 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.onUserShared(
|
||||
initialFilter: SimpleFilter<PrivateEventMessage<UsersShared>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PrivateEventMessage<UsersShared>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<UsersShared>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PrivateEventMessage<UsersShared>>
|
||||
) = onUsersShared(initialFilter * { it.chatEvent.userIds.size == 1 }, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
|
||||
@@ -98,6 +98,7 @@ data class MultipartFile (
|
||||
private val inputSource: () -> Input
|
||||
) : InputFile() {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val fileId: String = "${uuid4()}.${filename.fileExtension}"
|
||||
val input: Input
|
||||
get() = inputSource()
|
||||
|
||||
@@ -112,6 +112,7 @@ data class CreateChatInviteLinkWithJoinRequest(
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) : CreateChatInviteLink<ChatInviteLinkWithJoinRequest>, WithJoinRequestChatInviteLinkRequest {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(createsJoinRequestField)
|
||||
private val createsJoinRequest: Boolean = true
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ data class EditChatInviteLinkWithJoinRequest(
|
||||
) : EditChatInviteLink<ChatInviteLinkWithJoinRequest>,
|
||||
WithJoinRequestChatInviteLinkRequest {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(createsJoinRequestField)
|
||||
private val createsJoinRequest: Boolean = true
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ sealed interface LinkPreviewOptions {
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Medium(
|
||||
data class Default(
|
||||
@SerialName(urlField)
|
||||
override val url: String?,
|
||||
@SerialName(showAboveTextField)
|
||||
@@ -84,7 +84,7 @@ sealed interface LinkPreviewOptions {
|
||||
@Serializable
|
||||
private data class Surrogate(
|
||||
@SerialName(isDisabledField)
|
||||
val isDisabled: Boolean = true,
|
||||
val isDisabled: Boolean = false,
|
||||
@SerialName(urlField)
|
||||
val url: String? = null,
|
||||
@SerialName(preferSmallMediaField)
|
||||
@@ -108,7 +108,7 @@ sealed interface LinkPreviewOptions {
|
||||
surrogate.isDisabled -> Disabled
|
||||
surrogate.preferLargeMedia -> Large(surrogate.url, surrogate.showAboveText)
|
||||
surrogate.preferSmallMedia -> Small(surrogate.url, surrogate.showAboveText)
|
||||
else -> Medium(surrogate.url, surrogate.showAboveText)
|
||||
else -> Default(surrogate.url, surrogate.showAboveText)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ sealed interface LinkPreviewOptions {
|
||||
when (value) {
|
||||
is Disabled -> Disabled.serializer().serialize(encoder, value)
|
||||
is Large -> Large.serializer().serialize(encoder, value)
|
||||
is Medium -> Medium.serializer().serialize(encoder, value)
|
||||
is Default -> Default.serializer().serialize(encoder, value)
|
||||
is Small -> Small.serializer().serialize(encoder, value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,15 @@ import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
@Serializable(MenuButtonSerializer::class)
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
sealed interface MenuButton {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
val type: String
|
||||
|
||||
@Serializable
|
||||
object Commands : MenuButton {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String
|
||||
get() = "commands"
|
||||
}
|
||||
@@ -27,6 +29,7 @@ sealed interface MenuButton {
|
||||
val webApp: WebAppInfo
|
||||
) : MenuButton {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String
|
||||
get() = Companion.type
|
||||
|
||||
@@ -39,6 +42,7 @@ sealed interface MenuButton {
|
||||
@Serializable
|
||||
object Default : MenuButton {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String
|
||||
get() = "default"
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@ import dev.inmo.tgbotapi.abstracts.WithMessageId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewUser
|
||||
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Required
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
@@ -31,6 +28,7 @@ sealed interface ChatBoostSource {
|
||||
override val user: PreviewUser
|
||||
) : ByUser {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(sourceField)
|
||||
override val sourceName: String = sourceCode
|
||||
|
||||
@@ -45,6 +43,7 @@ sealed interface ChatBoostSource {
|
||||
override val user: PreviewUser
|
||||
) : ByUser {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(sourceField)
|
||||
override val sourceName: String = sourceCode
|
||||
|
||||
@@ -67,9 +66,11 @@ sealed interface ChatBoostSource {
|
||||
override val user: PreviewUser
|
||||
) : Giveaway, ByUser {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(sourceField)
|
||||
override val sourceName: String = Giveaway.sourceCode
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(isUnclaimedField)
|
||||
override val unclaimed: Boolean = false
|
||||
}
|
||||
@@ -80,9 +81,11 @@ sealed interface ChatBoostSource {
|
||||
override val messageId: MessageId
|
||||
) : Giveaway {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(sourceField)
|
||||
override val sourceName: String = Giveaway.sourceCode
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(isUnclaimedField)
|
||||
override val unclaimed: Boolean = true
|
||||
@SerialName(userField)
|
||||
@@ -104,6 +107,7 @@ sealed interface ChatBoostSource {
|
||||
@Serializable
|
||||
private data class Surrogate(
|
||||
@Required
|
||||
@EncodeDefault
|
||||
@SerialName(sourceField)
|
||||
val sourceName: String,
|
||||
@SerialName(userField)
|
||||
|
||||
@@ -65,6 +65,7 @@ data class RequestLocationKeyboardButton(
|
||||
) : KeyboardButton {
|
||||
@SerialName(requestLocationField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
val requestLocation: Boolean = true
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ data class ReplyForce(
|
||||
) : KeyboardMarkup {
|
||||
@SerialName(forceReplyField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
val forceReply: Boolean = true
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -8,5 +8,6 @@ data class ReplyKeyboardRemove(
|
||||
) : KeyboardMarkup {
|
||||
@SerialName("remove_keyboard")
|
||||
@Required
|
||||
@EncodeDefault
|
||||
val removeKeyboard: Boolean = true
|
||||
}
|
||||
|
||||
@@ -45,5 +45,6 @@ data class AdministratorChatMemberImpl(
|
||||
) : AdministratorChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val status: ChatMember.Status = ChatMember.Status.Administrator
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@ data class KickedChatMember(
|
||||
) : BannedChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val status: ChatMember.Status = ChatMember.Status.Kicked
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ data class LeftChatMemberImpl(
|
||||
) : LeftChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val status: ChatMember.Status = ChatMember.Status.Left
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ data class MemberChatMemberImpl(
|
||||
) : MemberChatMember {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val status: ChatMember.Status = ChatMember.Status.Member
|
||||
}
|
||||
|
||||
@@ -45,5 +45,6 @@ data class OwnerChatMember(
|
||||
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val status: ChatMember.Status = ChatMember.Status.Creator
|
||||
}
|
||||
|
||||
@@ -44,5 +44,6 @@ data class RestrictedChatMember(
|
||||
) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val status: ChatMember.Status = ChatMember.Status.Restricted
|
||||
}
|
||||
|
||||
@@ -71,24 +71,28 @@ data class UnknownBotCommandScope internal constructor(
|
||||
@Serializable
|
||||
object BotCommandScopeDefault : BotCommandScope {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = "default"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
object BotCommandScopeAllPrivateChats : BotCommandScope {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = "all_private_chats"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
object BotCommandScopeAllGroupChats : BotCommandScope {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = "all_group_chats"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
object BotCommandScopeAllChatAdministrators : BotCommandScope {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = "all_chat_administrators"
|
||||
}
|
||||
|
||||
@@ -102,6 +106,7 @@ data class BotCommandScopeChatAdministrators(
|
||||
override val chatId: ChatIdentifier
|
||||
) : ChatBotCommandScope {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = BotCommandScopeChatAdministrators.type
|
||||
companion object {
|
||||
const val type = "chat_administrators"
|
||||
@@ -113,6 +118,7 @@ data class BotCommandScopeChat(
|
||||
override val chatId: ChatIdentifier
|
||||
) : ChatBotCommandScope {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = BotCommandScopeChat.type
|
||||
companion object {
|
||||
const val type = "chat"
|
||||
@@ -125,6 +131,7 @@ data class BotCommandScopeChatMember(
|
||||
val userId: UserId
|
||||
) : ChatBotCommandScope {
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = BotCommandScopeChatMember.type
|
||||
companion object {
|
||||
const val type = "chat_member"
|
||||
|
||||
@@ -4,10 +4,7 @@ import dev.inmo.tgbotapi.abstracts.WithPreviewChatAndMessageId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewChat
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewUser
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Required
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
@@ -32,6 +29,7 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
||||
) : GiveawayPublicResults {
|
||||
@SerialName(wasRefundedField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val refunded: Boolean = true
|
||||
@SerialName(winnersCountField)
|
||||
override val count: Int = 0
|
||||
@@ -78,6 +76,7 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
||||
) : GiveawayPublicResults {
|
||||
@SerialName(wasRefundedField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val refunded: Boolean = false
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@ package dev.inmo.tgbotapi.types.message
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Required
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
@@ -27,6 +24,7 @@ sealed interface MessageOrigin {
|
||||
) : MessageOrigin {
|
||||
@SerialName(typeField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = Companion.type
|
||||
|
||||
companion object {
|
||||
@@ -43,6 +41,7 @@ sealed interface MessageOrigin {
|
||||
) : MessageOrigin {
|
||||
@SerialName(typeField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = Companion.type
|
||||
|
||||
companion object {
|
||||
@@ -66,6 +65,7 @@ sealed interface MessageOrigin {
|
||||
) : Public {
|
||||
@SerialName(typeField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = Companion.type
|
||||
|
||||
companion object {
|
||||
@@ -86,6 +86,7 @@ sealed interface MessageOrigin {
|
||||
) : Public {
|
||||
@SerialName(typeField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val type: String = Companion.type
|
||||
|
||||
companion object {
|
||||
@@ -105,6 +106,7 @@ sealed interface MessageOrigin {
|
||||
private data class Surrogate(
|
||||
@SerialName(typeField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
val type: String,
|
||||
@SerialName(senderChatField)
|
||||
val senderChat: PreviewChat? = null,
|
||||
|
||||
@@ -100,6 +100,7 @@ data class PassportElementErrorDataField(
|
||||
) : PassportSingleElementError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = dataField
|
||||
}
|
||||
fun EncryptedPassportElementWithData.createDataError(field: String, message: String) = PassportElementErrorDataField(
|
||||
@@ -121,6 +122,7 @@ data class PassportElementErrorFrontSide(
|
||||
) : PassportElementFileError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = frontSideField
|
||||
}
|
||||
fun EncryptedPassportElementWithFrontSide.createFrontSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFrontSide(
|
||||
@@ -141,6 +143,7 @@ data class PassportElementErrorReverseSide(
|
||||
) : PassportElementFileError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = reverseSideField
|
||||
}
|
||||
fun EncryptedPassportElementWithReverseSide.createReverseSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorReverseSide(
|
||||
@@ -160,6 +163,7 @@ data class PassportElementErrorSelfie(
|
||||
) : PassportElementFileError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = selfieField
|
||||
}
|
||||
fun EncryptedPassportElementWithSelfie.createSelfieError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorSelfie(
|
||||
@@ -181,6 +185,7 @@ data class PassportElementErrorFile(
|
||||
) : PassportElementFileError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = fileField
|
||||
}
|
||||
fun EncryptedPassportElementWithFilesCollection.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFile(
|
||||
@@ -200,6 +205,7 @@ data class PassportElementErrorFiles(
|
||||
) : PassportElementFilesError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = filesField
|
||||
}
|
||||
fun EncryptedPassportElementWithFilesCollection.createFilesError(message: String, unencryptedFileHashes: List<PassportElementHash>) = PassportElementErrorFiles(
|
||||
@@ -221,6 +227,7 @@ data class PassportElementErrorTranslationFile(
|
||||
) : PassportElementFileError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = translationFileField
|
||||
}
|
||||
fun EncryptedPassportElementTranslatable.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorTranslationFile(
|
||||
@@ -239,6 +246,7 @@ data class PassportElementErrorTranslationFiles(
|
||||
) : PassportElementFilesError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = translationFilesField
|
||||
}
|
||||
fun EncryptedPassportElementTranslatable.createFilesError(message: String, unencryptedFileHashes: List<PassportElementHash>) = PassportElementErrorTranslationFiles(
|
||||
@@ -259,6 +267,7 @@ data class PassportElementErrorUnspecified(
|
||||
) : PassportElementFileError() {
|
||||
@SerialName(sourceField)
|
||||
@Required
|
||||
@EncodeDefault
|
||||
override val source: String = unspecifiedField
|
||||
}
|
||||
fun EncryptedPassportElement.createUnspecifiedError(message: String, elementHash: PassportElementHash) = PassportElementErrorUnspecified(
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.types.buttons.*
|
||||
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
||||
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
||||
import dev.inmo.tgbotapi.types.request.RequestId
|
||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
@@ -137,7 +138,7 @@ inline fun ReplyKeyboardRowBuilder.webAppButton(
|
||||
* @see replyKeyboard
|
||||
* @see ReplyKeyboardBuilder.row
|
||||
*/
|
||||
inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
||||
text: String,
|
||||
requestUser: KeyboardButtonRequestUsers
|
||||
) = add(
|
||||
@@ -147,6 +148,33 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* Creates and put [RequestUserKeyboardButton]
|
||||
*
|
||||
* @see replyKeyboard
|
||||
* @see ReplyKeyboardBuilder.row
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("requestUsersButton(text, requestUser)", "dev.inmo.tgbotapi.extensions.utils.types.buttons"))
|
||||
inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
text: String,
|
||||
requestUser: KeyboardButtonRequestUsers
|
||||
) = requestUsersButton(text, requestUser)
|
||||
|
||||
/**
|
||||
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
||||
*
|
||||
* @see replyKeyboard
|
||||
* @see ReplyKeyboardBuilder.row
|
||||
*/
|
||||
inline fun ReplyKeyboardRowBuilder.requestBotsButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
maxCount: Int
|
||||
) = requestUsersButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Bot(requestId, maxCount)
|
||||
)
|
||||
|
||||
/**
|
||||
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
||||
*
|
||||
@@ -156,9 +184,26 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
inline fun ReplyKeyboardRowBuilder.requestBotButton(
|
||||
text: String,
|
||||
requestId: RequestId
|
||||
) = requestUserButton(
|
||||
) = requestBotsButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Bot(requestId)
|
||||
requestId,
|
||||
maxCount = keyboardButtonRequestUserLimit.first
|
||||
)
|
||||
|
||||
/**
|
||||
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Common]
|
||||
*
|
||||
* @see replyKeyboard
|
||||
* @see ReplyKeyboardBuilder.row
|
||||
*/
|
||||
inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
premiumUser: Boolean? = null,
|
||||
maxCount: Int
|
||||
) = requestUsersButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Common(requestId, premiumUser, maxCount)
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -171,9 +216,21 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
premiumUser: Boolean? = null
|
||||
) = requestUserButton(
|
||||
) = requestUsersButton(text, requestId, premiumUser, maxCount = keyboardButtonRequestUserLimit.first)
|
||||
|
||||
/**
|
||||
* Creates and put [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Any]
|
||||
*
|
||||
* @see replyKeyboard
|
||||
* @see ReplyKeyboardBuilder.row
|
||||
*/
|
||||
inline fun ReplyKeyboardRowBuilder.requestUsersOrBotsButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
maxCount: Int
|
||||
) = requestUsersButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Common(requestId, premiumUser)
|
||||
KeyboardButtonRequestUsers.Any(requestId, maxCount)
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -185,9 +242,10 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
inline fun ReplyKeyboardRowBuilder.requestUserOrBotButton(
|
||||
text: String,
|
||||
requestId: RequestId
|
||||
) = requestUserButton(
|
||||
) = requestUsersOrBotsButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Any(requestId)
|
||||
requestId,
|
||||
maxCount = keyboardButtonRequestUserLimit.first
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user