Skip to content

Commit

Permalink
Merge pull request #36 from cssxsh/re
Browse files Browse the repository at this point in the history
Restructure
  • Loading branch information
cssxsh authored Oct 1, 2022
2 parents a9e1bbf + 464d64c commit 104b918
Show file tree
Hide file tree
Showing 76 changed files with 3,082 additions and 3,834 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
/test/
/out/
/run/
*.log
*.log

debug-sandbox
52 changes: 41 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
plugins {
kotlin("jvm") version "1.6.21"
kotlin("plugin.serialization") version "1.6.21"
kotlin("jvm") version "1.7.20"
kotlin("plugin.serialization") version "1.7.20"

id("net.mamoe.mirai-console") version "2.12.0"
id("net.mamoe.maven-central-publish") version "0.7.1"
id("net.mamoe.mirai-console") version "2.12.3"
id("me.him188.maven-central-publish") version "1.0.0-dev-3"
}

group = "xyz.cssxsh"
version = "1.4.2"
version = "2.0.0-RC"

mavenCentralPublish {
useCentralS01()
singleDevGithubProject("cssxsh", "arknights-helper")
licenseFromGitHubProject("AGPL-3.0", "master")
workingDir = System.getenv("PUBLICATION_TEMP")?.let { file(it).resolve(projectName) }
?: buildDir.resolve("publishing-tmp")
publication {
artifact(tasks.getByName("buildPlugin"))
artifact(tasks.getByName("buildPluginLegacy"))
artifact(tasks["buildPlugin"])
}
}

Expand All @@ -25,11 +26,40 @@ repositories {
}

dependencies {
implementation("io.ktor:ktor-client-okhttp:1.6.8")
compileOnly("net.mamoe:mirai-core:2.12.0")
compileOnly("net.mamoe:mirai-core-utils:2.12.0")
implementation("io.ktor:ktor-client-okhttp-jvm:2.1.2") {
exclude(group = "org.jetbrains.kotlin")
exclude(group = "org.jetbrains.kotlinx")
exclude(group = "org.slf4j")
}
implementation("io.ktor:ktor-client-encoding-jvm:2.1.2") {
exclude(group = "org.jetbrains.kotlin")
exclude(group = "org.jetbrains.kotlinx")
exclude(group = "org.slf4j")
}
implementation("com.squareup.okhttp3:okhttp:4.10.0") {
exclude(group = "org.jetbrains.kotlin")
exclude(group = "org.jetbrains.kotlinx")
exclude(group = "org.slf4j")
}
implementation("com.cronutils:cron-utils:9.2.0") {
exclude("org.slf4j")
exclude("org.glassfish")
exclude("org.javassist")
}
implementation("org.jsoup:jsoup:1.15.3")
compileOnly("javax.validation:validation-api:2.0.1.Final")

testImplementation(kotlin("test"))
testImplementation("org.slf4j:slf4j-simple:2.0.1")
testImplementation("net.mamoe:mirai-logging-slf4j:2.12.3")
}

kotlin {
explicitApi()
}

testImplementation(kotlin("test", "1.6.21"))
mirai {
jvmTarget = JavaVersion.VERSION_11
}

tasks {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
115 changes: 41 additions & 74 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![MiraiForum](https://img.shields.io/badge/post-on%20MiraiForum-yellow)](https://mirai.mamoe.net/topic/203)

**使用前应该查阅的相关文档或项目**
**Arknights Helper 在2.0版本进行了重构 需要重新配置订阅 详见 方舟蹲饼**

* [User Manual](https://github.com/mamoe/mirai/blob/dev/docs/UserManual.md)
* [Permission Command](https://github.com/mamoe/mirai/blob/dev/mirai-console/docs/BuiltInCommands.md#permissioncommand)
Expand All @@ -21,10 +22,12 @@
`{...}`表示连续的多个参数

本插件指令权限ID 格式为 `xyz.cssxsh.mirai.plugin.arknights-helper:command.*`, `*` 是指令的第一指令名
例如 `/抽卡 十连` 的权限ID为 `xyz.cssxsh.mirai.plugin.arknights-helper:command.gacha`
例如 `/公招 远程位 支援` 的权限ID为 `xyz.cssxsh.mirai.plugin.arknights-helper:command.ark-recruit`

### 助手抽卡指令

**抽卡指令 2.0 版本重构中 咱不可用**

| 指令 | 描述 |
|:----------------------------------------------|:--------------------------------------------|
| `/<gacha 抽卡> <one 单抽> [times]?` | 单抽`times`次,默认为1 |
Expand Down Expand Up @@ -56,6 +59,8 @@ other:0.42

### 助手答题指令

**表情指令 2.0 版本重构中 咱不可用**

| 指令 | 描述 |
|:------------------------------------|:------------------|
| `/<mine 挖矿 答题> [type]?` | 机器人会提出一个问题 |
Expand All @@ -81,26 +86,28 @@ B. 选项

### 助手公招指令

| 指令 | 描述 |
|:------------------------|:------------------|
| `/<recruit 公招> {words}` | 查看关键词`words`的公招干员 |
| 指令 | 描述 |
|:------------------------------|:------------------|
| `/<ark-recruit 方舟公招> {words}` | 查看关键词`words`的公招干员 |

`words`的数量为1~5
* `words`的数量为1~5
例如 `/方舟公招 远程位 支援`

### 助手材料指令

| 指令 | 描述 |
|:------------------------------------------|:---------------|
| `/<item 材料> [name] [limit]? [now]?` | 查看材料的关卡掉落率 |
| `/<stage 关卡> [name] [limit]? [now]?` | 查看关卡的材料掉落率 |
| `/<zone 章节 活动 地图> [name] [limit]? [now]?` | 查看地图所有关卡的材料掉落率 |
| 指令 | 描述 |
|:-------------------------------------------|:---------------|
| `/<ark-item 方舟材料> [name] [limit]? [now]?` | 查看材料的关卡掉落率 |
| `/<ark-stage 方舟关卡> [name] [limit]? [now]?` | 查看关卡的材料掉落率 |
| `/<ark-zone 方舟章节> [name] [limit]? [now]?` | 查看地图所有关卡的材料掉落率 |

`limit` 是显示前多少项查询结果
`now` 是是否只显示当前开启关卡,默认为 `true`
可以通过配置[材料别名](#items)设置可选的材料索引
* `limit` 是显示前多少项查询结果
* `now` 是是否只显示当前开启关卡,默认为 `true`

### 助手玩家指令

**表情指令 2.0 版本重构中 咱不可用**

| 指令 | 描述 |
|:-----------------------------------------------------|:----------------------|
| `/<player 玩家> <detail 详情>` | 当前玩家(QQ号)在助手中的数据 |
Expand All @@ -114,34 +121,32 @@ B. 选项

### 助手蹲饼指令

| 指令 | 描述 |
|:------------------------------------|:-------------------|
| `/<guard 蹲饼> <detail 详情>` | 当前蹲饼的状态和轮询时间 |
| `/<guard 蹲饼> <speed 速度>` | 设置蹲饼轮询时间是`speed`分钟 |
| `/<guard 蹲饼> <open 打开> [contact]?` | 开启蹲饼状态 |
| `/<guard 蹲饼> <close 关闭> [contact]?` | 关闭蹲饼状态 |

`contact` 为群号或Q号,可选参数,可以自动从当前聊天环境中获取,比如私聊就获取好友Q号,群聊就获取群号
玩家的默认等级为`120`
理智的提醒时间会根据玩家等级和当前理智值`init`设置
| 指令 | 描述 |
|:--------------------------------------------------------|:---------|
| `/<ark-guard 方舟蹲饼> <detail 详情>` | 查看蹲饼详情 |
| `/<ark-guard 方舟蹲饼> <blog 微博> [contact] {blogs}` | 设置微博蹲饼内容 |
| `/<ark-guard 方舟蹲饼> <video 视频> [contact] {videos}` | 设置视频蹲饼内容 |
| `/<ark-guard 方舟蹲饼> <announce 公告> [contact] {announces}` | 设置视频蹲饼内容 |

* `contact` 为群号或Q号
* `blogs` 可选值为 `ARKNIGHTS`(官号), `BYPRODUCT`(朝陇山), `MOUNTEN`(一拾山), `HISTORICUS`(泰拉记事社)
例如 `/方舟蹲饼 微博 123456 ARKNIGHTS MOUNTEN`, 就订阅了官方号和一拾山
* `video` 可选值为 `ANIME, MUSIC, GAME, ENTERTAINMENT`
例如 `/方舟蹲饼 视频 123456 GAME MUSIC`, 就订阅了PV和音乐单曲
* `announce` 可选值为 `ANDROID, IOS, BILIBILI`
例如 `/方舟蹲饼 公告 123456 ANDROID`, 就订阅了官服的公告

### 助手数据指令

| 指令 | 描述 |
|:--------------------------------|:-------|
| `/<data 数据> <arknights 方舟>` | 更新游戏数据 |
| `/<data 数据> <penguin 企鹅 掉落>` | 更新掉落数据 |
| `/<data 数据> <name alias 别称 别名>` | 查看掉落别名 |
| `/<data 数据> <reload 重载>` | 重载插件配置 |
| `/<data 数据> <recruit alias 公招>` | 提交公招结果 |
| `/<data 数据> <tag 标签分析>` | 分析公招结果 |
| `/<data 数据> <role 干员分析>` | 分析公招结果 |
| `/<data 数据> <clear 清理>` | 清理数据 |

提交公招结果之前,可以设置[干员别名](#roles)方便输入
| 指令 | 描述 |
|:------------------------------|:-------|
| `/<ark-data 方舟数据> <clear 清理>` | 清理缓存 |
| `/<ark-data 方舟数据> <cron 定时>` | 重载定时设置 |

### 助手表情指令

**表情指令 2.0 版本重构中 咱不可用**

| 指令 | 描述 |
|:------------------------------------|:-----------------------------|
| `/<arkface 方舟表情> <random 随机> [id]?` | 随机发送一个表情, id是表情包id, 默认为任意表情包 |
Expand All @@ -154,44 +159,6 @@ B. 选项

位于`Mirai-Console`运行目录下的`config/xyz.cssxsh.mirai.plugin.arknights-helper`文件夹下的`config`文件

### roles

干员别名

```
roles:
小羊: 艾雅法拉
鳄鱼: 艾丝黛尔
```

### items

材料别名

```
items:
绿管: 晶体元件
```

### auto_add_guard

自动开启蹲饼功能 在机器人添加新好友和新群时自动开启蹲饼功能

### video

开启订阅的b站视频类型 `ANIME`, `MUSIC`, `GAME`, `ENTERTAINMENT`

### blog

开启订阅的微博号 `BYPRODUCT`(朝陇山), `MOUNTEN`(一拾山), `HISTORICUS`(泰拉记事社)

### source

游戏资源,可选值:
* `https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master`
* `https://raw.fastgit.org/Kengxxiao/ArknightsGameData/master`
* `https://cdn.jsdelivr.net/gh/Kengxxiao/ArknightsGameData@master`

## 安装

### MCL 指令安装
Expand All @@ -201,7 +168,7 @@ items:
### 手动安装

1. 运行 [Mirai Console](https://github.com/mamoe/mirai-console) 生成`plugins`文件夹
1.[Releases](https://github.com/cssxsh/arknights-helper/releases) 下载`jar`并将其放入`plugins`文件夹中
2.[Releases](https://github.com/cssxsh/arknights-helper/releases) 下载`jar`并将其放入`plugins`文件夹中

## TODO

Expand Down
68 changes: 68 additions & 0 deletions src/main/kotlin/xyz/cssxsh/arknights/CacheDataHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package xyz.cssxsh.arknights

import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.compression.*
import io.ktor.client.plugins.cookies.*
import io.ktor.client.statement.*
import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.*
import kotlinx.coroutines.sync.*
import kotlinx.serialization.*
import java.io.File

public abstract class CacheDataHolder<K : CacheKey, R : CacheInfo> {
protected open val mutex: Mutex = Mutex()
protected open val http: HttpClient = HttpClient(OkHttp) {
BrowserUserAgent()
ContentEncoding()
expectSuccess = true
install(HttpTimeout) {
socketTimeoutMillis = 30_000
connectTimeoutMillis = 30_000
requestTimeoutMillis = null
}
install(HttpCookies) {
storage = AcceptAllCookiesStorage()
}
}
public abstract val folder: File

protected abstract val cache: MutableMap<K, *>

public abstract suspend fun load(key: K)

public abstract suspend fun raw(key: K): List<R>

public abstract suspend fun clear()

protected abstract val ignore: suspend (exception: Throwable) -> Boolean

protected val CacheKey.file: File get() = folder.resolve(filename)

protected suspend inline fun <reified T> K.read(): T = mutex.withLock {
return CustomJson.decodeFromString(file.readText())
}

protected suspend inline fun <reified T> K.write(data: T): Unit = mutex.withLock {
file.writeText(CustomJson.encodeToString(data))
}

protected suspend fun HttpStatement.copyTo(target: File): Unit = supervisorScope {
while (isActive) {
try {
execute { response ->
target.outputStream().use { output ->
val channel = response.bodyAsChannel()

while (!channel.isClosedForRead) channel.copyTo(output)
}
}
break
} catch (cause: Throwable) {
if (ignore(cause).not()) throw cause
}
}
}
}
8 changes: 8 additions & 0 deletions src/main/kotlin/xyz/cssxsh/arknights/CacheInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package xyz.cssxsh.arknights

import java.time.OffsetDateTime

public interface CacheInfo {
public val created: OffsetDateTime
public val url: String
}
7 changes: 7 additions & 0 deletions src/main/kotlin/xyz/cssxsh/arknights/CacheKey.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package xyz.cssxsh.arknights


public interface CacheKey {
public val filename: String
public val url: String
}
Loading

0 comments on commit 104b918

Please sign in to comment.