mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2025-09-16 13:49:29 +00:00
fixes and improvements
This commit is contained in:
@@ -53,6 +53,10 @@ class DefaultAdminsCacheAPIRepoImpl(
|
||||
override suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>? = suspendCoroutine {
|
||||
actor.trySend(GetChatAdminsRepoAction(chatId, it))
|
||||
}
|
||||
|
||||
override suspend fun tryGetChatAdmins(chatId: ChatId): List<AdministratorChatMember>? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
override suspend fun setChatAdmins(chatId: ChatId, chatMembers: List<AdministratorChatMember>) = suspendCoroutine<Unit> {
|
||||
actor.trySend(SetChatAdminsRepoAction(chatId, chatMembers, it))
|
||||
}
|
||||
|
@@ -1,7 +1,5 @@
|
||||
package dev.inmo.tgbotapi.libraries.cache.admins
|
||||
|
||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.onetomany.ExposedKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.mappers.withMapper
|
||||
@@ -29,56 +27,9 @@ val telegramAdminsSerializationFormat = Json {
|
||||
}
|
||||
}
|
||||
|
||||
fun AdminsCacheAPI(
|
||||
bot: TelegramBot,
|
||||
database: Database,
|
||||
scope: CoroutineScope
|
||||
) : AdminsCacheAPI = DefaultAdminsCacheAPI(
|
||||
bot,
|
||||
DefaultAdminsCacheAPIRepoImpl(
|
||||
ExposedKeyValuesRepo(
|
||||
database,
|
||||
{ long("chatId") },
|
||||
{ text("member") },
|
||||
"AdminsTable"
|
||||
).withMapper<ChatId, AdministratorChatMember, Identifier, String>(
|
||||
keyFromToTo = { chatId },
|
||||
valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) },
|
||||
keyToToFrom = { toChatId() },
|
||||
valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(this) }
|
||||
),
|
||||
ExposedKeyValueRepo(
|
||||
database,
|
||||
{ long("chatId") },
|
||||
{ long("datetime") },
|
||||
"AdminsUpdatesTimesTable"
|
||||
).withMapper<ChatId, Long, Identifier, Long>(
|
||||
keyFromToTo = { chatId },
|
||||
valueFromToTo = { this },
|
||||
keyToToFrom = { toChatId() },
|
||||
valueToToFrom = { this }
|
||||
),
|
||||
scope
|
||||
),
|
||||
DynamicAdminsCacheSettingsAPI(
|
||||
ExposedKeyValueRepo(
|
||||
database,
|
||||
{ long("chatId") },
|
||||
{ text("settings") },
|
||||
"DynamicAdminsCacheSettingsAPI"
|
||||
).withMapper<ChatId, AdminsCacheSettings, Identifier, String>(
|
||||
keyFromToTo = { chatId },
|
||||
valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) },
|
||||
keyToToFrom = { toChatId() },
|
||||
valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(this) }
|
||||
),
|
||||
scope
|
||||
)
|
||||
)
|
||||
fun BehaviourContext.createAdminsCacheAPI(database: Database) = AdminsCacheAPI(this, database, this)
|
||||
|
||||
fun BehaviourContext.AdminsCacheAPI(database: Database) = AdminsCacheAPI(this, database, this)
|
||||
|
||||
fun BehaviourContext.AdminsCacheAPI(
|
||||
fun TelegramBot.createAdminsCacheAPI(
|
||||
database: Database,
|
||||
scope: CoroutineScope,
|
||||
defaultAdminsCacheAPIRepo: DefaultAdminsCacheAPIRepo = DefaultAdminsCacheAPIRepoImpl(
|
||||
@@ -121,3 +72,12 @@ fun BehaviourContext.AdminsCacheAPI(
|
||||
scope
|
||||
)
|
||||
) = DefaultAdminsCacheAPI(this, defaultAdminsCacheAPIRepo, adminsCacheSettingsAPI)
|
||||
|
||||
fun AdminsCacheAPI(
|
||||
bot: TelegramBot,
|
||||
database: Database,
|
||||
scope: CoroutineScope
|
||||
) : AdminsCacheAPI = bot.createAdminsCacheAPI(
|
||||
database,
|
||||
scope
|
||||
)
|
||||
|
Reference in New Issue
Block a user