mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-15 21:03:48 +00:00
commit
bd2c13c178
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,5 +1,15 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
|
||||||
|
## 0.37.4
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `Version`:
|
||||||
|
* `MicroUtils`: `0.8.7` -> `0.8.9`
|
||||||
|
* `Core`:
|
||||||
|
* New `SupergroupEvent` subtype: `MigratedToSupergroup`. This event is sent when a group is converted to a supergroup while bot is in the group.
|
||||||
|
* Helper extenstion functions on `ChatEvent` to cast it to `MigratedToSupergroup`.
|
||||||
|
|
||||||
## 0.37.3 Hotfix of 0.37.2
|
## 0.37.3 Hotfix of 0.37.2
|
||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
|
@ -12,11 +12,11 @@ klock_version=2.4.8
|
|||||||
uuid_version=0.3.1
|
uuid_version=0.3.1
|
||||||
ktor_version=1.6.5
|
ktor_version=1.6.5
|
||||||
|
|
||||||
micro_utils_version=0.8.7
|
micro_utils_version=0.8.9
|
||||||
|
|
||||||
javax_activation_version=1.1.1
|
javax_activation_version=1.1.1
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=0.37.3
|
library_version=0.37.4
|
||||||
|
|
||||||
github_release_plugin_version=2.2.12
|
github_release_plugin_version=2.2.12
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
|
||||||
|
|
||||||
class GroupChatCreated(
|
class GroupChatCreated(
|
||||||
val migratedTo: ChatIdentifier?
|
val migratedTo: ChatId?
|
||||||
): GroupEvent
|
): GroupEvent
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is sent when a group is converted to a supergroup.
|
||||||
|
*/
|
||||||
|
data class MigratedToSupergroup(
|
||||||
|
val migratedFrom: ChatId
|
||||||
|
): SupergroupEvent
|
@ -1,8 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent
|
||||||
|
|
||||||
class SupergroupChatCreated(
|
class SupergroupChatCreated(
|
||||||
val migratedFrom: ChatIdentifier?
|
val migratedFrom: ChatId?
|
||||||
): SupergroupEvent
|
): SupergroupEvent
|
||||||
|
@ -75,8 +75,8 @@ internal data class RawMessage(
|
|||||||
private val group_chat_created: Boolean = false,
|
private val group_chat_created: Boolean = false,
|
||||||
private val supergroup_chat_created: Boolean = false,
|
private val supergroup_chat_created: Boolean = false,
|
||||||
private val channel_chat_created: Boolean = false,
|
private val channel_chat_created: Boolean = false,
|
||||||
private val migrate_to_chat_id: ChatIdentifier? = null,
|
private val migrate_to_chat_id: ChatId? = null,
|
||||||
private val migrate_from_chat_id: ChatIdentifier? = null,
|
private val migrate_from_chat_id: ChatId? = null,
|
||||||
private val pinned_message: RawMessage? = null,
|
private val pinned_message: RawMessage? = null,
|
||||||
private val invoice: Invoice? = null,
|
private val invoice: Invoice? = null,
|
||||||
private val dice: Dice? = null,
|
private val dice: Dice? = null,
|
||||||
@ -194,6 +194,9 @@ internal data class RawMessage(
|
|||||||
supergroup_chat_created -> SupergroupChatCreated(
|
supergroup_chat_created -> SupergroupChatCreated(
|
||||||
migrate_from_chat_id
|
migrate_from_chat_id
|
||||||
)
|
)
|
||||||
|
migrate_from_chat_id != null -> MigratedToSupergroup(
|
||||||
|
migrate_from_chat_id
|
||||||
|
)
|
||||||
channel_chat_created -> ChannelChatCreated()
|
channel_chat_created -> ChannelChatCreated()
|
||||||
pinned_message != null -> PinnedMessage(pinned_message.asMessage)
|
pinned_message != null -> PinnedMessage(pinned_message.asMessage)
|
||||||
proximity_alert_triggered != null -> proximity_alert_triggered
|
proximity_alert_triggered != null -> proximity_alert_triggered
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.TestsJsonFormat
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.asMigratedToSupergroup
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.asSupergroupChatCreated
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.asSupergroupEventMessage
|
||||||
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertIs
|
||||||
|
import kotlin.test.fail
|
||||||
|
|
||||||
|
|
||||||
|
class MigratedToSupergroupTest {
|
||||||
|
@Test
|
||||||
|
fun MigratedToSupergroupEventShouldBeParsed() {
|
||||||
|
val payload = """
|
||||||
|
{
|
||||||
|
"update_id": 42,
|
||||||
|
"message": {
|
||||||
|
"message_id": 1,
|
||||||
|
"from": {
|
||||||
|
"id": 1087968824,
|
||||||
|
"is_bot": true,
|
||||||
|
"first_name": "Group",
|
||||||
|
"username": "GroupAnonymousBot"
|
||||||
|
},
|
||||||
|
"sender_chat": {
|
||||||
|
"id": 42,
|
||||||
|
"title": "MigratedToSupergroupTest",
|
||||||
|
"type": "supergroup"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 42,
|
||||||
|
"title": "MigratedToSupergroupTest",
|
||||||
|
"type": "supergroup"
|
||||||
|
},
|
||||||
|
"date": 1639955462,
|
||||||
|
"migrate_from_chat_id": 57005
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
val update = TestsJsonFormat.decodeFromString(UpdateDeserializationStrategy, payload)
|
||||||
|
val message = update.asMessageUpdate() ?: fail("update should be of MessageUpdate subtype")
|
||||||
|
val data = message.data.asSupergroupEventMessage() ?: fail("message should be of SupergroupEventMessage subtype")
|
||||||
|
val event = data.chatEvent.asMigratedToSupergroup() ?: fail("event should be of SupergroupChatCreated subtype")
|
||||||
|
|
||||||
|
assertEquals(ChatId(57005), event.migratedFrom)
|
||||||
|
}
|
||||||
|
}
|
@ -3081,6 +3081,15 @@ inline fun ChatEvent.asSupergroupChatCreated(): SupergroupChatCreated? = this as
|
|||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun ChatEvent.requireSupergroupChatCreated(): SupergroupChatCreated = this as SupergroupChatCreated
|
inline fun ChatEvent.requireSupergroupChatCreated(): SupergroupChatCreated = this as SupergroupChatCreated
|
||||||
|
|
||||||
|
@PreviewFeature
|
||||||
|
inline fun <T> ChatEvent.whenMigratedToSupergroup(block: (MigratedToSupergroup) -> T) = asMigratedToSupergroup() ?.let(block)
|
||||||
|
|
||||||
|
@PreviewFeature
|
||||||
|
inline fun ChatEvent.asMigratedToSupergroup(): MigratedToSupergroup? = this as? MigratedToSupergroup
|
||||||
|
|
||||||
|
@PreviewFeature
|
||||||
|
inline fun ChatEvent.requireMigratedToSupergroup(): MigratedToSupergroup = this as MigratedToSupergroup
|
||||||
|
|
||||||
@PreviewFeature
|
@PreviewFeature
|
||||||
inline fun <T> ChatEvent.whenChannelEvent(block: (ChannelEvent) -> T) = asChannelEvent() ?.let(block)
|
inline fun <T> ChatEvent.whenChannelEvent(block: (ChannelEvent) -> T) = asChannelEvent() ?.let(block)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user