diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1d63e11..4499cba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+# [3.2.0](https://github.com/Samarium150/mirai-console-lolicon/compare/3.1.0...3.2.0) (2021-03-30)
+
+
+### feat
+
+* add custom caching and proxy options ([de09441](https://github.com/Samarium150/mirai-console-lolicon/commit/de09441ba3b8633c2b155ee166ef592806f97085))
+
+
+
# [3.1.0](https://github.com/Samarium150/mirai-console-lolicon/compare/3.0.1...3.1.0) (2021-02-15)
diff --git a/build.gradle.kts b/build.gradle.kts
index f93afbc..909ae1a 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,16 +1,16 @@
import java.net.URL
plugins {
- val kotlinVersion = "1.4.21"
+ val kotlinVersion = "1.4.30"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
- id("net.mamoe.mirai-console") version "2.4.0"
+ id("net.mamoe.mirai-console") version "2.5.1"
id("org.jetbrains.dokka") version "1.4.0"
}
group = "com.github.samarium150"
-version = "3.1.0"
+version = "3.2.0"
repositories {
mavenLocal()
diff --git a/package.json b/package.json
index 5f42df4..1950b94 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mirai-console-lolicon",
- "version": "3.1.0",
+ "version": "3.2.0",
"description": "基于mirai-console的涩图机器人",
"scripts": {
"changelog": "conventional-changelog -p eslint -i CHANGELOG.md -s"
diff --git a/src/main/kotlin/Lolicon.kt b/src/main/kotlin/Lolicon.kt
index 192ee37..577d176 100644
--- a/src/main/kotlin/Lolicon.kt
+++ b/src/main/kotlin/Lolicon.kt
@@ -31,6 +31,8 @@ import net.mamoe.mirai.contact.Contact.Companion.uploadImage
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.User
import net.mamoe.mirai.message.data.FlashImage
+import java.io.File
+import java.io.InputStream
import java.net.URL
/**
@@ -91,7 +93,7 @@ object Lolicon: CompositeCommand(
return
}
val (apikey, r18, recall, cooldown) = ExecutionConfig.create(subject)
- val parameters = RequestParams(apikey, keyword, r18, size1200 = PluginConfig.size1200)
+ val parameters = RequestParams(apikey, keyword, r18, 1, PluginConfig.proxy, PluginConfig.size1200)
Main.logger.info(parameters.toReadable())
try {
val response: Response = RequestHandler.get(parameters)
@@ -99,7 +101,16 @@ object Lolicon: CompositeCommand(
for (imageData in response.data) {
Main.logger.info("url: ${imageData.url}")
sendMessage(imageData.toReadable())
- val stream = RequestHandler.download(imageData.url)
+ val stream: InputStream = if (PluginConfig.save && PluginConfig.cache) {
+ try {
+ val paths = imageData.url.split("/")
+ val path = "/data/mirai-console-lolicon/download/${paths[paths.lastIndex]}"
+ val cache = File(System.getProperty("user.dir") + path)
+ if (cache.exists()) cache.inputStream() else RequestHandler.download(imageData.url)
+ } catch (e: Exception) {
+ RequestHandler.download(imageData.url)
+ }
+ } else RequestHandler.download(imageData.url)
val img = subject?.uploadImage(stream)
if (img != null) {
val receipt = (if (PluginConfig.flash) sendMessage(FlashImage(img)) else sendMessage(img)) ?: return
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index 0b710d1..9b7a127 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -37,7 +37,7 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi
object Main: KotlinPlugin(
JvmPluginDescription(
id = "com.github.samarium150.mirai-console-lolicon",
- version = "3.1.0",
+ version = "3.2.0",
name = "mirai-console-lolicon"
)
) {
diff --git a/src/main/kotlin/PluginConfig.kt b/src/main/kotlin/PluginConfig.kt
index f2f951b..59eebed 100644
--- a/src/main/kotlin/PluginConfig.kt
+++ b/src/main/kotlin/PluginConfig.kt
@@ -46,6 +46,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
@ValueDescription("是否保存图片")
val save: Boolean by value(false)
+ /**
+ * Enable caching
+ *
+ * 是否使用已保存的图片作为缓存
+ */
+ @ValueDescription("是否使用已保存的图片作为缓存")
+ val cache: Boolean by value(false)
+
/**
* Enable flash image
*
@@ -70,6 +78,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
@ValueDescription("是否启用master_1200图片压缩")
val size1200: Boolean by value(true)
+ /**
+ * Custom proxy
+ *
+ * 自定义代理
+ */
+ @ValueDescription("获取Pixiv图片的代理")
+ val proxy: String by value("i.pixiv.cat")
+
/**
* Default recall time
*