mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
add MediaGroupUpdate
This commit is contained in:
parent
b1d732c99a
commit
f4e58375f2
@ -9,6 +9,8 @@
|
|||||||
* Added class `UpdatesFilter` which can help to filter updates by categories
|
* Added class `UpdatesFilter` which can help to filter updates by categories
|
||||||
* Added function `accumulateByKey` which work as debounce for keys and send list of received values
|
* Added function `accumulateByKey` which work as debounce for keys and send list of received values
|
||||||
* Added webhooks functions and workaround for `Reverse Proxy` mode
|
* Added webhooks functions and workaround for `Reverse Proxy` mode
|
||||||
|
* Added new type of updates `MediaGroupUpdate`, which can be received only from filters
|
||||||
|
* `UpdatesFilter` now use new type of updates for mediagroups
|
||||||
|
|
||||||
## 0.11.0
|
## 0.11.0
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.update
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||||
|
|
||||||
|
data class MediaGroupUpdate(
|
||||||
|
override val updateId: UpdateIdentifier,
|
||||||
|
override val data: MediaGroupMessage
|
||||||
|
) : BaseMessageUpdate
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdate
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||||
|
|
||||||
|
fun BaseMessageUpdate.toMediaGroupUpdate(): MediaGroupUpdate? = (data as? MediaGroupMessage) ?.let {
|
||||||
|
MediaGroupUpdate(updateId, it)
|
||||||
|
}
|
@ -99,13 +99,13 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
|
|
||||||
fun RequestsExecutor.startGettingOfUpdates(
|
fun RequestsExecutor.startGettingOfUpdates(
|
||||||
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
messageMediaGroupCallback: UpdateReceiver<List<MessageUpdate>>? = null,
|
messageMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||||
editedMessageMediaGroupCallback: UpdateReceiver<List<EditMessageUpdate>>? = null,
|
editedMessageMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
||||||
channelPostMediaGroupCallback: UpdateReceiver<List<ChannelPostUpdate>>? = null,
|
channelPostMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
||||||
editedChannelPostMediaGroupCallback: UpdateReceiver<List<EditChannelPostUpdate>>? = null,
|
editedChannelPostMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
||||||
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||||
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||||
|
@ -3,16 +3,17 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMediaGroupUpdate
|
||||||
|
|
||||||
data class UpdatesFilter(
|
data class UpdatesFilter(
|
||||||
private val messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
private val messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
private val messageMediaGroupCallback: UpdateReceiver<List<MessageUpdate>>? = null,
|
private val messageMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
private val editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
private val editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||||
private val editedMessageMediaGroupCallback: UpdateReceiver<List<EditMessageUpdate>>? = null,
|
private val editedMessageMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
private val channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
private val channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
||||||
private val channelPostMediaGroupCallback: UpdateReceiver<List<ChannelPostUpdate>>? = null,
|
private val channelPostMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
private val editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
private val editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
||||||
private val editedChannelPostMediaGroupCallback: UpdateReceiver<List<EditChannelPostUpdate>>? = null,
|
private val editedChannelPostMediaGroupCallback: UpdateReceiver<List<MediaGroupUpdate>>? = null,
|
||||||
private val chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
private val chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
||||||
private val inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
private val inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||||
private val callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
private val callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||||
@ -38,28 +39,28 @@ data class UpdatesFilter(
|
|||||||
is List<*> -> when (update.firstOrNull()) {
|
is List<*> -> when (update.firstOrNull()) {
|
||||||
is MessageUpdate -> update.mapNotNull { it as? MessageUpdate }.let { mappedList ->
|
is MessageUpdate -> update.mapNotNull { it as? MessageUpdate }.let { mappedList ->
|
||||||
messageMediaGroupCallback ?.also { receiver ->
|
messageMediaGroupCallback ?.also { receiver ->
|
||||||
receiver(mappedList)
|
receiver(mappedList.mapNotNull { it.toMediaGroupUpdate() })
|
||||||
} ?: messageCallback ?.also { receiver ->
|
} ?: messageCallback ?.also { receiver ->
|
||||||
mappedList.forEach { receiver(it) }
|
mappedList.forEach { receiver(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is EditMessageUpdate -> update.mapNotNull { it as? EditMessageUpdate }.let { mappedList ->
|
is EditMessageUpdate -> update.mapNotNull { it as? EditMessageUpdate }.let { mappedList ->
|
||||||
editedMessageMediaGroupCallback ?.also { receiver ->
|
editedMessageMediaGroupCallback ?.also { receiver ->
|
||||||
receiver(mappedList)
|
receiver(mappedList.mapNotNull { it.toMediaGroupUpdate() })
|
||||||
} ?: editedMessageCallback ?.also { receiver ->
|
} ?: editedMessageCallback ?.also { receiver ->
|
||||||
mappedList.forEach { receiver(it) }
|
mappedList.forEach { receiver(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ChannelPostUpdate -> update.mapNotNull { it as? ChannelPostUpdate }.let { mappedList ->
|
is ChannelPostUpdate -> update.mapNotNull { it as? ChannelPostUpdate }.let { mappedList ->
|
||||||
channelPostMediaGroupCallback ?.also { receiver ->
|
channelPostMediaGroupCallback ?.also { receiver ->
|
||||||
receiver(mappedList)
|
receiver(mappedList.mapNotNull { it.toMediaGroupUpdate() })
|
||||||
} ?: channelPostCallback ?.also { receiver ->
|
} ?: channelPostCallback ?.also { receiver ->
|
||||||
mappedList.forEach { receiver(it) }
|
mappedList.forEach { receiver(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is EditChannelPostUpdate -> update.mapNotNull { it as? EditChannelPostUpdate }.let { mappedList ->
|
is EditChannelPostUpdate -> update.mapNotNull { it as? EditChannelPostUpdate }.let { mappedList ->
|
||||||
editedChannelPostMediaGroupCallback ?.also { receiver ->
|
editedChannelPostMediaGroupCallback ?.also { receiver ->
|
||||||
receiver(mappedList)
|
receiver(mappedList.mapNotNull { it.toMediaGroupUpdate() })
|
||||||
} ?: editedChannelPostCallback ?.also { receiver ->
|
} ?: editedChannelPostCallback ?.also { receiver ->
|
||||||
mappedList.forEach { receiver(it) }
|
mappedList.forEach { receiver(it) }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user