mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2025-09-16 05:41:24 +00:00
build fixes
This commit is contained in:
@@ -7,8 +7,8 @@ import dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
|
||||
interface AdminsCacheAPI {
|
||||
suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>?
|
||||
suspend fun isAdmin(chatId: ChatId, userId: UserId): Boolean = getChatAdmins(chatId) ?.any {
|
||||
suspend fun getChatAdmins(chatId: IdChatIdentifier): List<AdministratorChatMember>?
|
||||
suspend fun isAdmin(chatId: IdChatIdentifier, userId: UserId): Boolean = getChatAdmins(chatId) ?.any {
|
||||
it.user.id == userId
|
||||
} == true
|
||||
suspend fun sentByAdmin(groupContentMessage: GroupContentMessage<*>): Boolean
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package dev.inmo.tgbotapi.libraries.cache.admins
|
||||
|
||||
import com.soywiz.klock.minutes
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.Seconds
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -23,22 +23,22 @@ data class AdminsCacheSettings(
|
||||
}
|
||||
|
||||
interface AdminsCacheSettingsAPI {
|
||||
suspend fun getChatSettings(chatId: ChatId): AdminsCacheSettings?
|
||||
suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings?
|
||||
}
|
||||
|
||||
interface MutableAdminsCacheSettingsAPI : AdminsCacheSettingsAPI {
|
||||
val chatSettingsUpdatedFlow: SharedFlow<Pair<ChatId, AdminsCacheSettings>>
|
||||
val chatSettingsUpdatedFlow: SharedFlow<Pair<IdChatIdentifier, AdminsCacheSettings>>
|
||||
|
||||
suspend fun setChatSettings(chatId: ChatId, settings: AdminsCacheSettings)
|
||||
suspend fun setChatSettings(chatId: IdChatIdentifier, settings: AdminsCacheSettings)
|
||||
}
|
||||
|
||||
fun AdminsCacheSettingsAPI.asMutable(): MutableAdminsCacheSettingsAPI? = this as? MutableAdminsCacheSettingsAPI
|
||||
|
||||
@Serializable
|
||||
class StaticAdminsCacheSettingsAPI(
|
||||
private val settings: Map<ChatId, AdminsCacheSettings>
|
||||
private val settings: Map<IdChatIdentifier, AdminsCacheSettings>
|
||||
) : AdminsCacheSettingsAPI {
|
||||
override suspend fun getChatSettings(chatId: ChatId): AdminsCacheSettings? = settings[chatId]
|
||||
override suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings? = settings[chatId]
|
||||
}
|
||||
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMe
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatMemberUpdatedMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
@@ -35,7 +35,7 @@ suspend fun BehaviourContext.activateAdminsChangesListening(
|
||||
|
||||
suspend fun BehaviourContext.activateAdminsChangesListening(
|
||||
repo: DefaultAdminsCacheAPIRepo,
|
||||
allowedChats: List<ChatId>
|
||||
allowedChats: List<IdChatIdentifier>
|
||||
) = activateAdminsChangesListening(
|
||||
repo,
|
||||
{
|
||||
|
@@ -2,19 +2,19 @@ package dev.inmo.tgbotapi.libraries.cache.admins
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
|
||||
fun AdminsChecker(
|
||||
adminsCacheAPI: AdminsCacheAPI
|
||||
): SimpleFilter<Pair<ChatId, UserId>> = SimpleFilter {
|
||||
): SimpleFilter<Pair<IdChatIdentifier, UserId>> = SimpleFilter {
|
||||
adminsCacheAPI.isAdmin(it.first, it.second)
|
||||
}
|
||||
|
||||
fun <T> AdminsChecker(
|
||||
adminsCacheAPI: AdminsCacheAPI,
|
||||
mapper: (T) -> Pair<ChatId, UserId>
|
||||
mapper: (T) -> Pair<IdChatIdentifier, UserId>
|
||||
): SimpleFilter<T> {
|
||||
val baseChecker = AdminsChecker(adminsCacheAPI)
|
||||
|
||||
@@ -31,7 +31,7 @@ fun MessageAdminsChecker(
|
||||
|
||||
fun AdminsChecker(
|
||||
adminsCacheAPI: AdminsCacheAPI,
|
||||
chatId: ChatId
|
||||
chatId: IdChatIdentifier
|
||||
) = SimpleFilter<FromUser> {
|
||||
adminsCacheAPI.isAdmin(chatId, it.from.id)
|
||||
}
|
||||
|
@@ -11,9 +11,9 @@ import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
interface DefaultAdminsCacheAPIRepo {
|
||||
suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>?
|
||||
suspend fun setChatAdmins(chatId: ChatId, chatMembers: List<AdministratorChatMember>)
|
||||
suspend fun lastUpdate(chatId: ChatId): DateTime?
|
||||
suspend fun getChatAdmins(chatId: IdChatIdentifier): List<AdministratorChatMember>?
|
||||
suspend fun setChatAdmins(chatId: IdChatIdentifier, chatMembers: List<AdministratorChatMember>)
|
||||
suspend fun lastUpdate(chatId: IdChatIdentifier): DateTime?
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@@ -29,7 +29,7 @@ class DefaultAdminsCacheAPI(
|
||||
bot.getMe().also { botInfo = it }
|
||||
}
|
||||
|
||||
override suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>? {
|
||||
override suspend fun getChatAdmins(chatId: IdChatIdentifier): List<AdministratorChatMember>? {
|
||||
val settings = settingsAPI.getChatSettings(chatId)
|
||||
val lastUpdate = repo.lastUpdate(chatId)
|
||||
return when {
|
||||
@@ -42,7 +42,7 @@ class DefaultAdminsCacheAPI(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun isAdmin(chatId: ChatId, userId: UserId): Boolean {
|
||||
override suspend fun isAdmin(chatId: IdChatIdentifier, userId: UserId): Boolean {
|
||||
val settings = settingsAPI.getChatSettings(chatId)
|
||||
val lastUpdate = repo.lastUpdate(chatId)
|
||||
return when {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package dev.inmo.tgbotapi.libraries.cache.admins
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
|
||||
@@ -13,7 +13,7 @@ suspend inline fun AdminsCacheAPI.isAdmin(message: Message) = when (message) {
|
||||
suspend inline fun AdminsCacheAPI.verifyMessageFromAdmin(message: Message) = isAdmin(message)
|
||||
|
||||
suspend inline fun <R : Any> AdminsCacheAPI.doIfAdmin(
|
||||
chatId: ChatId,
|
||||
chatId: IdChatIdentifier,
|
||||
userId: UserId,
|
||||
block: () -> R
|
||||
) = if(isAdmin(chatId, userId)) {
|
||||
|
@@ -3,12 +3,12 @@ package dev.inmo.tgbotapi.libraries.cache.admins
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChatAdministrators
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.chat.ExtendedBot
|
||||
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
|
||||
|
||||
internal suspend fun TelegramBot.updateAdmins(
|
||||
chatId: ChatId,
|
||||
chatId: IdChatIdentifier,
|
||||
repo: DefaultAdminsCacheAPIRepo,
|
||||
botInfo: ExtendedBot? = null
|
||||
): List<AdministratorChatMember> {
|
||||
|
Reference in New Issue
Block a user