Skip to content

Commit 31b99a8

Browse files
committed
feat: adapt to Lolicon API v2
BREAKING CHANGE: Simple getting is now adapted to Lolicon API v2. Upgrade mirai-console to 2.7-M2
1 parent 2bc355b commit 31b99a8

16 files changed

+286
-443
lines changed

build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ plugins {
55
kotlin("jvm") version kotlinVersion
66
kotlin("plugin.serialization") version kotlinVersion
77

8-
id("net.mamoe.mirai-console") version "2.7-M1"
9-
id("org.jetbrains.dokka") version "1.4.32"
8+
id("net.mamoe.mirai-console") version "2.7-M2"
9+
id("org.jetbrains.dokka") version "1.5.0"
1010
id("com.geoffgranum.gradle-conventional-changelog") version "0.3.1"
1111
}
1212

1313
group = "com.github.samarium150"
14-
version = "3.4.1"
14+
version = "4.0.0-beta.1"
1515

1616
repositories {
1717
mavenLocal()
18+
maven(url="https://maven.aliyun.com/repository/public")
1819
mavenCentral()
1920
}
2021

2122
dependencies {
22-
implementation("com.google.code.gson:gson:+")
23-
implementation("com.github.kittinunf.fuel:fuel:+")
23+
implementation("io.ktor:ktor-client-serialization:1.5.4")
2424
}
2525

2626
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {

src/main/kotlin/APIException.kt

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/main/kotlin/CommandConfig.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.samarium150.mirai.plugin
33
import net.mamoe.mirai.console.data.AutoSavePluginConfig
44
import net.mamoe.mirai.console.data.ValueDescription
55
import net.mamoe.mirai.console.data.value
6-
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
76

87
/**
98
* Command config
@@ -19,9 +18,7 @@ object CommandConfig: AutoSavePluginConfig("CommandConfig") {
1918
* Composite command secondary names
2019
* <br>
2120
* 复合命令的别名
22-
* 目前还是实验性配置
2321
*/
24-
@ConsoleExperimentalApi
2522
@ValueDescription("复合命令的别名")
2623
val lolicon: Array<String> by value(arrayOf("涩图"))
2724
}

src/main/kotlin/ExecutionConfig.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable
2727
* <br>
2828
* 执行get命令时的配置
2929
*
30-
* @property apikey [PluginConfig.apikey]
30+
// * @property apikey [PluginConfig.apikey]
3131
* @property r18 [PluginData.customR18Users] and [PluginData.customR18Groups]
3232
* @property recall [PluginConfig.recall]
3333
* @property cooldown [PluginConfig.cooldown]
@@ -36,21 +36,21 @@ import org.jetbrains.annotations.Nullable
3636
* @see PluginData
3737
*/
3838
data class ExecutionConfig(
39-
var apikey: String = PluginConfig.apikey,
39+
// var apikey: String = PluginConfig.apikey,
4040
var r18: Int = 0,
4141
var recall: Int = PluginConfig.recall,
4242
var cooldown: Int = PluginConfig.cooldown
4343
) {
44-
/**
45-
* Set [apikey] to [value]
46-
* <br>
47-
* 将 [apikey] 的值设置为 [value]
48-
*
49-
* @param value Input value <br> 输入的值
50-
*/
51-
private fun setAPIKey(@Nullable value: String?) {
52-
if (value != null) apikey = value
53-
}
44+
// /**
45+
// * Set [apikey] to [value]
46+
// * <br>
47+
// * 将 [apikey] 的值设置为 [value]
48+
// *
49+
// * @param value Input value <br> 输入的值
50+
// */
51+
// private fun setAPIKey(@Nullable value: String?) {
52+
// if (value != null) apikey = value
53+
// }
5454

5555
/**
5656
* Set [r18] to [value]
@@ -100,13 +100,13 @@ data class ExecutionConfig(
100100
val config = ExecutionConfig()
101101
when (subject) {
102102
is User -> {
103-
config.setAPIKey(PluginData.customAPIKeyUsers[subject.id])
103+
// config.setAPIKey(PluginData.customAPIKeyUsers[subject.id])
104104
config.setR18(PluginData.customR18Users[subject.id])
105105
config.setRecall(PluginData.customRecallUsers[subject.id])
106106
config.setCooldown(PluginData.customCooldownUsers[subject.id])
107107
}
108108
is Group -> {
109-
config.setAPIKey(PluginData.customAPIKeyGroups[subject.id])
109+
// config.setAPIKey(PluginData.customAPIKeyGroups[subject.id])
110110
config.setR18(PluginData.customR18Groups[subject.id])
111111
config.setRecall(PluginData.customRecallGroups[subject.id])
112112
config.setCooldown(PluginData.customCooldownGroups[subject.id])

src/main/kotlin/ImageData.kt

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
*/
1717
package com.github.samarium150.mirai.plugin
1818

19-
import kotlin.reflect.full.memberProperties
19+
import kotlinx.serialization.Serializable
20+
import kotlinx.serialization.encodeToString
21+
import kotlinx.serialization.json.Json
2022

2123
/**
2224
* The image information returned by Lolicon API
@@ -28,41 +30,32 @@ import kotlin.reflect.full.memberProperties
2830
* @property uid Author UID <br> 作者UID
2931
* @property title Image title <br> 图片标题
3032
* @property author Author's name <br> 作者名字
31-
* @property url Link to the image <br> 图片链接
3233
* @property r18 R18 category <br> 是否为R18
3334
* @property width Width of the image <br> 宽度
3435
* @property height Height of the image <br> 高度
3536
* @property tags Image tags <br> 标签
37+
* @property urls Image urls <br> 链接
3638
* @constructor Create an Image data instance <br> 实例化图片数据
37-
* @see Response
39+
* @see ResponseBody
3840
*/
39-
data class ImageData (
41+
@Serializable
42+
data class ImageData(
4043
val pid: Int,
4144
val p: Int,
4245
val uid: Int,
4346
val title: String,
4447
val author: String,
45-
val url: String,
4648
val r18: Boolean,
4749
val width: Int,
4850
val height: Int,
49-
val tags: ArrayList<String>
51+
val tags: List<String>,
52+
val ext: String,
53+
val uploadDate: Long,
54+
val urls: Map<String, String>
5055
) {
5156

52-
/**
53-
* Return the string representation
54-
* <br>
55-
* 字符串化该类
56-
*
57-
* @return the string representation <br> 类的字符串表示
58-
*/
5957
override fun toString(): String {
60-
var result = "ImageData({"
61-
for (props in ImageData::class.memberProperties) {
62-
result += "${props.name}: ${props.get(this)}, "
63-
}
64-
result = result.dropLast(2) + "})"
65-
return result
58+
return "ImageData" + Json.encodeToString(this)
6659
}
6760

6861
/**
@@ -73,7 +66,7 @@ data class ImageData (
7366
* @return [String] readable information <br> 具有可读性的信息
7467
*/
7568
fun toReadable(): String {
76-
return(
69+
return (
7770
"标题: ${title}\n" +
7871
"作者: $author (uid: ${uid})\n" +
7972
"标签: ${tags}\n" +

0 commit comments

Comments
 (0)