Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
fix: 修复诡异的图片生成
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Nov 7, 2020
1 parent c68883a commit 0f05203
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ class ArkNightCommand : ChatCommand {
val list = pool.getArkDrawResult(user)
if (list.isNotEmpty()) {
val result = DrawUtil.combineArkOpImage(list)
event.quoteReply(BotUtil.sendMessage("由于缺失资源文件, 以下干员无法显示 :(\n" +
buildString {
result.lostOps.forEach {
append("${it.name},")
}
removeSuffix(",")
}))
if (result.lostOps.isNotEmpty())
event.quoteReply(BotUtil.sendMessage("由于缺失资源文件, 以下干员无法显示 :(\n" +
buildString {
result.lostOps.forEach {
append("${it.name},")
}
removeSuffix(",")
}))
val gachaImage = withContext(Dispatchers.Default) { result.image.upload(event.subject) }
gachaImage.asMessageChain()
} else {
Expand All @@ -57,13 +58,14 @@ class ArkNightCommand : ChatCommand {
val list: List<ArkNightOperator> = pool.getArkDrawResult(user, 10)
if (list.isNotEmpty()) {
val result = DrawUtil.combineArkOpImage(list)
event.quoteReply(BotUtil.sendMessage("由于缺失资源文件, 以下干员无法显示 :(\n" +
buildString {
result.lostOps.forEach {
append("${it.name},")
}
removeSuffix(",")
}))
if (result.lostOps.isNotEmpty())
event.quoteReply(BotUtil.sendMessage("由于缺失资源文件, 以下干员无法显示 :(\n" +
buildString {
result.lostOps.forEach {
append("${it.name},")
}
removeSuffix(",")
}))
val gachaImage = withContext(Dispatchers.Default) { result.image.upload(event.subject) }
gachaImage.asMessageChain()
} else {
Expand Down
15 changes: 10 additions & 5 deletions src/main/kotlin/io/github/starwishsama/comet/utils/DrawUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object DrawUtil {
const val overTimeMessage = "抽卡次数到上限了, 可以少抽一点或者等待条数自动恢复哦~\n" +
"命令条数现在每小时会恢复100次, 封顶1000次"

// 干员名称/干员名称.png
// 资源下载链接, 文件位置: 干员名称/干员名称.png
private const val resourceUrl = "https://cdn.jsdelivr.net/gh/godofhuaye/arknight-assets@master/cg"

/**
Expand Down Expand Up @@ -82,17 +82,20 @@ object DrawUtil {
val lostOps: List<ArkNightOperator>
)

fun getStar(rare: Int): String = StringBuilder().apply {
fun getStar(rare: Int): String = buildString {
for (i in 0 until rare) {
append("")
}
}.toString()
}

fun checkHasGachaTime(user: BotUser, time: Int): Boolean =
(user.commandTime >= time || user.compareLevel(UserLevel.ADMIN)) && time <= 10000

fun downloadArkNightsFile() {
if (FileUtil.getResourceFolder().getChildFolder("ark").filesCount() < arkNight.size) {
// 安塞尔的资源不知为何没有
val actualSize = arkNight.size - 1

if (FileUtil.getResourceFolder().getChildFolder("ark").filesCount() < actualSize) {
val startTime = LocalDateTime.now()
daemonLogger.info("正在下载 明日方舟图片资源文件")

Expand All @@ -115,14 +118,16 @@ object DrawUtil {
} catch (e: Exception) {
if (e !is ApiException)
daemonLogger.warning("下载 $fileName 时出现了意外", e)
else
daemonLogger.warning("下载异常: ${e.message ?: "无信息"}")
return@forEach
} finally {
if (successCount > 0 && successCount % 10 == 0) {
daemonLogger.info("明日方舟 > 已下载 $successCount/${arkNight.size}")
}
}
}
daemonLogger.info("明日方舟 > 资源文件下载成功, 耗时 ${startTime.getLastingTime()}")
daemonLogger.info("明日方舟 > 资源文件下载成功 [$successCount/${actualSize}], 耗时 ${startTime.getLastingTime()}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.starwishsama.comet.utils.network
import cn.hutool.http.*
import io.github.starwishsama.comet.BotVariables.cfg
import io.github.starwishsama.comet.BotVariables.daemonLogger
import io.github.starwishsama.comet.exceptions.ApiException
import io.github.starwishsama.comet.utils.debugS
import io.github.starwishsama.comet.utils.network.NetUtil.proxyIsUsable
import org.openqa.selenium.*
Expand Down Expand Up @@ -136,7 +137,7 @@ object NetUtil {
`in`.close()
fos.close()
} else {
throw RuntimeException("在下载时发生了错误, 响应码 ${connUrl.responseCode}")
throw ApiException("在下载时发生了错误, 响应码 ${connUrl.responseCode}")
}

return file
Expand Down

0 comments on commit 0f05203

Please sign in to comment.