Skip to content

Commit

Permalink
Not caching received image by default. Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuueexxiinngg committed Aug 13, 2020
1 parent ba754b2 commit 90e5e31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ __CQHTTP runs on Mirai__
debug: false
# 要进行配置的QQ号 (Mirai支持多帐号登录, 故需要对每个帐号进行单独设置)
'1234567890':
# 是否缓存所有收到的图片, 默认为否 (仅包含图片信息, 不包含图片本身, < 0.5KB)
cacheImage: false
# HTTP 相关配置
http:
# 可选,是否启用HTTP API服务器, 默认为不启用, 此项开始与否跟postUrl无关
Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/tech/mihoyo/mirai/PluginBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ object PluginBase : PluginBase() {
session.cqApiImpl.cachedTempContact[this.sender.id] = this.group.id
}

val shouldCacheImage =
if (session.config.containsKey("cacheImage")) session.config.getBoolean("cacheImage") else true

if (shouldCacheImage) {
if (session.shouldCacheImage) {
message.filterIsInstance<Image>().forEach { image ->
val delegate = image::class.members.find { it.name == "delegate" }?.call(image)
var imageMD5 = ""
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/tech/mihoyo/mirai/web/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.ktor.util.*
import kotlinx.coroutines.*
import net.mamoe.mirai.Bot
import net.mamoe.mirai.console.plugins.ConfigSection
import tech.mihoyo.mirai.util.logger
import tech.mihoyo.mirai.web.http.HttpApiServer
import tech.mihoyo.mirai.web.websocket.WebSocketReverseClient
import tech.mihoyo.mirai.web.websocket.WebSocketServer
Expand Down Expand Up @@ -51,11 +52,17 @@ abstract class Session internal constructor(
@KtorExperimentalAPI
class BotSession internal constructor(val bot: Bot, val config: ConfigSection, coroutineContext: CoroutineContext) :
Session(coroutineContext, bot.id) {
val shouldCacheImage = if (config.containsKey("cacheImage")) config.getBoolean("cacheImage") else false
val cqApiImpl = MiraiApi(bot)
val httpApiServer = HttpApiServer(this)
val websocketClient = WebSocketReverseClient(this)
val websocketServer = WebSocketServer(this)

init {
if(shouldCacheImage) logger.info("Bot: ${bot.id} 已开启接收图片缓存, 将会缓存收取到的所有图片")
else logger.info("Bot: ${bot.id} 未开启接收图片缓存, 将不会缓存收取到的所有图片, 如需开启, 请在当前Bot配置中添加cacheImage=true")
}

override fun close() {
websocketClient.close()
websocketServer.close()
Expand Down

0 comments on commit 90e5e31

Please sign in to comment.