Skip to content

Commit

Permalink
fix: merge #23
Browse files Browse the repository at this point in the history
fix: resolve the conflict with chat-command
  • Loading branch information
Samarium150 authored Jan 25, 2021
2 parents 0641fa5 + 4a25904 commit 9f5a16c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 61 deletions.
18 changes: 18 additions & 0 deletions Module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Module mirai-console-lolicon
[ACGPro](https://github.com/ShrBox/ACGPro) 启发而写
<br>
Social preview的图片来自 [AliceSoft](https://www.alicesoft.com) 制作的游戏 [ドーナドーナ いっしょにわるいことをしよう](https://www.alicesoft.com/dohnadohna)
<br>
在群内随机发送图片(默认30s自动撤回+60s冷却),支持关键词检索
<br>
适配 [mirai-console](https://github.com/mamoe/mirai-console)
[2.0.0](https://github.com/mamoe/mirai-console/releases/tag/2.0.0)
<br>
可以在 [Lolicon API](https://api.lolicon.app/#/setu) 申请apikey来增加调用额度
<br>
帮助文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
<br>
本页面为Kotlin源文件的注释文档

# Package com.github.samarium150.mirai.plugin
插件主包
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Social preview的图片来自 [AliceSoft](https://www.alicesoft.com) 制作的
<br>
可以在 [Lolicon API](https://api.lolicon.app/#/setu) 申请apikey来增加调用额度
<br>
文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
使用文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
13 changes: 11 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -21,7 +22,15 @@ dependencies {
implementation("com.github.kittinunf.fuel:fuel:+")
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
kotlinOptions.jvmTarget = "11"
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dokkaSourceSets {
named("main") {
includes.from("Module.md")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/Lolicon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
51 changes: 1 addition & 50 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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<MessageEvent>

/**
* Will be invoked when the plugin is enabled
Expand All @@ -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
*/
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/RequestHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 9f5a16c

Please sign in to comment.