diff --git a/Module.md b/Module.md
new file mode 100644
index 0000000..4d8dd18
--- /dev/null
+++ b/Module.md
@@ -0,0 +1,18 @@
+# Module mirai-console-lolicon
+受 [ACGPro](https://github.com/ShrBox/ACGPro) 启发而写
+
+Social preview的图片来自 [AliceSoft](https://www.alicesoft.com) 制作的游戏 [ドーナドーナ いっしょにわるいことをしよう](https://www.alicesoft.com/dohnadohna)
+
+在群内随机发送图片(默认30s自动撤回+60s冷却),支持关键词检索
+
+适配 [mirai-console](https://github.com/mamoe/mirai-console)
+[2.0.0](https://github.com/mamoe/mirai-console/releases/tag/2.0.0)
+
+可以在 [Lolicon API](https://api.lolicon.app/#/setu) 申请apikey来增加调用额度
+
+帮助文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
+
+本页面为Kotlin源文件的注释文档
+
+# Package com.github.samarium150.mirai.plugin
+插件主包
diff --git a/README.md b/README.md
index 460fb93..ef1b16e 100644
--- a/README.md
+++ b/README.md
@@ -15,4 +15,4 @@ Social preview的图片来自 [AliceSoft](https://www.alicesoft.com) 制作的
可以在 [Lolicon API](https://api.lolicon.app/#/setu) 申请apikey来增加调用额度
-文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
+使用文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
diff --git a/build.gradle.kts b/build.gradle.kts
index 35e5eb8..1a12c9f 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -4,10 +4,11 @@ plugins {
kotlin("plugin.serialization") version kotlinVersion
id("net.mamoe.mirai-console") version "2.0.0"
+ id("org.jetbrains.dokka") version "1.4.0"
}
group = "com.github.samarium150"
-version = "2.0"
+version = "2.1"
repositories {
mavenLocal()
@@ -21,7 +22,15 @@ dependencies {
implementation("com.github.kittinunf.fuel:fuel:+")
}
-tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all {
+tasks.withType().all {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
kotlinOptions.jvmTarget = "11"
}
+
+tasks.withType().configureEach {
+ dokkaSourceSets {
+ named("main") {
+ includes.from("Module.md")
+ }
+ }
+}
diff --git a/src/main/kotlin/APIError.kt b/src/main/kotlin/APIException.kt
similarity index 87%
rename from src/main/kotlin/APIError.kt
rename to src/main/kotlin/APIException.kt
index 5c5392a..054f289 100644
--- a/src/main/kotlin/APIError.kt
+++ b/src/main/kotlin/APIException.kt
@@ -17,13 +17,13 @@
package com.github.samarium150.mirai.plugin
/**
- * Class representation for handling Lolicon API error
+ * Class representation for handling Lolicon API Exceptions
*
- * @property code [Int] Error code
- * @property message [String] Error message
+ * @property code [Int] status code from HTTP response
+ * @property message [String] message from HTTP response
* @constructor
*/
-class APIError internal constructor(
+class APIException internal constructor(
private val code: Int,
override val message: String
) : Exception(message) {
diff --git a/src/main/kotlin/Lolicon.kt b/src/main/kotlin/Lolicon.kt
index 3d1a0c3..536d2a8 100644
--- a/src/main/kotlin/Lolicon.kt
+++ b/src/main/kotlin/Lolicon.kt
@@ -100,7 +100,7 @@ object Lolicon: CompositeCommand(
} catch (fe: FuelError) {
Main.logger.warning(fe.toString())
sendMessage("网络连接失败或图片已被删除,之后再试试吧")
- } catch (ae: APIError) {
+ } catch (ae: APIException) {
Main.logger.warning(ae.toString())
sendMessage(ae.toReadable())
} catch (e: Exception) {
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index 592913c..c8c6a96 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -16,25 +16,14 @@
*/
package com.github.samarium150.mirai.plugin
-import kotlinx.coroutines.CoroutineExceptionHandler
-import net.mamoe.mirai.console.MiraiConsole
-import net.mamoe.mirai.console.command.CommandExecuteResult
-import net.mamoe.mirai.console.command.CommandManager
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister
-import net.mamoe.mirai.console.command.CommandSender.Companion.toCommandSender
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
import net.mamoe.mirai.console.permission.AbstractPermitteeId
import net.mamoe.mirai.console.permission.PermissionService.Companion.permit
-import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
-import net.mamoe.mirai.event.ConcurrencyKind
-import net.mamoe.mirai.event.EventPriority
-import net.mamoe.mirai.event.Listener
-import net.mamoe.mirai.event.events.MessageEvent
-import net.mamoe.mirai.event.globalEventChannel
import net.mamoe.mirai.utils.info
/**
@@ -43,15 +32,10 @@ import net.mamoe.mirai.utils.info
object Main: KotlinPlugin(
JvmPluginDescription(
id = "com.github.samarium150.mirai-console-lolicon",
- version = "2.0",
+ version = "2.1",
name = "mirai-console-lolicon"
)
) {
- /**
- * The listener for listening message events
- * Contacts send commands as messages
- */
- private lateinit var commandListener: Listener
/**
* Will be invoked when the plugin is enabled
@@ -68,39 +52,6 @@ object Main: KotlinPlugin(
else
logger.warning("请先在配置文件设置Bot所有者id")
- /**
- * Subscribe events
- */
- commandListener =
- globalEventChannel().subscribeAlways(
- MessageEvent::class,
- CoroutineExceptionHandler { _, throwable -> logger.error(throwable) },
- ConcurrencyKind.CONCURRENT,
- EventPriority.NORMAL
- ) call@ {
- if (!PluginConfig.enabled) return@call
- val sender = this.toCommandSender()
- when (val result = CommandManager.executeCommand(sender, message)) {
- is CommandExecuteResult.IllegalArgument -> {
- result.exception.message?.let { sender.sendMessage(it) }
- // intercept()
- }
- is CommandExecuteResult.ExecutionFailed -> {
- val owner = result.command.owner
- val (logger, printOwner) = when (owner) {
- is JvmPlugin -> owner.logger to false
- else -> MiraiConsole.mainLogger to true
- }
- logger.warning(
- "Exception in executing command `$message`" +
- if (printOwner) ", command owned by $owner" else "",
- result.exception
- )
- // intercept()
- }
- }
- }
-
/**
* Register commands
*/
diff --git a/src/main/kotlin/RequestHandler.kt b/src/main/kotlin/RequestHandler.kt
index 2ece840..f29382b 100644
--- a/src/main/kotlin/RequestHandler.kt
+++ b/src/main/kotlin/RequestHandler.kt
@@ -48,15 +48,15 @@ object RequestHandler {
* @return [Response]
* @throws FuelError if GET request is failed
* @throws JsonSyntaxException if returned JSON is invalid
- * @throws APIError if Lolicon API didn't return status 0
+ * @throws APIException if Lolicon API didn't return status 0
*/
- @Throws(FuelError::class, JsonSyntaxException::class, APIError::class)
+ @Throws(FuelError::class, JsonSyntaxException::class, APIException::class)
fun get(request: Request): Response {
val url = "https://api.lolicon.app/setu/?$request"
val (_, response, result) = getResponse(url)
if (result is Result.Failure) throw result.getException()
val feedback: Response = gson.fromJson(String(response.data), Response::class.java)
- if (feedback.code != 0) throw APIError(feedback.code, feedback.msg)
+ if (feedback.code != 0) throw APIException(feedback.code, feedback.msg)
return feedback
}