diff --git a/_pm.yml b/_pm.yml index c42f1a2..cf16e17 100644 --- a/_pm.yml +++ b/_pm.yml @@ -3,8 +3,4 @@ BOT_LANG: zh_CN B0T_OWNER: PM_MODE: private PM_WHITE_LIST: -LOG_LEVEL: INFO -BOT_LANG_LIST: - - en_US - - zh_CN - - zh_TW \ No newline at end of file +LOG_LEVEL: INFO \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/IdDefs.kt b/bot/src/main/java/io/nekohasekai/pm/IdDefs.kt index feb4c72..e4eb6cb 100644 --- a/bot/src/main/java/io/nekohasekai/pm/IdDefs.kt +++ b/bot/src/main/java/io/nekohasekai/pm/IdDefs.kt @@ -1,5 +1,8 @@ package io.nekohasekai.pm +import io.nekohasekai.ktlib.td.core.TdHandler +import io.nekohasekai.pm.instance.PmBot + const val PERSIST_BOT_CREATE = 0 const val PERSIST_SET_START_MESSAGES = 2 const val PERSIST_NEW_FUNCTION = 3 @@ -15,4 +18,11 @@ const val DATA_DELETE_BOT_MENU = 5L const val DATA_DELETE_MESSAGE = 6L const val DATA_EDIT_OPTIONS = 7L const val DATA_EDIT_COMMANDS = 8L -const val DATA_EDIT_COMMAND = 9L \ No newline at end of file +const val DATA_EDIT_COMMAND = 9L + +val TdHandler.launcher + get() = when (val sudo = sudo) { + is Launcher -> sudo + is PmBot -> sudo.launcher + else -> error("invalid handler") + } \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/Launcher.kt b/bot/src/main/java/io/nekohasekai/pm/Launcher.kt index f3e35da..db42e54 100644 --- a/bot/src/main/java/io/nekohasekai/pm/Launcher.kt +++ b/bot/src/main/java/io/nekohasekai/pm/Launcher.kt @@ -5,6 +5,7 @@ import cn.hutool.core.date.SystemClock import cn.hutool.core.io.FileUtil import io.nekohasekai.ktlib.compress.* import io.nekohasekai.ktlib.core.* +import io.nekohasekai.ktlib.db.IdTableCacheMap import io.nekohasekai.ktlib.td.cli.TdCli import io.nekohasekai.ktlib.td.core.extensions.* import io.nekohasekai.ktlib.td.core.i18n.* @@ -24,7 +25,9 @@ import java.util.* import kotlin.concurrent.schedule import kotlin.system.exitProcess -object Launcher : TdCli(), PmInstance { +class Launcher(val id: String = "TdPM") : TdCli(), PmInstance { + + val log = mkLog(id) var public = false lateinit var whiteList: IntArray @@ -48,24 +51,56 @@ object Launcher : TdCli(), PmInstance { lateinit var users: Array - override val integration get() = BotIntegration.Cache.fetch(me.id).value - override val settings get() = BotSetting.Cache.fetch(me.id).value - override val blocks by lazy { UserBlocks.Cache(me.id) } + val botIntegrations by lazy { IdTableCacheMap(database, BotIntegration) } + val botSettings by lazy { IdTableCacheMap(database, BotSetting) } + val actionMessages by lazy { IdTableCacheMap(database, ActionMessage) } + val startMessages by lazy { StartMessages.Cache(database) } + val botCommands by lazy { BotCommands.Cache(database) } + + override val integration get() = botIntegrations.fetch(me.id).value + override val settings get() = botSettings.fetch(me.id).value + override val blocks by lazy { UserBlocks.Cache(database, me.id) } + + val instanceMap = HashMap() + + fun initBot(userBot: UserBot): PmBot { + + return instanceMap[userBot.botId] ?: synchronized(instanceMap) { + + PmBot(userBot.botToken, userBot, this).apply { + + instanceMap[botUserId] = this + + start() + + } + + } + + } override var configFile = File("pm.yml") - @JvmStatic - fun main(args: Array) { + companion object { + + const val repoName = "TdPmBot" + const val repoUrl = "https://github.com/TdBotProject/TdPmBot" + const val licenseUrl = "https://github.com/TdBotProject/TdPmBot/blob/master/LICENSE" - launch(args) + @JvmStatic + fun main(args: Array) = with(Launcher()) { - loadConfig() + launch(args) - start() + loadConfig() - if (admin == 0L) { + start() - defaultLog.warn("Bot owner not specified, send /id to bot to get your userId.") + if (admin == 0L) { + + log.warn("Bot owner not specified, send /id to bot to get your userId.") + + } } @@ -95,7 +130,7 @@ object Launcher : TdCli(), PmInstance { runCatching { item.toInt() }.onFailure { - defaultLog.warn(">> Invalid white-list user-id item: $item", it) + log.warn(">> Invalid white-list user-id item: $item", it) }.getOrNull() @@ -111,7 +146,7 @@ object Launcher : TdCli(), PmInstance { else -> { - defaultLog.error(">> Invalid mode defined: $pmMode") + log.error(">> Invalid mode defined: $pmMode") exitProcess(100) @@ -136,7 +171,7 @@ object Launcher : TdCli(), PmInstance { } else if (!backupTo.name.endsWith(".tar.xz")) { - defaultLog.error(">> File name must ends with .tar.xz") + log.error(">> File name must ends with .tar.xz") exitProcess(100) @@ -178,7 +213,7 @@ object Launcher : TdCli(), PmInstance { output.close() - defaultLog.info(">> Saved to ${backupTo.path}") + log.info(">> Saved to ${backupTo.path}") exitProcess(0) @@ -190,7 +225,7 @@ object Launcher : TdCli(), PmInstance { super.onLoad() - defaultLog.debug("Init databases") + log.debug("Init databases") initDatabase("pm_data.db") @@ -276,7 +311,9 @@ object Launcher : TdCli(), PmInstance { database { - BotInstances.loadAll() + log.trace("Loading PM Bots") + + UserBot.all().forEach { initBot(it) } } @@ -290,18 +327,19 @@ object Launcher : TdCli(), PmInstance { override suspend fun gc() { - defaultLog.debug(">> 执行垃圾回收") + log.debug(">> 执行垃圾回收") - defaultLog.debug(">> 内存缓存") + log.debug(">> 内存缓存") super.gc() - BotIntegration.Cache.clear() - BotSetting.Cache.clear() - ActionMessage.Cache.clear() - StartMessages.Cache.clear() + botIntegrations.gc() + botSettings.gc() + actionMessages.gc() + startMessages.gc() + botCommands.gc() - defaultLog.debug(">> 清理数据库") + log.debug(">> 清理数据库") val time = (SystemClock.now() / 1000L).toInt() - 24 * 60 * 60 @@ -338,26 +376,22 @@ object Launcher : TdCli(), PmInstance { } - defaultLog.trace(">> ${me.displayNameFormatted}") + log.trace(">> ${me.displayNameFormatted}") gc(this) - BotInstances.instanceMap.forEach { + instanceMap.forEach { - defaultLog.trace(">> ${it.value.me.displayNameFormatted}") + log.trace(">> ${it.value.me.displayNameFormatted}") it.value.gc() } - defaultLog.debug("<< 执行垃圾回收") + log.debug("<< 执行垃圾回收") } - const val repoName = "TdPmBot" - const val repoUrl = "https://github.com/TdBotProject/TdPmBot" - const val licenseUrl = "https://github.com/TdBotProject/TdPmBot/blob/master/LICENSE" - override suspend fun userBlocked(userId: Int) = blocks.fetch(userId).value == true override suspend fun onUndefinedFunction(userId: Int, chatId: Long, message: TdApi.Message, function: String, param: String, params: Array, originParams: Array) { @@ -372,7 +406,7 @@ object Launcher : TdCli(), PmInstance { } - val command = BotCommands.Cache.fetch(me.id to function).value?.takeIf { !it.hide } + val command = botCommands.fetch(me.id to function).value?.takeIf { !it.hide } if (message.fromPrivate) { @@ -405,7 +439,7 @@ object Launcher : TdCli(), PmInstance { if (message.fromPrivate) { - val command = BotCommands.Cache.fetch(me.id to payload).value?.takeIf { !it.hide } ?: rejectFunction() + val command = botCommands.fetch(me.id to payload).value?.takeIf { !it.hide } ?: rejectFunction() command.messages.forEach { sudo make it syncTo chatId } @@ -421,7 +455,7 @@ object Launcher : TdCli(), PmInstance { val L = localeFor(userId) - val startMessages = StartMessages.Cache.fetch(me.id).value + val startMessages = startMessages.fetch(me.id).value if (!public && chatId != admin) { diff --git a/bot/src/main/java/io/nekohasekai/pm/database/ActionMessage.kt b/bot/src/main/java/io/nekohasekai/pm/database/ActionMessage.kt index e5fdf0f..5ef994d 100644 --- a/bot/src/main/java/io/nekohasekai/pm/database/ActionMessage.kt +++ b/bot/src/main/java/io/nekohasekai/pm/database/ActionMessage.kt @@ -1,7 +1,5 @@ package io.nekohasekai.pm.database -import io.nekohasekai.ktlib.db.IdTableCacheMap -import io.nekohasekai.pm.Launcher import org.jetbrains.exposed.dao.Entity import org.jetbrains.exposed.dao.EntityClass import org.jetbrains.exposed.dao.id.EntityID @@ -20,6 +18,4 @@ class ActionMessage(id: EntityID) : Entity(id) { companion object : EntityClass(ActionMessages) - object Cache : IdTableCacheMap(Launcher.database, ActionMessage) - } \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/database/BotCommands.kt b/bot/src/main/java/io/nekohasekai/pm/database/BotCommands.kt index 6ef07cb..e97ff37 100644 --- a/bot/src/main/java/io/nekohasekai/pm/database/BotCommands.kt +++ b/bot/src/main/java/io/nekohasekai/pm/database/BotCommands.kt @@ -1,8 +1,6 @@ package io.nekohasekai.pm.database -import io.nekohasekai.ktlib.db.DatabaseCacheMap -import io.nekohasekai.ktlib.db.kryo -import io.nekohasekai.pm.Launcher +import io.nekohasekai.ktlib.db.* import org.jetbrains.exposed.sql.* import td.TdApi import java.util.* @@ -18,7 +16,7 @@ object BotCommands : Table("bot_commands") { override val primaryKey = PrimaryKey(botId, command) - object Cache : DatabaseCacheMap, BotCommand>(Launcher.database) { + class Cache(database: DatabaseDispatcher) : DatabaseCacheMap, BotCommand>(database) { override fun read(id: Pair): BotCommand? { diff --git a/bot/src/main/java/io/nekohasekai/pm/database/BotIntegration.kt b/bot/src/main/java/io/nekohasekai/pm/database/BotIntegration.kt index 019a3a0..093ee3c 100644 --- a/bot/src/main/java/io/nekohasekai/pm/database/BotIntegration.kt +++ b/bot/src/main/java/io/nekohasekai/pm/database/BotIntegration.kt @@ -1,7 +1,5 @@ package io.nekohasekai.pm.database -import io.nekohasekai.ktlib.db.IdTableCacheMap -import io.nekohasekai.pm.Launcher import org.jetbrains.exposed.dao.Entity import org.jetbrains.exposed.dao.EntityClass import org.jetbrains.exposed.dao.id.EntityID @@ -21,6 +19,5 @@ class BotIntegration(id: EntityID) : Entity(id) { companion object : EntityClass(BotIntegrations) - object Cache : IdTableCacheMap(Launcher.database, this) } \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/database/BotSetting.kt b/bot/src/main/java/io/nekohasekai/pm/database/BotSetting.kt index 1edbce5..649d262 100644 --- a/bot/src/main/java/io/nekohasekai/pm/database/BotSetting.kt +++ b/bot/src/main/java/io/nekohasekai/pm/database/BotSetting.kt @@ -1,7 +1,5 @@ package io.nekohasekai.pm.database -import io.nekohasekai.ktlib.db.IdTableCacheMap -import io.nekohasekai.pm.Launcher import org.jetbrains.exposed.dao.Entity import org.jetbrains.exposed.dao.EntityClass import org.jetbrains.exposed.dao.id.EntityID @@ -22,6 +20,4 @@ class BotSetting(id: EntityID) : Entity(id) { companion object : EntityClass(BotSettings) - object Cache : IdTableCacheMap(Launcher.database, this) - } \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/database/PmInstance.kt b/bot/src/main/java/io/nekohasekai/pm/database/PmInstance.kt index cdecb9b..196b124 100644 --- a/bot/src/main/java/io/nekohasekai/pm/database/PmInstance.kt +++ b/bot/src/main/java/io/nekohasekai/pm/database/PmInstance.kt @@ -11,8 +11,8 @@ import io.nekohasekai.ktlib.td.core.i18n.LocaleController import io.nekohasekai.ktlib.td.core.i18n.localeFor import io.nekohasekai.ktlib.td.core.raw.getChat import io.nekohasekai.ktlib.td.core.raw.getMessageOrNull -import io.nekohasekai.pm.Launcher import io.nekohasekai.pm.instance.messagesForCurrentBot +import io.nekohasekai.pm.launcher import org.jetbrains.exposed.sql.* interface PmInstance { @@ -24,7 +24,7 @@ interface PmInstance { } -val PmInstance.L by receive { Launcher.localeFor(admin) } +val PmInstance.L by receive { (this as TdHandler).launcher.localeFor(admin) } fun TdHandler.saveMessage(type: Int, chatId: Long, messageId: Long, targetId: Long? = null) { @@ -52,6 +52,8 @@ fun TdHandler.saveMessage(type: Int, chatId: Long, messageId: Long, targetId: Lo suspend fun TdHandler.gc(instance: PmInstance) { + instance.blocks.gc() + var deleted = 0 val integration = instance.integration diff --git a/bot/src/main/java/io/nekohasekai/pm/database/StartMessages.kt b/bot/src/main/java/io/nekohasekai/pm/database/StartMessages.kt index fe8d108..85b8666 100644 --- a/bot/src/main/java/io/nekohasekai/pm/database/StartMessages.kt +++ b/bot/src/main/java/io/nekohasekai/pm/database/StartMessages.kt @@ -1,12 +1,7 @@ package io.nekohasekai.pm.database -import io.nekohasekai.ktlib.db.DatabaseCacheMap -import io.nekohasekai.ktlib.db.kryo -import io.nekohasekai.ktlib.db.upsert -import io.nekohasekai.pm.Launcher -import org.jetbrains.exposed.sql.Table -import org.jetbrains.exposed.sql.deleteWhere -import org.jetbrains.exposed.sql.select +import io.nekohasekai.ktlib.db.* +import org.jetbrains.exposed.sql.* import td.TdApi import java.util.* @@ -16,7 +11,7 @@ object StartMessages : Table("pm_start_messages") { val messages = kryo>("messages") - object Cache : DatabaseCacheMap>(Launcher.database) { + class Cache(database: DatabaseDispatcher) : DatabaseCacheMap>(database) { override fun read(id: Int): LinkedList? { diff --git a/bot/src/main/java/io/nekohasekai/pm/database/UserBlocks.kt b/bot/src/main/java/io/nekohasekai/pm/database/UserBlocks.kt index 18a9830..b264607 100644 --- a/bot/src/main/java/io/nekohasekai/pm/database/UserBlocks.kt +++ b/bot/src/main/java/io/nekohasekai/pm/database/UserBlocks.kt @@ -1,7 +1,7 @@ package io.nekohasekai.pm.database import io.nekohasekai.ktlib.db.DatabaseCacheMap -import io.nekohasekai.pm.Launcher +import io.nekohasekai.ktlib.db.DatabaseDispatcher import org.jetbrains.exposed.sql.* object UserBlocks : Table("pm_blocks") { @@ -11,7 +11,7 @@ object UserBlocks : Table("pm_blocks") { override val primaryKey = PrimaryKey(botId, blockedUser) - class Cache(val botUserId: Int) : DatabaseCacheMap(Launcher.database) { + class Cache(database: DatabaseDispatcher, val botUserId: Int) : DatabaseCacheMap(database) { override fun read(id: Int): Boolean { @@ -43,6 +43,7 @@ object UserBlocks : Table("pm_blocks") { UserBlocks.deleteWhere { (botId eq botUserId) and (blockedUser eq id) } } + } } \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/AbstractUserInputHandler.kt b/bot/src/main/java/io/nekohasekai/pm/instance/AbstractInputUserFunction.kt similarity index 97% rename from bot/src/main/java/io/nekohasekai/pm/instance/AbstractUserInputHandler.kt rename to bot/src/main/java/io/nekohasekai/pm/instance/AbstractInputUserFunction.kt index 16c2438..2e5d8f0 100644 --- a/bot/src/main/java/io/nekohasekai/pm/instance/AbstractUserInputHandler.kt +++ b/bot/src/main/java/io/nekohasekai/pm/instance/AbstractInputUserFunction.kt @@ -15,7 +15,7 @@ import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.select import td.TdApi -abstract class AbstractUserInputHandler : TdHandler() { +abstract class AbstractInputUserFunction : TdHandler() { override suspend fun onFunction(userId: Int, chatId: Long, message: TdApi.Message, function: String, param: String, params: Array, originParams: Array) { diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/BlockHandler.kt b/bot/src/main/java/io/nekohasekai/pm/instance/BlockHandler.kt index 7464438..adda7f7 100644 --- a/bot/src/main/java/io/nekohasekai/pm/instance/BlockHandler.kt +++ b/bot/src/main/java/io/nekohasekai/pm/instance/BlockHandler.kt @@ -11,7 +11,7 @@ import io.nekohasekai.pm.* import io.nekohasekai.pm.database.* import td.TdApi -class BlockHandler(pmInstance: PmInstance) : AbstractUserInputHandler(), PmInstance by pmInstance { +class BlockHandler(pmInstance: PmInstance) : AbstractInputUserFunction(), PmInstance by pmInstance { override fun onLoad() { diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/BotInstances.kt b/bot/src/main/java/io/nekohasekai/pm/instance/BotInstances.kt deleted file mode 100644 index e60cf37..0000000 --- a/bot/src/main/java/io/nekohasekai/pm/instance/BotInstances.kt +++ /dev/null @@ -1,34 +0,0 @@ -package io.nekohasekai.pm.instance - -import io.nekohasekai.ktlib.core.defaultLog -import io.nekohasekai.pm.database.UserBot - -object BotInstances { - - val instanceMap = HashMap() - - fun loadAll() { - - defaultLog.trace("Loading PM Bots") - - UserBot.all().forEach { initBot(it) } - - } - - fun initBot(userBot: UserBot): PmBot { - - return instanceMap[userBot.botId] ?: synchronized(instanceMap) { - - PmBot(userBot.botToken, userBot).apply { - - instanceMap[botUserId] = this - - start() - - } - - } - - } - -} \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/Filters.kt b/bot/src/main/java/io/nekohasekai/pm/instance/Filters.kt index d0d7e4c..1290ee0 100644 --- a/bot/src/main/java/io/nekohasekai/pm/instance/Filters.kt +++ b/bot/src/main/java/io/nekohasekai/pm/instance/Filters.kt @@ -7,3 +7,4 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq val TdHandler.messagesForCurrentBot get() = (MessageRecords.botId eq me.id) val TdHandler.commandsForCurrentBot get() = (BotCommands.botId eq me.id) +val TdHandler.userBot get() = (sudo as? PmBot)?.userBot \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/InputHandler.kt b/bot/src/main/java/io/nekohasekai/pm/instance/InputHandler.kt index ed57fe8..67621e5 100644 --- a/bot/src/main/java/io/nekohasekai/pm/instance/InputHandler.kt +++ b/bot/src/main/java/io/nekohasekai/pm/instance/InputHandler.kt @@ -101,7 +101,7 @@ class InputHandler(pmInstance: PmInstance) : TdHandler(), PmInstance by pmInstan }.also { - TdClient.timer.schedule(it, 1000L) + TdClient.timer.schedule(it, 300L) } @@ -130,18 +130,9 @@ class InputHandler(pmInstance: PmInstance) : TdHandler(), PmInstance by pmInstan } - val botUserId = me.id - val userBot = (Launcher.sudo as? PmBot)?.userBot - - val owner = admin - - Launcher.apply { - - sudo make L.INTEGRATION_PAUSED_NOTICE.input(me.displayName, me.username) syncTo admin - - findHandler().integrationMenu(L, botUserId, userBot, owner.toInt(), owner, 0L, false) - - } + launcher.getChatOrNull(admin) ?: return null + launcher make L.INTEGRATION_PAUSED_NOTICE.input(me.displayName, me.username) syncTo admin + launcher.findHandler().integrationMenu(L, me.id, userBot, admin.toInt(), admin, 0L, false) } @@ -278,12 +269,9 @@ class InputHandler(pmInstance: PmInstance) : TdHandler(), PmInstance by pmInstan } - Launcher make L.INTEGRATION_PAUSED_NOTICE.input( - me.displayName, - me.username - ) syncTo admin - - Launcher.findHandler().integrationMenu(L, me.id, null, admin.toInt(), admin, 0L, false) + launcher.getChatOrNull(admin) ?: return + launcher make L.INTEGRATION_PAUSED_NOTICE.input(me.displayName, me.username) syncTo admin + launcher.findHandler().integrationMenu(L, me.id, userBot, admin.toInt(), admin, 0L, false) } diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/JoinHandler.kt b/bot/src/main/java/io/nekohasekai/pm/instance/JoinHandler.kt index f2a925a..ad7d065 100644 --- a/bot/src/main/java/io/nekohasekai/pm/instance/JoinHandler.kt +++ b/bot/src/main/java/io/nekohasekai/pm/instance/JoinHandler.kt @@ -13,7 +13,7 @@ import io.nekohasekai.pm.database.L import io.nekohasekai.pm.database.PmInstance import td.TdApi -class JoinHandler(pmInstance: PmInstance) : AbstractUserInputHandler(), PmInstance by pmInstance { +class JoinHandler(pmInstance: PmInstance) : AbstractInputUserFunction(), PmInstance by pmInstance { override fun onLoad() { diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/PmBot.kt b/bot/src/main/java/io/nekohasekai/pm/instance/PmBot.kt index fbd45f8..0f18c8a 100644 --- a/bot/src/main/java/io/nekohasekai/pm/instance/PmBot.kt +++ b/bot/src/main/java/io/nekohasekai/pm/instance/PmBot.kt @@ -17,22 +17,22 @@ import io.nekohasekai.pm.manage.menu.* import org.jetbrains.exposed.sql.* import td.TdApi -class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstance { +class PmBot(botToken: String, val userBot: UserBot, val launcher: Launcher) : TdBot(botToken), PmInstance { - override val database = Launcher.database + override val database = launcher.database override val admin get() = userBot.owner.toLong() - override val integration get() = BotIntegration.Cache.fetch(botUserId).value - override val settings get() = BotSetting.Cache.fetch(botUserId).value + override val integration get() = launcher.botIntegrations.fetch(botUserId).value + override val settings get() = launcher.botSettings.fetch(botUserId).value - override val blocks by lazy { UserBlocks.Cache(botUserId) } + override val blocks by lazy { UserBlocks.Cache(database, botUserId) } override suspend fun onAuthorizationState(authorizationState: TdApi.AuthorizationState) { if (auth && authorizationState is TdApi.AuthorizationStateClosed) { - defaultLog.info("${me.displayName} (@${me.username}): PmBot Closed") + defaultLog.debug("${me.displayName} (@${me.username}): PmBot Closed") } @@ -53,7 +53,7 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc override suspend fun onLogin() { - defaultLog.info("${me.displayName} (@${me.username}): PmBot Loaded") + defaultLog.debug("${me.displayName} (@${me.username}): PmBot Loaded") updateCommands() @@ -97,7 +97,7 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc } - BotInstances.instanceMap.remove(botUserId) + launcher.instanceMap.remove(botUserId) } @@ -106,8 +106,9 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc destroy() val owner = admin + val userBot = userBot - Launcher.apply { + launcher.apply { getChatOrNull(owner) ?: return @@ -122,8 +123,9 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc destroy() val owner = admin + val userBot = userBot - Launcher.apply { + launcher.apply { getChatOrNull(owner) ?: return @@ -171,7 +173,7 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc } - val command = BotCommands.Cache.fetch(me.id to function).value?.takeIf { !it.hide } + val command = launcher.botCommands.fetch(me.id to function).value?.takeIf { !it.hide } if (!message.fromPrivate) { @@ -197,7 +199,7 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc if (message.fromPrivate) { - val command = BotCommands.Cache.fetch(me.id to payload).value?.takeIf { !it.hide } ?: rejectFunction() + val command = launcher.botCommands.fetch(me.id to payload).value?.takeIf { !it.hide } ?: rejectFunction() command.messages.forEach { sudo make it syncTo chatId } @@ -211,15 +213,15 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc if (!message.fromPrivate) return - val startMessages = StartMessages.Cache.fetch(botUserId).value + val startMessages = launcher.startMessages.fetch(botUserId).value if (startMessages == null) { var content = L.DEFAULT_WELCOME - if (Launcher.public) { + if (launcher.public) { - content += "\n\n" + L.POWERED_BY.input(Launcher.me.username, L.LICENSE.input(Launcher.repoName, Launcher.licenseUrl, "Github Repo".htmlLink(Launcher.repoUrl))) + content += "\n\n" + L.POWERED_BY.input(launcher.me.username, L.LICENSE.input(Launcher.repoName, Launcher.licenseUrl, "Github Repo".htmlLink(Launcher.repoUrl))) } @@ -249,13 +251,7 @@ class PmBot(botToken: String, val userBot: UserBot) : TdBot(botToken), PmInstanc if (chatId != admin) rejectFunction() - val botUserId = me.id - - Launcher.apply { - - findHandler().botMenu(userId, chatId, 0L, false, botUserId, userBot) - - } + launcher.findHandler().botMenu(userId, chatId, 0L, false, me.id, userBot) sudo make L.CREATE_FINISHED sendTo chatId diff --git a/bot/src/main/java/io/nekohasekai/pm/instance/RecallHandler.kt b/bot/src/main/java/io/nekohasekai/pm/instance/RecallHandler.kt index fc7017e..8880ea9 100644 --- a/bot/src/main/java/io/nekohasekai/pm/instance/RecallHandler.kt +++ b/bot/src/main/java/io/nekohasekai/pm/instance/RecallHandler.kt @@ -11,7 +11,7 @@ import io.nekohasekai.pm.database.* import org.jetbrains.exposed.sql.* import td.TdApi -class RecallHandler(pmInstance: PmInstance) : AbstractUserInputHandler(), PmInstance by pmInstance { +class RecallHandler(pmInstance: PmInstance) : AbstractInputUserFunction(), PmInstance by pmInstance { override fun onLoad() { diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/AdminCommands.kt b/bot/src/main/java/io/nekohasekai/pm/manage/AdminCommands.kt index d9c03a6..f7c4c4c 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/AdminCommands.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/AdminCommands.kt @@ -2,7 +2,7 @@ package io.nekohasekai.pm.manage import io.nekohasekai.ktlib.td.core.TdHandler import io.nekohasekai.ktlib.td.core.utils.make -import io.nekohasekai.pm.Launcher +import io.nekohasekai.pm.launcher import td.TdApi class AdminCommands : TdHandler() { @@ -21,13 +21,13 @@ class AdminCommands : TdHandler() { override suspend fun onFunction(userId: Int, chatId: Long, message: TdApi.Message, function: String, param: String, params: Array, originParams: Array) { - if (userId != Launcher.admin.toInt()) rejectFunction() + if (userId != launcher.admin.toInt()) rejectFunction() if (function == COMMAND_GC) { val status = sudo make "GC Executing..." syncTo chatId - Launcher.gc() + launcher.gc() sudo make "GC Finished" editTo status diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/BotHandler.kt b/bot/src/main/java/io/nekohasekai/pm/manage/BotHandler.kt index 10546c8..e30e910 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/BotHandler.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/BotHandler.kt @@ -5,9 +5,8 @@ import io.nekohasekai.ktlib.core.shift import io.nekohasekai.ktlib.td.core.TdHandler import io.nekohasekai.ktlib.td.core.extensions.displayName import io.nekohasekai.ktlib.td.core.extensions.toInt -import io.nekohasekai.pm.Launcher import io.nekohasekai.pm.database.UserBot -import io.nekohasekai.pm.instance.BotInstances +import io.nekohasekai.pm.launcher abstract class BotHandler : TdHandler() { @@ -21,7 +20,7 @@ abstract class BotHandler : TdHandler() { return if (botUserId == me.id) me else { - BotInstances.initBot(userBot!!).me + launcher.initBot(userBot!!).me }.displayName @@ -31,7 +30,7 @@ abstract class BotHandler : TdHandler() { return if (botUserId == me.id) me else { - BotInstances.initBot(userBot!!).me + launcher.initBot(userBot!!).me }.displayName.escapeHtmlTags() @@ -41,7 +40,7 @@ abstract class BotHandler : TdHandler() { val botId = data[0].toInt() - val userBot = if (botId == me.id && chatId == Launcher.admin) { + val userBot = if (botId == me.id && chatId == launcher.admin) { null diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/CreateBot.kt b/bot/src/main/java/io/nekohasekai/pm/manage/CreateBot.kt index af9ef4a..043604b 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/CreateBot.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/CreateBot.kt @@ -10,7 +10,6 @@ import io.nekohasekai.ktlib.td.core.utils.* import io.nekohasekai.ktlib.td.http.httpSync import io.nekohasekai.pm.* import io.nekohasekai.pm.database.UserBot -import io.nekohasekai.pm.instance.BotInstances import td.TdApi class CreateBot : TdHandler() { @@ -44,11 +43,11 @@ class CreateBot : TdHandler() { } - if (chatId != Launcher.admin) { + if (chatId != launcher.admin) { - if (!Launcher.public) rejectFunction() + if (!launcher.public) rejectFunction() - if (!Launcher.userAccessible(userId)) { + if (!launcher.userAccessible(userId)) { sudo makeMd localeFor(userId).PRIVATE_INSTANCE.input(Launcher.repoUrl) syncTo chatId @@ -158,7 +157,7 @@ class CreateBot : TdHandler() { } - if (BotInstances.initBot(userBot).waitForAuth()) { + if (launcher.initBot(userBot).waitForAuth()) { sudo makeHtml L.FINISH_CREATION.input(userBot.username) editTo status @@ -168,7 +167,6 @@ class CreateBot : TdHandler() { } - } } \ No newline at end of file diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/MyBots.kt b/bot/src/main/java/io/nekohasekai/pm/manage/MyBots.kt index e75e3ce..17b4b95 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/MyBots.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/MyBots.kt @@ -53,7 +53,7 @@ class MyBots : TdHandler() { suspend fun deleteActionMessage(userId: Int, chatId: Long, messageId: Long) { - val currentActionMessage = ActionMessage.Cache.fetch(userId) + val currentActionMessage = launcher.actionMessages.fetch(userId) val currentActionMessageId = currentActionMessage.value?.messageId @@ -73,7 +73,7 @@ class MyBots : TdHandler() { fun saveActionMessage(userId: Int, messageId: Long) { - val currentActionMessage = ActionMessage.Cache.fetch(userId) + val currentActionMessage = launcher.actionMessages.fetch(userId) currentActionMessage.apply { @@ -111,7 +111,7 @@ class MyBots : TdHandler() { val bots = LinkedHashMap() - if (chatId == Launcher.admin) { + if (chatId == launcher.admin) { bots[me.username] = me.id diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandMenu.kt b/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandMenu.kt index dd85075..544da40 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandMenu.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandMenu.kt @@ -9,8 +9,8 @@ import io.nekohasekai.ktlib.td.core.raw.editMessageReplyMarkup import io.nekohasekai.ktlib.td.core.raw.editMessageReplyMarkupOrNull import io.nekohasekai.ktlib.td.core.utils.* import io.nekohasekai.pm.* -import io.nekohasekai.pm.database.* -import io.nekohasekai.pm.instance.BotInstances +import io.nekohasekai.pm.database.BotCommand +import io.nekohasekai.pm.database.UserBot import io.nekohasekai.pm.instance.PmBot import io.nekohasekai.pm.manage.BotHandler import io.nekohasekai.pm.manage.MyBots @@ -61,7 +61,7 @@ class CommandMenu : BotHandler() { } - if (userBot == null && Launcher.public) { + if (userBot == null && launcher.public) { newLine { @@ -97,7 +97,7 @@ class CommandMenu : BotHandler() { if (command.messages.isEmpty()) L.EMPTY else L.MESSAGES_STATUS_COUNT.input(command.messages.size), botUserName(botUserId, userBot), command.command, - if (userBot == null && Launcher.public) L.COMMAND_INPUT_WHEN_PUBLIC_DEF else "" + if (userBot == null && launcher.public) L.COMMAND_INPUT_WHEN_PUBLIC_DEF else "" ) withMarkup commandButtons(L, botUserId, userBot, command) onSuccess { if (!isEdit) findHandler().saveActionMessage(userId, it.id) @@ -162,7 +162,7 @@ class CommandMenu : BotHandler() { override suspend fun onNewBotCallbackQuery(userId: Int, chatId: Long, messageId: Long, queryId: Long, data: Array, botUserId: Int, userBot: UserBot?) { - val command = BotCommands.Cache.fetch(botUserId to data[0].decodeToString()).value ?: return + val command = launcher.botCommands.fetch(botUserId to data[0].decodeToString()).value ?: return if (data.size < 2) { @@ -218,7 +218,7 @@ class CommandMenu : BotHandler() { 2 -> { - val self = if (userBot != null) BotInstances.initBot(userBot) else this + val self = if (userBot != null) launcher.initBot(userBot) else this self.writePersist(userId, persistId, 1L, EditMessagesCache(botUserId, userBot, messageId, command), allowFunction = true) @@ -248,7 +248,7 @@ class CommandMenu : BotHandler() { val target: Boolean - BotCommands.Cache.fetch(botUserId to command.command).apply { + launcher.botCommands.fetch(botUserId to command.command).apply { val currVal = value @@ -294,13 +294,13 @@ class CommandMenu : BotHandler() { editMessageReplyMarkup(chatId, messageId, commandButtons(L, botUserId, userBot, command)) - if (userBot != null) BotInstances.initBot(userBot).updateCommands() else (sudo as Launcher).updateCommands() + if (userBot != null) launcher.initBot(userBot).updateCommands() else (sudo as Launcher).updateCommands() } 5 -> { - BotCommands.Cache.fetch(botUserId to command.command).apply { + launcher.botCommands.fetch(botUserId to command.command).apply { if (value != null) { @@ -317,7 +317,7 @@ class CommandMenu : BotHandler() { findHandler().commandsMenu(botUserId, userBot, userId, chatId, messageId, true) - if (userBot != null) BotInstances.initBot(userBot).updateCommands() else (sudo as Launcher).updateCommands() + if (userBot != null) launcher.initBot(userBot).updateCommands() else (sudo as Launcher).updateCommands() } @@ -388,7 +388,7 @@ class CommandMenu : BotHandler() { if (!cache.description) { - BotCommands.Cache.fetch(cache.botUserId to cache.command.command).apply { + launcher.botCommands.fetch(cache.botUserId to cache.command.command).apply { value = null changed = true @@ -399,7 +399,7 @@ class CommandMenu : BotHandler() { cache.command.command = text - BotCommands.Cache.fetch(cache.botUserId to cache.command.command).apply { + launcher.botCommands.fetch(cache.botUserId to cache.command.command).apply { value = cache.command changed = true @@ -412,7 +412,7 @@ class CommandMenu : BotHandler() { cache.command.description = text - BotCommands.Cache.fetch(cache.botUserId to cache.command.command).apply { + launcher.botCommands.fetch(cache.botUserId to cache.command.command).apply { value = cache.command changed = true @@ -437,7 +437,7 @@ class CommandMenu : BotHandler() { if (!cache.edited) { - Launcher.editMessageReplyMarkupOrNull(chatId, cache.startsAt, null) + launcher.editMessageReplyMarkupOrNull(chatId, cache.startsAt, null) cache.edited = true @@ -507,7 +507,7 @@ class CommandMenu : BotHandler() { val botUserId = cache.botUserId - if (chatId != Launcher.admin && database { UserBot.findById(botUserId)?.owner != userId }) { + if (chatId != launcher.admin && database { UserBot.findById(botUserId)?.owner != userId }) { // 权限检查 @@ -521,7 +521,7 @@ class CommandMenu : BotHandler() { userCalled(userId, "submitted messages to function /${cache.command} for $botUserId") - BotCommands.Cache.fetch(cache.botUserId to cache.command.command).apply { + launcher.botCommands.fetch(cache.botUserId to cache.command.command).apply { value = cache.command changed = true @@ -535,7 +535,7 @@ class CommandMenu : BotHandler() { (sudo as? Launcher)?.updateCommands() (sudo as? PmBot)?.updateCommands() - (if (cache.userBot != null) Launcher.findHandler() else this) + (if (cache.userBot != null) launcher.findHandler() else this) .commandMenu(cache.botUserId, cache.userBot, cache.command, userId, chatId, 0L, false) diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandsMenu.kt b/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandsMenu.kt index d43b06d..75e0f70 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandsMenu.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/menu/CommandsMenu.kt @@ -9,7 +9,6 @@ import io.nekohasekai.ktlib.td.core.raw.editMessageReplyMarkupOrNull import io.nekohasekai.ktlib.td.core.utils.* import io.nekohasekai.pm.* import io.nekohasekai.pm.database.* -import io.nekohasekai.pm.instance.BotInstances import io.nekohasekai.pm.instance.PmBot import io.nekohasekai.pm.manage.BotHandler import io.nekohasekai.pm.manage.MyBots @@ -177,7 +176,7 @@ class CommandsMenu : BotHandler() { val botUserId = cache.botId - if (chatId != Launcher.admin && database { UserBot.findById(botUserId)?.owner != userId }) { + if (chatId != launcher.admin && database { UserBot.findById(botUserId)?.owner != userId }) { // 权限检查 @@ -191,7 +190,7 @@ class CommandsMenu : BotHandler() { userCalled(userId, "submitted messages to function /${cache.command} for $botUserId") - BotCommands.Cache.fetch(botUserId to cache.command).apply { + launcher.botCommands.fetch(botUserId to cache.command).apply { value = BotCommand(cache.botId, cache.command, cache.description, false, cache.messages, false) changed = true @@ -205,7 +204,7 @@ class CommandsMenu : BotHandler() { (sudo as? Launcher)?.updateCommands() (sudo as? PmBot)?.updateCommands() - (if (cache.userBot != null) Launcher.findHandler() else this) + (if (cache.userBot != null) launcher.findHandler() else this) .commandsMenu(cache.botId, cache.userBot, userId, chatId, 0L, false) @@ -293,7 +292,7 @@ class CommandsMenu : BotHandler() { sudo removePersist userId - BotInstances.initBot(cache.userBot!!).apply { + launcher.initBot(cache.userBot!!).apply { writePersist(userId, persistId, subId, * data, allowFunction = true) @@ -348,7 +347,7 @@ class CommandsMenu : BotHandler() { } - Launcher.findHandler().commandsMenu(cache.botId, cache.userBot, userId, chatId, 0L, false) + launcher.findHandler().commandsMenu(cache.botId, cache.userBot, userId, chatId, 0L, false) } diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/menu/DeleteMenu.kt b/bot/src/main/java/io/nekohasekai/pm/manage/menu/DeleteMenu.kt index 024a827..7dd8159 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/menu/DeleteMenu.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/menu/DeleteMenu.kt @@ -7,7 +7,6 @@ import io.nekohasekai.ktlib.td.core.i18n.localeFor import io.nekohasekai.ktlib.td.core.utils.* import io.nekohasekai.pm.* import io.nekohasekai.pm.database.UserBot -import io.nekohasekai.pm.instance.BotInstances import io.nekohasekai.pm.manage.BotHandler import io.nekohasekai.pm.manage.MyBots import java.util.* @@ -85,7 +84,7 @@ class DeleteMenu : BotHandler() { val status = sudo make L.STOPPING at messageId syncEditTo chatId - val bot = BotInstances.initBot(userBot!!) + val bot = launcher.initBot(userBot!!) bot.waitForClose() diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/menu/IntegrationMenu.kt b/bot/src/main/java/io/nekohasekai/pm/manage/menu/IntegrationMenu.kt index 1f8c542..312b868 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/menu/IntegrationMenu.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/menu/IntegrationMenu.kt @@ -7,8 +7,9 @@ import io.nekohasekai.ktlib.td.core.raw.getChat import io.nekohasekai.ktlib.td.core.raw.getUser import io.nekohasekai.ktlib.td.core.utils.* import io.nekohasekai.pm.* -import io.nekohasekai.pm.database.* -import io.nekohasekai.pm.instance.PmBot +import io.nekohasekai.pm.database.BotIntegration +import io.nekohasekai.pm.database.UserBot +import io.nekohasekai.pm.instance.userBot import io.nekohasekai.pm.manage.BotHandler import io.nekohasekai.pm.manage.MyBots import td.TdApi @@ -37,7 +38,7 @@ class IntegrationMenu : BotHandler() { suspend fun integrationMenu(L: LocaleController, botUserId: Int, userBot: UserBot?, userId: Int, chatId: Long, messageId: Long, isEdit: Boolean) { - val integration = BotIntegration.Cache.fetch(botUserId).value + val integration = launcher.botIntegrations.fetch(botUserId).value val botUserName = botUserName(botUserId, userBot) @@ -115,7 +116,7 @@ class IntegrationMenu : BotHandler() { val action = data[0][0].toInt() - val integration = BotIntegration.Cache.fetch(botUserId).value + val integration = launcher.botIntegrations.fetch(botUserId).value if (integration == null) { @@ -199,7 +200,7 @@ class IntegrationMenu : BotHandler() { } - BotIntegration.Cache.fetch(botUserId).value = if (action < 4) integration else null + launcher.botIntegrations.fetch(botUserId).value = if (action < 4) integration else null integrationMenu(L, botUserId, userBot, userId, chatId, messageId, true) @@ -209,7 +210,7 @@ class IntegrationMenu : BotHandler() { val L = localeFor(userId) - if (userId.toLong() != Launcher.admin && database { UserBot.findById(me.id)?.owner != userId }) { + if (userId.toLong() != launcher.admin && database { UserBot.findById(me.id)?.owner != userId }) { // 权限检查 @@ -228,13 +229,13 @@ class IntegrationMenu : BotHandler() { } - val integrationEntry = BotIntegration.Cache.fetch(me.id) + val integrationEntry = launcher.botIntegrations.fetch(me.id) val integration = integrationEntry.value if (integration == null) { - BotIntegration.Cache.remove(me.id) + launcher.botIntegrations.remove(me.id) database.write { @@ -269,11 +270,11 @@ class IntegrationMenu : BotHandler() { sudo make L.INTEGRATION_HAS_SET syncReplyTo message val botUserId = me.id - val userBot = (sudo as? PmBot)?.userBot + val userBot = userBot - Launcher.apply { + launcher.apply { - val actionMessage = ActionMessage.Cache.fetch(userId) + val actionMessage = actionMessages.fetch(userId) if (actionMessage.value != null) { diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/menu/PreferencesMenu.kt b/bot/src/main/java/io/nekohasekai/pm/manage/menu/PreferencesMenu.kt index 0121431..e13b7df 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/menu/PreferencesMenu.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/menu/PreferencesMenu.kt @@ -73,7 +73,7 @@ class PreferencesMenu : BotHandler() { suspend fun optionsMenu(botUserId: Int, userBot: UserBot?, userId: Int, chatId: Long, messageId: Long, isEdit: Boolean) { - val botSetting = BotSetting.Cache.fetch(botUserId).value + val botSetting = launcher.botSettings.fetch(botUserId).value val L = localeFor(userId) @@ -100,7 +100,7 @@ class PreferencesMenu : BotHandler() { } - val botSettingCache = BotSetting.Cache.fetch(botUserId) + val botSettingCache = launcher.botSettings.fetch(botUserId) val botSetting = botSettingCache.value var target = false diff --git a/bot/src/main/java/io/nekohasekai/pm/manage/menu/StartMessagesMenu.kt b/bot/src/main/java/io/nekohasekai/pm/manage/menu/StartMessagesMenu.kt index b212b1b..d3ad1d0 100644 --- a/bot/src/main/java/io/nekohasekai/pm/manage/menu/StartMessagesMenu.kt +++ b/bot/src/main/java/io/nekohasekai/pm/manage/menu/StartMessagesMenu.kt @@ -6,9 +6,7 @@ import io.nekohasekai.ktlib.td.core.extensions.* import io.nekohasekai.ktlib.td.core.i18n.* import io.nekohasekai.ktlib.td.core.utils.* import io.nekohasekai.pm.* -import io.nekohasekai.pm.database.StartMessages import io.nekohasekai.pm.database.UserBot -import io.nekohasekai.pm.instance.BotInstances import io.nekohasekai.pm.manage.BotHandler import io.nekohasekai.pm.manage.MyBots import td.TdApi @@ -36,7 +34,7 @@ class StartMessagesMenu : BotHandler() { val L = localeFor(userId) - val startMessages = StartMessages.Cache.fetch(botUserId).value + val startMessages = launcher.startMessages.fetch(botUserId).value sudo make L.START_MESSAGES_STATUS.input(botName(botUserId, userBot), botUserName(botUserId, userBot), when { @@ -112,7 +110,7 @@ class StartMessagesMenu : BotHandler() { } else { - BotInstances.initBot(userBot).apply { + launcher.initBot(userBot).apply { writePersist(userId, persistId, 0L, StartMessagesCache(me.id), allowFunction = true) @@ -132,7 +130,7 @@ class StartMessagesMenu : BotHandler() { 1 -> { - StartMessages.Cache.fetch(botUserId).apply { + launcher.startMessages.fetch(botUserId).apply { value = null changed = true @@ -231,7 +229,7 @@ class StartMessagesMenu : BotHandler() { val botUserId = cache.botId - if (chatId != Launcher.admin && database { UserBot.findById(botUserId)?.owner != userId }) { + if (chatId != launcher.admin && database { UserBot.findById(botUserId)?.owner != userId }) { // 权限检查 @@ -245,7 +243,7 @@ class StartMessagesMenu : BotHandler() { userCalled(userId, "submitted start messages to $botUserId") - StartMessages.Cache.fetch(botUserId).apply { + launcher.startMessages.fetch(botUserId).apply { value = cache.messages changed = true diff --git a/ktlib b/ktlib index be5c030..8494875 160000 --- a/ktlib +++ b/ktlib @@ -1 +1 @@ -Subproject commit be5c0309734a4574a533b32c27b75cdadb1ba8e7 +Subproject commit 8494875d754095c7f141da6292d607f4408f1729