Skip to content

Commit

Permalink
feat: add custom caching and proxy options; fixes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Samarium150 committed Mar 30, 2021
1 parent 7712f53 commit 7d8d123
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
15 changes: 13 additions & 2 deletions src/main/kotlin/Lolicon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -91,15 +93,24 @@ 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)
Main.logger.info(response.toReadable())
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
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
@ValueDescription("是否保存图片")
val save: Boolean by value(false)

/**
* Enable caching
* <br>
* 是否使用已保存的图片作为缓存
*/
@ValueDescription("是否使用已保存的图片作为缓存")
val cache: Boolean by value(false)

/**
* Enable flash image
* <br>
Expand All @@ -70,6 +78,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
@ValueDescription("是否启用master_1200图片压缩")
val size1200: Boolean by value(true)

/**
* Custom proxy
* <br>
* 自定义代理
*/
@ValueDescription("获取Pixiv图片的代理")
val proxy: String by value("i.pixiv.cat")

/**
* Default recall time
* <br>
Expand Down

0 comments on commit 7d8d123

Please sign in to comment.