File tree Expand file tree Collapse file tree 5 files changed +47
-3
lines changed Expand file tree Collapse file tree 5 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ plugins {
7
7
}
8
8
9
9
group = " com.github.samarium150"
10
- version = " 1.4"
10
+ version = " 1.4.1 "
11
11
12
12
repositories {
13
13
mavenLocal()
Original file line number Diff line number Diff line change
1
+ package com.github.samarium150.mirai.plugin
2
+
3
+ /* *
4
+ * Class representation for handling Lolicon API error
5
+ *
6
+ * @property code [Int] Error code
7
+ * @property message [String] Error message
8
+ * @constructor
9
+ */
10
+ class APIError internal constructor(
11
+ private val code : Int ,
12
+ override val message : String
13
+ ): Exception(message) {
14
+
15
+ /* *
16
+ * Override toString() for logging
17
+ *
18
+ * @return [String]
19
+ */
20
+ override fun toString (): String {
21
+ return " [${code} : ${message} ]"
22
+ }
23
+
24
+ /* *
25
+ * Return the readable information
26
+ *
27
+ * @return [String]
28
+ */
29
+ fun toReadable (): String {
30
+ return when (code) {
31
+ - 1 , 401 -> message
32
+ 403 -> " 调用不规范, 用户两行泪. 快去找开发者的麻烦."
33
+ 404 -> " 没有找到相关图片, 换个关键词试试吧"
34
+ else -> throw Exception (this .toString())
35
+ }
36
+ }
37
+ }
Original file line number Diff line number Diff line change 1
1
package com.github.samarium150.mirai.plugin
2
2
3
+ import com.github.kittinunf.fuel.core.FuelError
3
4
import kotlinx.coroutines.*
4
5
import kotlinx.io.errors.IOException
5
6
import net.mamoe.mirai.Mirai
@@ -125,6 +126,12 @@ object Lolicon: CompositeCommand(
125
126
@Suppress(" BlockingMethodInNonBlockingContext" )
126
127
withContext(Dispatchers .IO ) { try { stream.close() } catch (e: IOException ) {} }
127
128
}
129
+ } catch (fe: FuelError ) {
130
+ Main .logger.warning(fe.toString())
131
+ sendMessage(" 网络连接失败或图片已被删除,之后再试试吧" )
132
+ } catch (ae: APIError ) {
133
+ Main .logger.warning(ae.toString())
134
+ sendMessage(ae.toReadable())
128
135
} catch (e: Exception ) {
129
136
Main .logger.error(e)
130
137
}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ import net.mamoe.mirai.utils.info
26
26
object Main: KotlinPlugin(
27
27
JvmPluginDescription (
28
28
id = "com.github.samarium150.mirai-console-lolicon",
29
- version = "1.4",
29
+ version = "1.4.1 ",
30
30
name = "mirai-console-lolicon"
31
31
)
32
32
) {
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ object RequestHandler {
34
34
val (_, response, result) = getResponse(url)
35
35
if (result is Result .Failure ) throw result.getException()
36
36
val feedback: Response = gson.fromJson(String (response.data), Response ::class .java)
37
- if (feedback.code != 0 ) throw Exception ( feedback.msg)
37
+ if (feedback.code != 0 ) throw APIError (feedback.code, feedback.msg)
38
38
return feedback
39
39
}
40
40
You can’t perform that action at this time.
0 commit comments