mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
add a lot of shortcuts for events
This commit is contained in:
parent
b0219389fc
commit
1f40ce1a81
@ -20,7 +20,11 @@
|
|||||||
* `Flow<ChatEventMessage<*>>#onlyGroupEvents`
|
* `Flow<ChatEventMessage<*>>#onlyGroupEvents`
|
||||||
* `Flow<ChatEventMessage<*>>#onlySupergroupEvents`
|
* `Flow<ChatEventMessage<*>>#onlySupergroupEvents`
|
||||||
* A lot of extensions for `Flow<ChatEventMessage>` has been added:
|
* A lot of extensions for `Flow<ChatEventMessage>` has been added:
|
||||||
|
* `FlowsUpdatesFilter#events`
|
||||||
* `FlowsUpdatesFilter#channelEvents`
|
* `FlowsUpdatesFilter#channelEvents`
|
||||||
|
* `FlowsUpdatesFilter#groupEvents`
|
||||||
|
* `FlowsUpdatesFilter#supergroupEvents`
|
||||||
|
* And a lot of other filters with specific types
|
||||||
|
|
||||||
## 0.30.3
|
## 0.30.3
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.utils.chat_events
|
package dev.inmo.tgbotapi.extensions.utils.chat_events
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
||||||
import dev.inmo.tgbotapi.types.message.*
|
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent
|
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.mapNotNull
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
@ -19,9 +16,9 @@ fun <T : ChatEventMessage<*>> Flow<ChatEventMessage<*>>.divideBySource(contentTy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Replaced and renamed", ReplaceWith("allChannelEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.allChannelEvents"))
|
@Deprecated("Replaced and renamed", ReplaceWith("channelEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.channelEvents"))
|
||||||
fun Flow<ChatEventMessage<*>>.onlyChannelEvents() = allChannelEvents()
|
fun Flow<ChatEventMessage<*>>.onlyChannelEvents() = channelEvents()
|
||||||
@Deprecated("Replaced and renamed", ReplaceWith("allGroupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.allGroupEvents"))
|
@Deprecated("Replaced and renamed", ReplaceWith("groupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.groupEvents"))
|
||||||
fun Flow<ChatEventMessage<*>>.onlyGroupEvents() = allGroupEvents()
|
fun Flow<ChatEventMessage<*>>.onlyGroupEvents() = groupEvents()
|
||||||
@Deprecated("Replaced and renamed", ReplaceWith("allSupergroupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.allSupergroupEvents"))
|
@Deprecated("Replaced and renamed", ReplaceWith("supergroupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.supergroupEvents"))
|
||||||
fun Flow<ChatEventMessage<*>>.onlySupergroupEvents() = allSupergroupEvents()
|
fun Flow<ChatEventMessage<*>>.onlySupergroupEvents() = supergroupEvents()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
@file:Suppress("NOTHING_TO_INLINE", "unused")
|
@file:Suppress("NOTHING_TO_INLINE", "unused", "EXPERIMENTAL_API_USAGE")
|
||||||
|
|
||||||
package dev.inmo.tgbotapi.extensions.utils.shortcuts
|
package dev.inmo.tgbotapi.extensions.utils.shortcuts
|
||||||
|
|
||||||
@ -33,43 +33,66 @@ inline fun FlowsUpdatesFilter.supergroupEvents(): Flow<SupergroupEventMessage<*>
|
|||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun <reified T: ChatEvent, reified O: ChatEventMessage<T>> Flow<ChatEventMessage<*>>.filterByChatEvent(): Flow<O> = mapNotNull {
|
inline fun <reified T: ChatEvent, reified O: ChatEventMessage<T>> Flow<ChatEventMessage<*>>.filterByChatEvent(): Flow<O> = mapNotNull {
|
||||||
if (it.chatEvent is T) {
|
if (it.chatEvent is T) it as? O else null
|
||||||
it as? O
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun <reified T : ChannelEvent> Flow<ChatEventMessage<*>>.channelEvents() = filterByChatEvent<T, ChannelEventMessage<T>>()
|
inline fun <reified T : ChannelEvent> Flow<ChatEventMessage<*>>.filterChannelEvents() = filterByChatEvent<T, ChannelEventMessage<T>>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.channelCreatedEvents() = channelEvents<ChannelChatCreated>()
|
@RiskFeature("Use with caution")
|
||||||
inline fun Flow<ChatEventMessage<*>>.deletedChannelPhotoEvents() = channelEvents<DeleteChatPhoto>()
|
inline fun <reified T : ChannelEvent> FlowsUpdatesFilter.filterChannelEvents() = channelEvents().filterChannelEvents<T>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newChannelPhotoEvents() = channelEvents<NewChatPhoto>()
|
inline fun Flow<ChatEventMessage<*>>.channelCreatedEvents() = filterChannelEvents<ChannelChatCreated>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newChannelTitleEvents() = channelEvents<NewChatTitle>()
|
inline fun FlowsUpdatesFilter.channelCreatedEvents() = filterChannelEvents<ChannelChatCreated>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newChannelPinnedMessageEvents() = channelEvents<PinnedMessage>()
|
inline fun Flow<ChatEventMessage<*>>.deletedChannelPhotoEvents() = filterChannelEvents<DeleteChatPhoto>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.allChannelEvents() = channelEvents<ChannelEvent>()
|
inline fun FlowsUpdatesFilter.deletedChannelPhotoEvents() = filterChannelEvents<DeleteChatPhoto>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newChannelPhotoEvents() = filterChannelEvents<NewChatPhoto>()
|
||||||
|
inline fun FlowsUpdatesFilter.newChannelPhotoEvents() = filterChannelEvents<NewChatPhoto>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newChannelTitleEvents() = filterChannelEvents<NewChatTitle>()
|
||||||
|
inline fun FlowsUpdatesFilter.newChannelTitleEvents() = filterChannelEvents<NewChatTitle>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newChannelPinnedMessageEvents() = filterChannelEvents<PinnedMessage>()
|
||||||
|
inline fun FlowsUpdatesFilter.newChannelPinnedMessageEvents() = filterChannelEvents<PinnedMessage>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.channelEvents() = filterChannelEvents<ChannelEvent>()
|
||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun <reified T : GroupEvent> Flow<ChatEventMessage<*>>.groupEvents() = filterByChatEvent<T, GroupEventMessage<T>>()
|
inline fun <reified T : GroupEvent> Flow<ChatEventMessage<*>>.filterGroupEvents() = filterByChatEvent<T, GroupEventMessage<T>>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.groupCreatedEvents() = groupEvents<GroupChatCreated>()
|
@RiskFeature("Use with caution")
|
||||||
inline fun Flow<ChatEventMessage<*>>.deletedGroupPhotoEvents() = groupEvents<DeleteChatPhoto>()
|
inline fun <reified T : GroupEvent> FlowsUpdatesFilter.filterGroupEvents() = groupEvents().filterByChatEvent<T, GroupEventMessage<T>>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newGroupMembersEvents() = groupEvents<NewChatMembers>()
|
inline fun Flow<ChatEventMessage<*>>.groupCreatedEvents() = filterGroupEvents<GroupChatCreated>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.leftGroupMemberEvents() = groupEvents<LeftChatMember>()
|
inline fun FlowsUpdatesFilter.groupCreatedEvents() = filterGroupEvents<GroupChatCreated>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newGroupPhotoEvents() = groupEvents<NewChatPhoto>()
|
inline fun Flow<ChatEventMessage<*>>.deletedGroupPhotoEvents() = filterGroupEvents<DeleteChatPhoto>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newGroupTitleEvents() = groupEvents<NewChatTitle>()
|
inline fun FlowsUpdatesFilter.deletedGroupPhotoEvents() = filterGroupEvents<DeleteChatPhoto>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newGroupPinnedMessageEvents() = groupEvents<PinnedMessage>()
|
inline fun Flow<ChatEventMessage<*>>.newGroupMembersEvents() = filterGroupEvents<NewChatMembers>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInGroupEvents() = groupEvents<ProximityAlertTriggered>()
|
inline fun FlowsUpdatesFilter.newGroupMembersEvents() = filterGroupEvents<NewChatMembers>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.allGroupEvents() = groupEvents<GroupEvent>()
|
inline fun Flow<ChatEventMessage<*>>.leftGroupMemberEvents() = filterGroupEvents<LeftChatMember>()
|
||||||
|
inline fun FlowsUpdatesFilter.leftGroupMemberEvents() = filterGroupEvents<LeftChatMember>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newGroupPhotoEvents() = filterGroupEvents<NewChatPhoto>()
|
||||||
|
inline fun FlowsUpdatesFilter.newGroupPhotoEvents() = filterGroupEvents<NewChatPhoto>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newGroupTitleEvents() = filterGroupEvents<NewChatTitle>()
|
||||||
|
inline fun FlowsUpdatesFilter.newGroupTitleEvents() = filterGroupEvents<NewChatTitle>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newGroupPinnedMessageEvents() = filterGroupEvents<PinnedMessage>()
|
||||||
|
inline fun FlowsUpdatesFilter.newGroupPinnedMessageEvents() = filterGroupEvents<PinnedMessage>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInGroupEvents() = filterGroupEvents<ProximityAlertTriggered>()
|
||||||
|
inline fun FlowsUpdatesFilter.proximityAlertTriggeredInGroupEvents() = filterGroupEvents<ProximityAlertTriggered>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.groupEvents() = filterGroupEvents<GroupEvent>()
|
||||||
|
|
||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun <reified T : SupergroupEvent> Flow<ChatEventMessage<*>>.supergroupEvents() = filterByChatEvent<T, SupergroupEventMessage<T>>()
|
inline fun <reified T : SupergroupEvent> Flow<ChatEventMessage<*>>.filterSupergroupEvents() = filterByChatEvent<T, SupergroupEventMessage<T>>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.supergroupCreatedEvents() = supergroupEvents<SupergroupChatCreated>()
|
@RiskFeature("Use with caution")
|
||||||
inline fun Flow<ChatEventMessage<*>>.deletedSupergroupPhotoEvents() = supergroupEvents<DeleteChatPhoto>()
|
inline fun <reified T : SupergroupEvent> FlowsUpdatesFilter.filterSupergroupEvents() = supergroupEvents().filterByChatEvent<T, SupergroupEventMessage<T>>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newSupergroupMembersEvents() = supergroupEvents<NewChatMembers>()
|
inline fun Flow<ChatEventMessage<*>>.supergroupCreatedEvents() = filterSupergroupEvents<SupergroupChatCreated>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.leftSupergroupMemberEvents() = supergroupEvents<LeftChatMember>()
|
inline fun FlowsUpdatesFilter.supergroupCreatedEvents() = filterSupergroupEvents<SupergroupChatCreated>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newSupergroupPhotoEvents() = supergroupEvents<NewChatPhoto>()
|
inline fun Flow<ChatEventMessage<*>>.deletedSupergroupPhotoEvents() = filterSupergroupEvents<DeleteChatPhoto>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newSupergroupTitleEvents() = supergroupEvents<NewChatTitle>()
|
inline fun FlowsUpdatesFilter.deletedSupergroupPhotoEvents() = filterSupergroupEvents<DeleteChatPhoto>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.newSupergroupPinnedMessageEvents() = supergroupEvents<PinnedMessage>()
|
inline fun Flow<ChatEventMessage<*>>.newSupergroupMembersEvents() = filterSupergroupEvents<NewChatMembers>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInSupergroupEvents() = supergroupEvents<ProximityAlertTriggered>()
|
inline fun FlowsUpdatesFilter.newSupergroupMembersEvents() = filterSupergroupEvents<NewChatMembers>()
|
||||||
inline fun Flow<ChatEventMessage<*>>.allSupergroupEvents() = supergroupEvents<SupergroupEvent>()
|
inline fun Flow<ChatEventMessage<*>>.leftSupergroupMemberEvents() = filterSupergroupEvents<LeftChatMember>()
|
||||||
|
inline fun FlowsUpdatesFilter.leftSupergroupMemberEvents() = filterSupergroupEvents<LeftChatMember>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newSupergroupPhotoEvents() = filterSupergroupEvents<NewChatPhoto>()
|
||||||
|
inline fun FlowsUpdatesFilter.newSupergroupPhotoEvents() = filterSupergroupEvents<NewChatPhoto>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newSupergroupTitleEvents() = filterSupergroupEvents<NewChatTitle>()
|
||||||
|
inline fun FlowsUpdatesFilter.newSupergroupTitleEvents() = filterSupergroupEvents<NewChatTitle>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.newSupergroupPinnedMessageEvents() = filterSupergroupEvents<PinnedMessage>()
|
||||||
|
inline fun FlowsUpdatesFilter.newSupergroupPinnedMessageEvents() = filterSupergroupEvents<PinnedMessage>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents<ProximityAlertTriggered>()
|
||||||
|
inline fun FlowsUpdatesFilter.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents<ProximityAlertTriggered>()
|
||||||
|
inline fun Flow<ChatEventMessage<*>>.supergroupEvents() = filterSupergroupEvents<SupergroupEvent>()
|
||||||
|
Loading…
Reference in New Issue
Block a user