1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

fixes in typing of giveaways

This commit is contained in:
InsanusMokrassar 2024-01-07 17:40:41 +06:00
parent 6c76e1c47a
commit f760e60089
13 changed files with 187 additions and 42 deletions

View File

@ -138,3 +138,13 @@ suspend fun BehaviourContext.waitMediaContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent(initRequest, errorFactory).mapContent<MediaContent>()
suspend fun BehaviourContext.waitScheduledGiveawayContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent(initRequest, errorFactory).mapContent<ScheduledGiveawayContent>()
suspend fun BehaviourContext.waitGiveawayPublicResultsContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContent(initRequest, errorFactory).mapContent<GiveawayPublicResultsContent>()

View File

@ -152,3 +152,13 @@ suspend fun BehaviourContext.waitMediaContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage(initRequest, errorFactory).mapWithContent<MediaContent>()
suspend fun BehaviourContext.waitScheduledGiveawayContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage(initRequest, errorFactory).mapWithContent<ScheduledGiveawayContent>()
suspend fun BehaviourContext.waitGiveawayPublicResultsContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitContentMessage(initRequest, errorFactory).mapWithContent<GiveawayPublicResultsContent>()

View File

@ -130,3 +130,14 @@ suspend fun BehaviourContext.waitEditedInvoice(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContent<InvoiceContent>(initRequest, false, errorFactory)
suspend fun BehaviourContext.waitEditedScheduledGiveawayContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContent<ScheduledGiveawayContent>(initRequest, false, errorFactory)
suspend fun BehaviourContext.waitEditedGiveawayPublicResultsContent(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContent<GiveawayPublicResultsContent>(initRequest, false, errorFactory)

View File

@ -136,3 +136,14 @@ suspend fun BehaviourContext.waitEditedInvoiceMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<InvoiceContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedScheduledGiveawayContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<ScheduledGiveawayContent>(initRequest, errorFactory)
suspend fun BehaviourContext.waitEditedGiveawayPublicResultsContentMessage(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEditedContentMessage<GiveawayPublicResultsContent>(initRequest, errorFactory)

View File

@ -703,3 +703,52 @@ suspend fun <BC : BehaviourContext> BC.onMediaContent(
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.onScheduledGiveawayContent(
initialFilter: CommonMessageFilter<ScheduledGiveawayContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ScheduledGiveawayContentMessage, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ScheduledGiveawayContentMessage, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ScheduledGiveawayContentMessage>
) = onContentMessageWithType(
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.onScheduledGiveawayContent(
initialFilter: CommonMessageFilter<GiveawayPublicResultsContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, GiveawayPublicResultsContentMessage, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in GiveawayPublicResultsContentMessage, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, GiveawayPublicResultsContentMessage>
) = onContentMessageWithType(
initialFilter,
subcontextUpdatesFilter,
markerFactory,
scenarioReceiver
)

View File

@ -1,6 +1,8 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@ -11,4 +13,4 @@ data class GiveawayPrivateResults(
override val unclaimedCount: Int,
@Transient // TODO::Add message serializer
val message: AccessibleMessage? = null
) : GiveawayResults
) : GiveawayResults, ChatEvent, PublicChatEvent

View File

@ -6,6 +6,6 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
import kotlinx.serialization.Serializable
@Serializable
sealed interface GiveawayResults : WithPreviewChat, ChatEvent, PublicChatEvent {
sealed interface GiveawayResults : WithPreviewChat {
val unclaimedCount: Int
}

View File

@ -1,16 +1,19 @@
package dev.inmo.tgbotapi.types.giveaway
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent
import dev.inmo.tgbotapi.types.giveaway.GiveawayInfo
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Giveaway(
data class ScheduledGiveaway(
@SerialName(chatsField)
val chats: List<PreviewChat>,
@SerialName(winnersSelectionDateField)
@ -27,4 +30,4 @@ data class Giveaway(
val countries: List<IetfLang>? = null,
@SerialName(premiumSubscriptionMonthCountField)
override val premiumMonths: Int? = null
) : GiveawayInfo, ChatEvent, PublicChatEvent
) : GiveawayInfo

View File

@ -9,10 +9,8 @@ import dev.inmo.tgbotapi.types.dice.Dice
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.files.Sticker
import dev.inmo.tgbotapi.types.games.RawGame
import dev.inmo.tgbotapi.types.giveaway.Giveaway
import dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
import dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
import dev.inmo.tgbotapi.types.giveaway.GiveawayResults
import dev.inmo.tgbotapi.types.giveaway.*
import dev.inmo.tgbotapi.types.message.content.ScheduledGiveawayContent
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
@ -134,7 +132,7 @@ internal data class RawMessage(
// Giveaways
private val giveaway_created: GiveawayCreated? = null,
private val giveaway: Giveaway? = null,
private val giveaway: ScheduledGiveaway? = null,
private val giveaway_winners: GiveawayResults? = null,
private val giveaway_completed: GiveawayPrivateResults? = null,
) {
@ -193,6 +191,8 @@ internal data class RawMessage(
venue != null -> VenueContent(venue)
poll != null -> PollContent(poll)
invoice != null -> InvoiceContent(invoice)
giveaway != null -> ScheduledGiveawayContent(giveaway)
giveaway_winners is GiveawayPublicResults -> GiveawayPublicResultsContent(giveaway_winners)
else -> null
}
}
@ -237,8 +237,7 @@ internal data class RawMessage(
users_shared != null -> users_shared
chat_shared != null -> chat_shared
giveaway_created != null -> giveaway_created
giveaway != null -> giveaway
giveaway_winners != null -> giveaway_winners
giveaway_winners is GiveawayPrivateResults -> giveaway_winners
giveaway_completed != null -> giveaway_completed
else -> null
}

View File

@ -0,0 +1,25 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import kotlinx.serialization.Serializable
@Serializable
data class GiveawayPublicResultsContent(
val giveaway: GiveawayPublicResults
) : MessageContent {
override fun createResend(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId?,
disableNotification: Boolean,
protectContent: Boolean,
replyToMessageId: MessageId?,
allowSendingWithoutReply: Boolean?,
replyMarkup: KeyboardMarkup?
): Request<out AccessibleMessage> {
TODO("Not yet implemented")
}
}

View File

@ -0,0 +1,29 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.giveaway.GiveawayInfo
import dev.inmo.tgbotapi.types.giveaway.ScheduledGiveaway
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ScheduledGiveawayContent(
val giveaway: ScheduledGiveaway
) : MessageContent {
override fun createResend(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId?,
disableNotification: Boolean,
protectContent: Boolean,
replyToMessageId: MessageId?,
allowSendingWithoutReply: Boolean?,
replyMarkup: KeyboardMarkup?
): Request<out AccessibleMessage> {
TODO("Not yet implemented")
}
}

View File

@ -32,5 +32,7 @@ typealias VisualMediaGroupMessage = CommonMessage<VisualMediaGroupPartContent>
typealias VideoMessage = CommonMessage<VideoContent>
typealias PhotoMessage = CommonMessage<PhotoContent>
typealias AnimationMessage = CommonMessage<AnimationContent>
typealias ScheduledGiveawayContentMessage = CommonMessage<ScheduledGiveawayContent>
typealias GiveawayPublicResultsContentMessage = CommonMessage<GiveawayPublicResultsContent>

View File

@ -197,11 +197,8 @@ import dev.inmo.tgbotapi.types.files.VideoFile
import dev.inmo.tgbotapi.types.files.VideoNoteFile
import dev.inmo.tgbotapi.types.files.VideoSticker
import dev.inmo.tgbotapi.types.files.VoiceFile
import dev.inmo.tgbotapi.types.giveaway.Giveaway
import dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
import dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
import dev.inmo.tgbotapi.types.giveaway.GiveawayResults
import dev.inmo.tgbotapi.types.location.LiveLocation
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.location.StaticLocation
@ -298,6 +295,7 @@ import dev.inmo.tgbotapi.types.message.content.DiceContent
import dev.inmo.tgbotapi.types.message.content.DocumentContent
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent
import dev.inmo.tgbotapi.types.message.content.GameContent
import dev.inmo.tgbotapi.types.message.content.GiveawayPublicResultsContent
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
import dev.inmo.tgbotapi.types.message.content.LocationContent
@ -310,6 +308,7 @@ import dev.inmo.tgbotapi.types.message.content.MessageContent
import dev.inmo.tgbotapi.types.message.content.PhotoContent
import dev.inmo.tgbotapi.types.message.content.PollContent
import dev.inmo.tgbotapi.types.message.content.ResendableContent
import dev.inmo.tgbotapi.types.message.content.ScheduledGiveawayContent
import dev.inmo.tgbotapi.types.message.content.SpoilerableMediaContent
import dev.inmo.tgbotapi.types.message.content.StaticLocationContent
import dev.inmo.tgbotapi.types.message.content.StickerContent
@ -2781,15 +2780,6 @@ public inline fun TelegramMedia.titledTelegramMediaOrThrow(): TitledTelegramMedi
public inline fun <T> TelegramMedia.ifTitledTelegramMedia(block: (TitledTelegramMedia) -> T): T? =
titledTelegramMediaOrNull() ?.let(block)
public inline fun ChatEvent.giveawayOrNull(): Giveaway? = this as?
dev.inmo.tgbotapi.types.giveaway.Giveaway
public inline fun ChatEvent.giveawayOrThrow(): Giveaway = this as
dev.inmo.tgbotapi.types.giveaway.Giveaway
public inline fun <T> ChatEvent.ifGiveaway(block: (Giveaway) -> T): T? = giveawayOrNull()
?.let(block)
public inline fun ChatEvent.giveawayCreatedOrNull(): GiveawayCreated? = this as?
dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
@ -2808,24 +2798,6 @@ public inline fun ChatEvent.giveawayPrivateResultsOrThrow(): GiveawayPrivateResu
public inline fun <T> ChatEvent.ifGiveawayPrivateResults(block: (GiveawayPrivateResults) -> T): T? =
giveawayPrivateResultsOrNull() ?.let(block)
public inline fun ChatEvent.giveawayPublicResultsOrNull(): GiveawayPublicResults? = this as?
dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
public inline fun ChatEvent.giveawayPublicResultsOrThrow(): GiveawayPublicResults = this as
dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
public inline fun <T> ChatEvent.ifGiveawayPublicResults(block: (GiveawayPublicResults) -> T): T? =
giveawayPublicResultsOrNull() ?.let(block)
public inline fun ChatEvent.giveawayResultsOrNull(): GiveawayResults? = this as?
dev.inmo.tgbotapi.types.giveaway.GiveawayResults
public inline fun ChatEvent.giveawayResultsOrThrow(): GiveawayResults = this as
dev.inmo.tgbotapi.types.giveaway.GiveawayResults
public inline fun <T> ChatEvent.ifGiveawayResults(block: (GiveawayResults) -> T): T? =
giveawayResultsOrNull() ?.let(block)
public inline fun ChatEvent.channelChatCreatedOrNull(): ChannelChatCreated? = this as?
dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated
@ -3748,6 +3720,18 @@ public inline fun ResendableContent.gameContentOrThrow(): GameContent = this as
public inline fun <T> ResendableContent.ifGameContent(block: (GameContent) -> T): T? =
gameContentOrNull() ?.let(block)
public inline fun ResendableContent.giveawayPublicResultsContentOrNull():
GiveawayPublicResultsContent? = this as?
dev.inmo.tgbotapi.types.message.content.GiveawayPublicResultsContent
public inline fun ResendableContent.giveawayPublicResultsContentOrThrow():
GiveawayPublicResultsContent = this as
dev.inmo.tgbotapi.types.message.content.GiveawayPublicResultsContent
public inline fun <T>
ResendableContent.ifGiveawayPublicResultsContent(block: (GiveawayPublicResultsContent) -> T): T?
= giveawayPublicResultsContentOrNull() ?.let(block)
public inline fun ResendableContent.invoiceContentOrNull(): InvoiceContent? = this as?
dev.inmo.tgbotapi.types.message.content.InvoiceContent
@ -3815,6 +3799,16 @@ public inline fun ResendableContent.pollContentOrThrow(): PollContent = this as
public inline fun <T> ResendableContent.ifPollContent(block: (PollContent) -> T): T? =
pollContentOrNull() ?.let(block)
public inline fun ResendableContent.scheduledGiveawayContentOrNull(): ScheduledGiveawayContent? =
this as? dev.inmo.tgbotapi.types.message.content.ScheduledGiveawayContent
public inline fun ResendableContent.scheduledGiveawayContentOrThrow(): ScheduledGiveawayContent =
this as dev.inmo.tgbotapi.types.message.content.ScheduledGiveawayContent
public inline fun <T>
ResendableContent.ifScheduledGiveawayContent(block: (ScheduledGiveawayContent) -> T): T? =
scheduledGiveawayContentOrNull() ?.let(block)
public inline fun ResendableContent.stickerContentOrNull(): StickerContent? = this as?
dev.inmo.tgbotapi.types.message.content.StickerContent