From eab5838cd62218ca469a4cff81a3fcdf17eb20fd Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Tue, 23 Jul 2024 18:25:48 +0800 Subject: [PATCH 1/7] =?UTF-8?q?deps:=20=E6=9B=B4=E6=96=B0simbot=E5=88=B04.?= =?UTF-8?q?3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildSrc/src/main/kotlin/P.kt | 4 ++-- gradle/libs.versions.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/P.kt b/buildSrc/src/main/kotlin/P.kt index 87e828b..631a536 100644 --- a/buildSrc/src/main/kotlin/P.kt +++ b/buildSrc/src/main/kotlin/P.kt @@ -40,8 +40,8 @@ object P { override val description: String get() = DESCRIPTION override val homepage: String get() = HOMEPAGE - const val VERSION = "0.0.8" - const val NEXT_VERSION = "0.0.9" + const val VERSION = "0.0.9" + const val NEXT_VERSION = "0.0.10" override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT" override val version = if (isSnapshot()) snapshotVersion else VERSION diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d048046..12cb0fb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ openjdk-jmh = "1.35" log4j = "2.20.0" reactor = "3.6.2" # simbot -simbot = "4.1.0" +simbot = "4.3.0" suspendTransform = "0.9.0" gradleCommon = "0.6.0" # ksp From 16fc260b2b29657964607da6ede88b344948cc6d Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Tue, 23 Jul 2024 18:27:44 +0800 Subject: [PATCH 2/7] =?UTF-8?q?deps:=20=E6=9B=B4=E6=96=B0simbot=E5=88=B04.?= =?UTF-8?q?3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/dependabot.yml | 2 +- .github/release.yml | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 903f937..ea7718b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,7 +2,7 @@ version: 2 updates: - package-ecosystem: gradle directory: / - target-branch: "dev" + target-branch: "dev/main" schedule: interval: weekly labels: diff --git a/.github/release.yml b/.github/release.yml index ab82170..2ff9ddd 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -4,21 +4,19 @@ changelog: - 'for-release' - 'ignore-in-release' categories: - - title: '🔧 Bug Fix' + - title: '🔧Bug Fix' labels: - 'bug' - - title: '⚙️ 修复缺陷' - labels: - '缺陷' - - title: '🎉 新特性' + - title: '🎉新特性' labels: - '特性' - - title: '✨ 优化' + - title: '✨优化' labels: - '优化' - - title: '📦 依赖更新' + - title: '📦依赖更新' labels: - 'dependencies' - - title: '👀 其他变更' + - title: '👀 Others' labels: - '*' From 2fb5ab0dc0d0dff11f4d13d6db2a5c179ef6ed94 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Tue, 23 Jul 2024 19:48:42 +0800 Subject: [PATCH 3/7] feat(core): Support `TelegramBotRegisteredEvent` and `TelegramBotStartedEvent` --- .../core/bot/internal/TelegramBotImpl.kt | 35 ++++++++++------ .../bot/internal/TelegramBotManagerImpl.kt | 28 ++++++------- .../telegram/core/event/TelegramEvent.kt | 14 ++++++- .../core/event/TelegramInternalEvent.kt | 42 +++++++++++++++++++ .../internal/TelegramInternalEventImpls.kt | 40 ++++++++++++++++++ 5 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramInternalEvent.kt create mode 100644 simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/internal/TelegramInternalEventImpls.kt diff --git a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotImpl.kt b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotImpl.kt index fbdf92f..6f85fc4 100644 --- a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotImpl.kt +++ b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotImpl.kt @@ -19,7 +19,9 @@ package love.forte.simbot.component.telegram.core.bot.internal import kotlinx.coroutines.Job import kotlinx.coroutines.ensureActive +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onCompletion import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -37,12 +39,10 @@ import love.forte.simbot.component.telegram.core.bot.internal.command.TelegramBo import love.forte.simbot.component.telegram.core.bot.internal.command.toTGCommands import love.forte.simbot.component.telegram.core.component.TelegramComponent import love.forte.simbot.component.telegram.core.event.TelegramUnsupportedEvent -import love.forte.simbot.component.telegram.core.event.internal.TelegramChannelMessageEventImpl -import love.forte.simbot.component.telegram.core.event.internal.TelegramChatGroupMessageEventImpl -import love.forte.simbot.component.telegram.core.event.internal.TelegramPrivateMessageEventImpl -import love.forte.simbot.component.telegram.core.event.internal.TelegramSuperGroupMessageEventImpl +import love.forte.simbot.component.telegram.core.event.internal.* import love.forte.simbot.event.Event import love.forte.simbot.event.EventDispatcher +import love.forte.simbot.event.EventResult import love.forte.simbot.event.onEachError import love.forte.simbot.logger.LoggerFactory import love.forte.simbot.telegram.api.bot.GetMeApi @@ -114,6 +114,9 @@ internal class TelegramBotImpl( // mark started isStarted = true + // push start event + eventDispatcher.pushEventWithBot(TelegramBotStartedEventImpl(this), this) + .launchIn(this) } } @@ -139,9 +142,6 @@ internal class TelegramBotImpl( } - - - @OptIn(FragileSimbotAPI::class) internal fun subscribeInternalProcessor( bot: TelegramBotImpl, @@ -151,14 +151,11 @@ internal fun subscribeInternalProcessor( val divider = object : SuspendableUpdateDivider() { private suspend fun pushEvent(event: Event) { bot.logger.debug("Bot {} on event: {}", bot, event) - eventDispatcher.push(event) - .onEachError { result -> - bot.eventLogger.error("Bot {} on event dispatch error result: {}", bot, result, result.content) - } - .onCompletion { + eventDispatcher.pushEventWithBot(event, bot) { flow -> + flow.onCompletion { bot.eventLogger.trace("Bot {} event publish completed", bot) } - .collect() + }.collect() } override suspend fun onMismatchUpdateEvent(name: String, value: Any, update: Update?, context: StdlibEvent) { @@ -379,3 +376,15 @@ internal fun subscribeInternalProcessor( } } + +internal inline fun EventDispatcher.pushEventWithBot( + event: Event, + bot: TelegramBotImpl, + block: (Flow) -> Flow = { it } +): Flow { + return push(event) + .onEachError { result -> + bot.eventLogger.error("Bot {} on event dispatch error result: {}", bot, result, result.content) + } + .let(block) +} diff --git a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotManagerImpl.kt b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotManagerImpl.kt index 7a329e3..1f6ad6f 100644 --- a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotManagerImpl.kt +++ b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/internal/TelegramBotManagerImpl.kt @@ -18,6 +18,7 @@ package love.forte.simbot.component.telegram.core.bot.internal import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.launchIn import love.forte.simbot.bot.ConflictBotException import love.forte.simbot.bot.JobBasedBotManager import love.forte.simbot.common.collection.computeValue @@ -25,13 +26,13 @@ import love.forte.simbot.common.collection.concurrentMutableMap import love.forte.simbot.common.collection.removeValue import love.forte.simbot.common.coroutines.mergeWith import love.forte.simbot.common.id.ID -import love.forte.simbot.common.id.NumericalID import love.forte.simbot.common.id.literal import love.forte.simbot.component.telegram.core.bot.TelegramBot import love.forte.simbot.component.telegram.core.bot.TelegramBotConfiguration import love.forte.simbot.component.telegram.core.bot.TelegramBotManager import love.forte.simbot.component.telegram.core.bot.TelegramBotManagerConfiguration import love.forte.simbot.component.telegram.core.component.TelegramComponent +import love.forte.simbot.component.telegram.core.event.internal.TelegramBotRegisteredEventImpl import love.forte.simbot.event.EventDispatcher import love.forte.simbot.telegram.stdlib.bot.Bot import love.forte.simbot.telegram.stdlib.bot.BotFactory @@ -53,7 +54,7 @@ internal class TelegramBotManagerImpl( private val botsWithTokenKey = concurrentMutableMap() // id token cache - private val idTokenMap = concurrentMutableMap() + // private val idTokenMap = concurrentMutableMap() override fun register(ticket: Bot.Ticket, configuration: TelegramBotConfiguration): TelegramBot { val token = ticket.token @@ -78,12 +79,12 @@ internal class TelegramBotManagerImpl( createBot() }!! - // TODO register update idTokenMap - newBot.onCompletion { botsWithTokenKey.removeValue(token) { newBot } } + eventDispatcher.pushRegisteredEvent(newBot) + return newBot } @@ -91,17 +92,14 @@ internal class TelegramBotManagerImpl( botsWithTokenKey.values.asSequence() override fun find(id: ID): TelegramBot? { - fun findByLongId(lid: Long): TelegramBot? = - idTokenMap[lid]?.let { token -> botsWithTokenKey[token] }?.takeIf { it.isActive } - - if (id is NumericalID) { - return findByLongId(id.toLong()) - } - val token = id.literal - val foundByToken = botsWithTokenKey[token] - if (foundByToken != null) return foundByToken - - return token.toLongOrNull()?.let { longId -> findByLongId(longId) } + return botsWithTokenKey[token] } } + +internal fun EventDispatcher.pushRegisteredEvent( + bot: TelegramBotImpl +): Job { + val e = TelegramBotRegisteredEventImpl(bot) + return pushEventWithBot(e, bot).launchIn(bot) +} diff --git a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramEvent.kt b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramEvent.kt index b21aaac..8a85393 100644 --- a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramEvent.kt +++ b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramEvent.kt @@ -30,13 +30,25 @@ import love.forte.simbot.telegram.type.Message */ public typealias StdlibEvent = love.forte.simbot.telegram.stdlib.event.Event +/** + * An telegram bot event. + * + * @see TelegramEvent + */ +public interface TelegramBotEvent : BotEvent { + /** + * The [TelegramBot]. + */ + override val bot: TelegramBot +} + /** * Is a Telegram simbot component event definition type. * Is an implementation of the event type in the simbot API. * * @author ForteScarlet */ -public interface TelegramEvent : BotEvent { +public interface TelegramEvent : TelegramBotEvent { // 所有的 Telegram Event 都是建立在 Bot 之上的, // 因此所有 TelegramEvent 都实现 BotEvent diff --git a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramInternalEvent.kt b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramInternalEvent.kt new file mode 100644 index 0000000..a8e682a --- /dev/null +++ b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/TelegramInternalEvent.kt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024. ForteScarlet. + * + * This file is part of simbot-component-telegram. + * + * simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram. + * If not, see . + */ + +package love.forte.simbot.component.telegram.core.event + +import love.forte.simbot.component.telegram.core.bot.TelegramBot +import love.forte.simbot.event.BotRegisteredEvent + + +/** + * An event that indicating a [TelegramBot] has been registered. + * + * This is an event used as a notification + * that the bot may not have been started yet. + */ +public interface TelegramBotRegisteredEvent : BotRegisteredEvent, TelegramBotEvent { + override val bot: TelegramBot +} + +/** + * An event that indicating a [TelegramBot] has been started at the first time. + * + * This is an event used as a notification. + * At this point, [bot.isStarted][TelegramBot.isStarted] is already `true`. + */ +public interface TelegramBotStartedEvent : BotRegisteredEvent, TelegramBotEvent { + override val bot: TelegramBot +} diff --git a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/internal/TelegramInternalEventImpls.kt b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/internal/TelegramInternalEventImpls.kt new file mode 100644 index 0000000..cc73def --- /dev/null +++ b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/event/internal/TelegramInternalEventImpls.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024. ForteScarlet. + * + * This file is part of simbot-component-telegram. + * + * simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram. + * If not, see . + */ + +package love.forte.simbot.component.telegram.core.event.internal + +import love.forte.simbot.annotations.ExperimentalSimbotAPI +import love.forte.simbot.common.id.ID +import love.forte.simbot.common.id.UUID +import love.forte.simbot.common.time.Timestamp +import love.forte.simbot.component.telegram.core.bot.TelegramBot +import love.forte.simbot.component.telegram.core.event.TelegramBotRegisteredEvent +import love.forte.simbot.component.telegram.core.event.TelegramBotStartedEvent + +internal class TelegramBotRegisteredEventImpl(override val bot: TelegramBot) : TelegramBotRegisteredEvent { + override val id: ID = UUID.random() + + @OptIn(ExperimentalSimbotAPI::class) + override val time: Timestamp = Timestamp.now() +} + +internal class TelegramBotStartedEventImpl(override val bot: TelegramBot) : TelegramBotStartedEvent { + override val id: ID = UUID.random() + + @OptIn(ExperimentalSimbotAPI::class) + override val time: Timestamp = Timestamp.now() +} From 4048038a57bbc41c14aec3517960e5e58ce1321f Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Tue, 23 Jul 2024 23:49:07 +0800 Subject: [PATCH 4/7] =?UTF-8?q?feat(core):=20`TelegramBot`=20=E4=B8=AD?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20`execute*`=20API=20=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=AF=B7=E6=B1=82API=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/jvmMain/java/module-info.java | 1 + .../telegram/core/bot/BotRequests.kt | 5 +- .../telegram/core/bot/TelegramBot.kt | 39 +++++++ .../src/jvmMain/java/module-info.java | 1 + .../telegram/stdlib/bot/BotRequests.jvm.kt | 103 +++++++++++++++--- 5 files changed, 129 insertions(+), 20 deletions(-) diff --git a/simbot-component-telegram-api/src/jvmMain/java/module-info.java b/simbot-component-telegram-api/src/jvmMain/java/module-info.java index 34ae149..23ca42c 100644 --- a/simbot-component-telegram-api/src/jvmMain/java/module-info.java +++ b/simbot-component-telegram-api/src/jvmMain/java/module-info.java @@ -3,6 +3,7 @@ requires simbot.common.core; requires simbot.common.ktor.inputfile; requires transitive simbot.component.telegram.type; + requires io.ktor.client.core; exports love.forte.simbot.telegram.api; exports love.forte.simbot.telegram.api.bot; diff --git a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/BotRequests.kt b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/BotRequests.kt index c5007fc..91a75f6 100644 --- a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/BotRequests.kt +++ b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/BotRequests.kt @@ -32,11 +32,10 @@ import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlin.jvm.JvmSynthetic -// TODO JVM - /** * Use [TelegramBot] to request the [TelegramApi] and get [HttpResponse]. * @see TelegramApi.requestRawBy + * @see TelegramBot.executeRaw */ @JvmSynthetic public suspend fun TelegramApi<*>.requestRawBy(bot: TelegramBot): HttpResponse = @@ -45,6 +44,7 @@ public suspend fun TelegramApi<*>.requestRawBy(bot: TelegramBot): HttpResponse = /** * Use [TelegramBot] to request the [TelegramApi] and get [TelegramApiResult] with [R]. * @see TelegramApi.requestResult + * @see TelegramBot.executeResult */ @JvmSynthetic public suspend fun TelegramApi.requestResultBy(bot: TelegramBot): TelegramApiResult = @@ -53,6 +53,7 @@ public suspend fun TelegramApi.requestResultBy(bot: TelegramBot): T /** * Use [TelegramBot] to request the [TelegramApi] and get [R]. * @see TelegramApi.requestData + * @see TelegramBot.execute */ @JvmSynthetic public suspend fun TelegramApi.requestDataBy(bot: TelegramBot): R = diff --git a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/TelegramBot.kt b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/TelegramBot.kt index fd7fd8b..5ea65bf 100644 --- a/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/TelegramBot.kt +++ b/simbot-component-telegram-core/src/commonMain/kotlin/love/forte/simbot/component/telegram/core/bot/TelegramBot.kt @@ -17,6 +17,7 @@ package love.forte.simbot.component.telegram.core.bot +import io.ktor.client.statement.* import love.forte.simbot.bot.Bot import love.forte.simbot.bot.ContactRelation import love.forte.simbot.bot.GroupRelation @@ -27,6 +28,8 @@ import love.forte.simbot.component.telegram.core.bot.command.TelegramBotCommands import love.forte.simbot.component.telegram.core.bot.command.TelegramBotCommandsUpdater import love.forte.simbot.component.telegram.core.component.TelegramComponent import love.forte.simbot.suspendrunner.ST +import love.forte.simbot.telegram.api.TelegramApi +import love.forte.simbot.telegram.api.TelegramApiResult import love.forte.simbot.telegram.api.update.Update import love.forte.simbot.telegram.type.BotCommandScope import love.forte.simbot.telegram.type.User @@ -124,6 +127,42 @@ public interface TelegramBot : Bot { */ public val commandsUpdater: TelegramBotCommandsUpdater + /** + * Execute [TelegramApi] by this bot. + * + * @throws Exception Any exception that may occur during the API request process + * + * @see requestDataBy + */ + @ST + public suspend fun execute(api: TelegramApi): R = + api.requestDataBy(this) + + /** + * Execute [TelegramApi] by this bot. + * + * @throws Exception Any exception that may occur during the API request process + * + * @return The raw [HttpResponse] + * @see requestRawBy + */ + @ST + public suspend fun executeRaw(api: TelegramApi<*>): HttpResponse = + api.requestRawBy(this) + + /** + * Execute [TelegramApi] by this bot. + * + * @throws Exception Any exception that may occur during the API request process + * + * @return The [TelegramApiResult] + * @see requestResultBy + */ + @ST + public suspend fun executeResult(api: TelegramApi): TelegramApiResult = + api.requestResultBy(this) + + override val groupRelation: GroupRelation? get() = null diff --git a/simbot-component-telegram-stdlib/src/jvmMain/java/module-info.java b/simbot-component-telegram-stdlib/src/jvmMain/java/module-info.java index adcbab0..38a7f11 100644 --- a/simbot-component-telegram-stdlib/src/jvmMain/java/module-info.java +++ b/simbot-component-telegram-stdlib/src/jvmMain/java/module-info.java @@ -11,6 +11,7 @@ requires static kotlinx.coroutines.reactive; requires static org.reactivestreams; + requires io.ktor.client.core; exports love.forte.simbot.telegram.stdlib.bot; exports love.forte.simbot.telegram.stdlib.event; diff --git a/simbot-component-telegram-stdlib/src/jvmMain/kotlin/love/forte/simbot/telegram/stdlib/bot/BotRequests.jvm.kt b/simbot-component-telegram-stdlib/src/jvmMain/kotlin/love/forte/simbot/telegram/stdlib/bot/BotRequests.jvm.kt index cc35bab..a0f761a 100644 --- a/simbot-component-telegram-stdlib/src/jvmMain/kotlin/love/forte/simbot/telegram/stdlib/bot/BotRequests.jvm.kt +++ b/simbot-component-telegram-stdlib/src/jvmMain/kotlin/love/forte/simbot/telegram/stdlib/bot/BotRequests.jvm.kt @@ -23,65 +23,132 @@ package love.forte.simbot.telegram.stdlib.bot import io.ktor.client.statement.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.future.future +import love.forte.simbot.annotations.InternalSimbotAPI +import love.forte.simbot.suspendrunner.reserve.SuspendReserve +import love.forte.simbot.suspendrunner.reserve.suspendReserve import love.forte.simbot.suspendrunner.runInNoScopeBlocking import love.forte.simbot.telegram.api.* import java.util.concurrent.CompletableFuture +import kotlin.coroutines.CoroutineContext +import kotlin.coroutines.EmptyCoroutineContext /** * [requestRawBy] in async. * @see TelegramApi.requestRaw */ -@JvmSynthetic @JvmOverloads -public fun TelegramApi<*>.requestByAsync(bot: Bot, scope: CoroutineScope = bot): CompletableFuture = - scope.future { requestRawBy(bot) } +public fun TelegramApi<*>.requestByAsync( + bot: Bot, + scope: CoroutineScope? = null, + context: CoroutineContext? = null, +): CompletableFuture = + (scope ?: bot).future(context = context ?: EmptyCoroutineContext) { requestRawBy(bot) } /** * [requestResultBy] in async. * @see TelegramApi.requestResult */ -@JvmSynthetic @JvmOverloads public fun TelegramApi.requestResultByAsync( bot: Bot, - scope: CoroutineScope = bot + scope: CoroutineScope? = null, + context: CoroutineContext? = null, ): CompletableFuture> = - scope.future { requestResultBy(bot) } + (scope ?: bot).future(context = context ?: EmptyCoroutineContext) { requestResultBy(bot) } /** * [requestDataBy] in async. * @see TelegramApi.requestData */ -@JvmSynthetic @JvmOverloads -public fun TelegramApi.requestDataByAsync(bot: Bot, scope: CoroutineScope = bot): CompletableFuture = - scope.future { requestDataBy(bot) } +public fun TelegramApi.requestDataByAsync( + bot: Bot, + scope: CoroutineScope? = null, + context: CoroutineContext? = null, +): CompletableFuture = + (scope ?: bot).future(context = context ?: EmptyCoroutineContext) { requestDataBy(bot) } /** * [requestRawBy] in blocking. * @see requestRawBy */ -@JvmSynthetic -public fun TelegramApi<*>.requestByBlocking(bot: Bot): HttpResponse = - runInNoScopeBlocking { requestRawBy(bot) } +@JvmOverloads +public fun TelegramApi<*>.requestByBlocking( + bot: Bot, + context: CoroutineContext? = null, +): HttpResponse = + runInNoScopeBlocking(context = context ?: EmptyCoroutineContext) { requestRawBy(bot) } /** * [requestResultBy] in blocking. * @see requestResultBy */ -@JvmSynthetic +@JvmOverloads public fun TelegramApi.requestResultByBlocking( - bot: Bot + bot: Bot, + context: CoroutineContext? = null, ): TelegramApiResult = - runInNoScopeBlocking { requestResultBy(bot) } + runInNoScopeBlocking(context = context ?: EmptyCoroutineContext) { requestResultBy(bot) } + +/** + * [requestDataBy] in blocking. + * @see requestDataBy + */ +@JvmOverloads +public fun TelegramApi.requestDataByBlocking( + bot: Bot, + context: CoroutineContext? = null, +): R = + runInNoScopeBlocking(context = context ?: EmptyCoroutineContext) { requestDataBy(bot) } + + +/** + * [requestRawBy] in blocking. + * @see requestRawBy + */ +@OptIn(InternalSimbotAPI::class) +@JvmOverloads +public fun TelegramApi<*>.requestByReserve( + bot: Bot, + scope: CoroutineScope? = null, + context: CoroutineContext? = null, +): SuspendReserve = + suspendReserve( + scope = scope ?: bot, + context = context ?: EmptyCoroutineContext, + ) { requestRawBy(bot) } + +/** + * [requestResultBy] in blocking. + * @see requestResultBy + */ +@OptIn(InternalSimbotAPI::class) +@JvmOverloads +public fun TelegramApi.requestResultByReserve( + bot: Bot, + scope: CoroutineScope? = null, + context: CoroutineContext? = null, +): SuspendReserve> = + suspendReserve( + scope = scope ?: bot, + context = context ?: EmptyCoroutineContext, + ) { requestResultBy(bot) } /** * [requestDataBy] in blocking. * @see requestDataBy */ -@JvmSynthetic -public fun TelegramApi.requestDataByBlocking(bot: Bot): R = - runInNoScopeBlocking { requestDataBy(bot) } +@OptIn(InternalSimbotAPI::class) +@JvmOverloads +public fun TelegramApi.requestDataByReserve( + bot: Bot, + scope: CoroutineScope? = null, + context: CoroutineContext? = null, +): SuspendReserve = + suspendReserve( + scope = scope ?: bot, + context = context ?: EmptyCoroutineContext, + ) { requestDataBy(bot) } From 8b25f10cdf4c77dee1bae8da18adec43e2f05d3a Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Wed, 24 Jul 2024 00:11:01 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BC=98=E5=8C=96KDoc;=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0gtag;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .simbot/dokka-assets/css/kdoc-style.css | 32 ++++++-- .simbot/dokka-assets/logo-icon-light.svg | 78 +++++++++++++++++++ .simbot/dokka-assets/logo-icon.svg | 40 +++++----- .../includes/page_metadata.ftl | 26 +++++++ ...bot-telegram-dokka-multi-module.gradle.kts | 29 ++++--- ...elegram-dokka-partial-configure.gradle.kts | 45 ++++++++--- 6 files changed, 203 insertions(+), 47 deletions(-) create mode 100644 .simbot/dokka-assets/logo-icon-light.svg create mode 100644 .simbot/dokka-templates/includes/page_metadata.ftl diff --git a/.simbot/dokka-assets/css/kdoc-style.css b/.simbot/dokka-assets/css/kdoc-style.css index 83a1461..f06f72c 100644 --- a/.simbot/dokka-assets/css/kdoc-style.css +++ b/.simbot/dokka-assets/css/kdoc-style.css @@ -1,8 +1,26 @@ -.library-name a::before { - background: url("../images/logo-icon.svg") center no-repeat; - background-size: contain; - width: 40px; - height: 40px; - top: -12px; - left: -50px; +/* + * Copyright (c) 2024. ForteScarlet. + * + * Project https://github.com/simple-robot/simpler-robot + * Email ForteScarlet@163.com + * + * This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Lesser GNU General Public License for more details. + * + * You should have received a copy of the Lesser GNU General Public License + * along with this program. If not, see . + * + */ + +:root { + --dokka-logo-image-url: url('../images/logo-icon-light.svg'); } diff --git a/.simbot/dokka-assets/logo-icon-light.svg b/.simbot/dokka-assets/logo-icon-light.svg new file mode 100644 index 0000000..4cb3625 --- /dev/null +++ b/.simbot/dokka-assets/logo-icon-light.svg @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.simbot/dokka-assets/logo-icon.svg b/.simbot/dokka-assets/logo-icon.svg index 4cb3625..a1d8512 100644 --- a/.simbot/dokka-assets/logo-icon.svg +++ b/.simbot/dokka-assets/logo-icon.svg @@ -22,57 +22,57 @@ - --> - + - + - - - + + + - + - + - - + + - + - - + + diff --git a/.simbot/dokka-templates/includes/page_metadata.ftl b/.simbot/dokka-templates/includes/page_metadata.ftl new file mode 100644 index 0000000..2f6156c --- /dev/null +++ b/.simbot/dokka-templates/includes/page_metadata.ftl @@ -0,0 +1,26 @@ +<#macro display> + ${pageName} + <@template_cmd name="pathToRoot"> +