Skip to content

Commit 7d8d123

Browse files
committed
feat: add custom caching and proxy options; fixes #34
1 parent 7712f53 commit 7d8d123

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# [3.2.0](https://github.com/Samarium150/mirai-console-lolicon/compare/3.1.0...3.2.0) (2021-03-30)
2+
3+
4+
### feat
5+
6+
* add custom caching and proxy options ([de09441](https://github.com/Samarium150/mirai-console-lolicon/commit/de09441ba3b8633c2b155ee166ef592806f97085))
7+
8+
9+
110
# [3.1.0](https://github.com/Samarium150/mirai-console-lolicon/compare/3.0.1...3.1.0) (2021-02-15)
211

312

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import java.net.URL
22

33
plugins {
4-
val kotlinVersion = "1.4.21"
4+
val kotlinVersion = "1.4.30"
55
kotlin("jvm") version kotlinVersion
66
kotlin("plugin.serialization") version kotlinVersion
77

8-
id("net.mamoe.mirai-console") version "2.4.0"
8+
id("net.mamoe.mirai-console") version "2.5.1"
99
id("org.jetbrains.dokka") version "1.4.0"
1010
}
1111

1212
group = "com.github.samarium150"
13-
version = "3.1.0"
13+
version = "3.2.0"
1414

1515
repositories {
1616
mavenLocal()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mirai-console-lolicon",
3-
"version": "3.1.0",
3+
"version": "3.2.0",
44
"description": "基于mirai-console的涩图机器人",
55
"scripts": {
66
"changelog": "conventional-changelog -p eslint -i CHANGELOG.md -s"

src/main/kotlin/Lolicon.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import net.mamoe.mirai.contact.Contact.Companion.uploadImage
3131
import net.mamoe.mirai.contact.Group
3232
import net.mamoe.mirai.contact.User
3333
import net.mamoe.mirai.message.data.FlashImage
34+
import java.io.File
35+
import java.io.InputStream
3436
import java.net.URL
3537

3638
/**
@@ -91,15 +93,24 @@ object Lolicon: CompositeCommand(
9193
return
9294
}
9395
val (apikey, r18, recall, cooldown) = ExecutionConfig.create(subject)
94-
val parameters = RequestParams(apikey, keyword, r18, size1200 = PluginConfig.size1200)
96+
val parameters = RequestParams(apikey, keyword, r18, 1, PluginConfig.proxy, PluginConfig.size1200)
9597
Main.logger.info(parameters.toReadable())
9698
try {
9799
val response: Response = RequestHandler.get(parameters)
98100
Main.logger.info(response.toReadable())
99101
for (imageData in response.data) {
100102
Main.logger.info("url: ${imageData.url}")
101103
sendMessage(imageData.toReadable())
102-
val stream = RequestHandler.download(imageData.url)
104+
val stream: InputStream = if (PluginConfig.save && PluginConfig.cache) {
105+
try {
106+
val paths = imageData.url.split("/")
107+
val path = "/data/mirai-console-lolicon/download/${paths[paths.lastIndex]}"
108+
val cache = File(System.getProperty("user.dir") + path)
109+
if (cache.exists()) cache.inputStream() else RequestHandler.download(imageData.url)
110+
} catch (e: Exception) {
111+
RequestHandler.download(imageData.url)
112+
}
113+
} else RequestHandler.download(imageData.url)
103114
val img = subject?.uploadImage(stream)
104115
if (img != null) {
105116
val receipt = (if (PluginConfig.flash) sendMessage(FlashImage(img)) else sendMessage(img)) ?: return

src/main/kotlin/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi
3737
object Main: KotlinPlugin(
3838
JvmPluginDescription(
3939
id = "com.github.samarium150.mirai-console-lolicon",
40-
version = "3.1.0",
40+
version = "3.2.0",
4141
name = "mirai-console-lolicon"
4242
)
4343
) {

src/main/kotlin/PluginConfig.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
4646
@ValueDescription("是否保存图片")
4747
val save: Boolean by value(false)
4848

49+
/**
50+
* Enable caching
51+
* <br>
52+
* 是否使用已保存的图片作为缓存
53+
*/
54+
@ValueDescription("是否使用已保存的图片作为缓存")
55+
val cache: Boolean by value(false)
56+
4957
/**
5058
* Enable flash image
5159
* <br>
@@ -70,6 +78,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
7078
@ValueDescription("是否启用master_1200图片压缩")
7179
val size1200: Boolean by value(true)
7280

81+
/**
82+
* Custom proxy
83+
* <br>
84+
* 自定义代理
85+
*/
86+
@ValueDescription("获取Pixiv图片的代理")
87+
val proxy: String by value("i.pixiv.cat")
88+
7389
/**
7490
* Default recall time
7591
* <br>

0 commit comments

Comments
 (0)