Skip to content

Commit

Permalink
修复nga炸了的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
diyigemt committed Aug 26, 2022
1 parent 77f6218 commit a57271a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Please note that for various reasons, developers may **stop updating** or **dele

## 更新日志

2022-08-26 v1.0.6

1. 添加配置项nga.yml->source,可选择nga的数据来源,紧急修复nga主站(ngabbs.com)炸了的问题,默认选择副站

2022-08-21 v1.0.5

1. 添加配置项arona.yml->endWithSensei允许用户设置称呼系统的后缀,默认是"老师"(保留人设)
Expand Down Expand Up @@ -473,6 +477,7 @@ NGA图楼推送配置,具体配置方法可以看[下面](#nga-config)
| uid | String | 你自己的nga uid |
| cid | String | 你自己的nga cid |
| checkInterval | Int | 扫描周期,单位min |
| source | MAIN / SUB | 配置nga数据来源,可选MAIN或SUB,防止nga炸了 |
| watch | Map<Int, String> | 监听的nga cid(无须修改) |
| cache | List<Pair<Int, String>> | 已经推送过的楼层缓存(无须修改) |

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "net.diyigemt.arona"
version = "1.0.5"
version = "1.0.6"
val miraiVersion = "2.11.1"
val exposedVersion = "0.38.2"
val sqliteVersion = "3.36.0.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ object NGAImageTranslatePusher : AronaQuartzService {
}
}
val cache = NGAPushConfig.cache
val isNew = cache.isEmpty()
val pending = fetchNGA.filter {
!cache.any { c -> c.second == it.postId }
}.also {
if (it.isEmpty()) return
}
updateCache(cache, pending)
val init = context?.mergedJobDataMap?.getBooleanValue(ImageTranslateCheckInitKey) ?: false
if (init) {
if (init && isNew) {
return
}
pending.map { floor ->
Expand Down Expand Up @@ -94,7 +95,7 @@ object NGAImageTranslatePusher : AronaQuartzService {
val random = Calendar.getInstance().time.time - Random().nextInt(25) + 5
cookies["lastvisit"] = random.toString()
cookies["lastpath"] = "/read.php?tid=${cookies["ngaPassportUid"]}"
val body = Jsoup.connect("https://ngabbs.com/read.php?tid=30843163")
val body = Jsoup.connect("https://${NGAPushConfig.source.url}/read.php?tid=30843163")
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36")
.ignoreContentType(true)
.cookies(cookies)
Expand Down Expand Up @@ -162,7 +163,7 @@ object NGAImageTranslatePusher : AronaQuartzService {
return@map builder
.name(it.key)
.value(it.value)
.domain("ngabbs.com")
.domain(NGAPushConfig.source.url)
.path("/")
.build()
}
Expand All @@ -171,6 +172,10 @@ object NGAImageTranslatePusher : AronaQuartzService {
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {}
}

enum class NGASource(val url: String) {
MAIN("ngabbs.com"), SUB("nga.178.com")
}

override fun init() {
registerService()
}
Expand All @@ -180,14 +185,14 @@ object NGAImageTranslatePusher : AronaQuartzService {
Arona.warning("nga推送配置未初始化,请修改nga.yml配置文件")
return
}
cookies["ngaPassportUid"] = NGAPushConfig.uid
cookies["ngaPassportCid"] = NGAPushConfig.cid
jobKey = QuartzProvider.createRepeatSingleTask(
TranslatePusherJob::class.java,
NGAPushConfig.checkInterval,
ImageTranslateCheckJobKey,
ImageTranslateCheckJobKey
).first
cookies["ngaPassportUid"] = NGAPushConfig.uid
cookies["ngaPassportCid"] = NGAPushConfig.cid
QuartzProvider.createSimpleDelayJob(20) {
QuartzProvider.triggerTaskWithData(jobKey, mapOf(ImageTranslateCheckInitKey to true))
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/net/diyigemt/arona/config/NGAPushConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.diyigemt.arona.config

import net.diyigemt.arona.advance.NGAImageTranslatePusher
import net.mamoe.mirai.console.data.AutoSavePluginConfig
import net.mamoe.mirai.console.data.ValueDescription
import net.mamoe.mirai.console.data.value
Expand All @@ -15,6 +16,9 @@ object NGAPushConfig: AutoSavePluginConfig("nga") {
@ValueDescription("扫描周期(单位min)")
val checkInterval: Int by value(30)

@ValueDescription("数据源(主站寄了的时候可以换一下),可选\"MAIN\"(主站)和\"SUB\"(备用站)")
val source: NGAImageTranslatePusher.NGASource by value(NGAImageTranslatePusher.NGASource.SUB)

@ValueDescription("要监听的发送者uid以及nga昵称")
val watch: MutableMap<String, String> by value(
mutableMapOf(
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
id: "net.diyigemt.arona"
version: "1.0.5"
version: "1.0.6"
name: "ba-activity-pusher"
author: "diyigemt"
info: "BA日服/国际服活动推送插件"

0 comments on commit a57271a

Please sign in to comment.