mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-02 05:17:26 +00:00
Compare commits
8 Commits
optimize-s
...
master
Author | SHA1 | Date | |
---|---|---|---|
d274b7c402 | |||
0a4c26aded | |||
7bd9e1c410 | |||
cc4eeac728
|
|||
6b47e19569
|
|||
24ff4b214e | |||
bf8de1ac1e | |||
a7c434da61 |
@ -5,7 +5,7 @@ ENV jarFileName=ContentGrabbingJi-exec.jar
|
|||||||
ENV CGJ_REDIS_URI="127.0.0.1:6379"
|
ENV CGJ_REDIS_URI="127.0.0.1:6379"
|
||||||
ENV CGJ_PROXY=""
|
ENV CGJ_PROXY=""
|
||||||
RUN mkdir /data/
|
RUN mkdir /data/
|
||||||
ENTRYPOINT ["/usr/java/openjdk-14/bin/java", "-Duser.timezone=Aisa/Shanghai"]
|
ENTRYPOINT ["/usr/java/openjdk-14/bin/java", "-Duser.timezone=GMT+8"]
|
||||||
CMD ["-Dcgj.logsPath=/data/logs", "-jar", "/CGJ.jar", "botMode", "-botDataDir=/data"]
|
CMD ["-Dcgj.logsPath=/data/logs", "-jar", "/CGJ.jar", "botMode", "-botDataDir=/data"]
|
||||||
|
|
||||||
COPY ${jarFileName} /CGJ.jar
|
COPY ${jarFileName} /CGJ.jar
|
||||||
|
47
README.md
47
README.md
@ -1,20 +1,19 @@
|
|||||||
# ContentGrabbingJi - 色图姬 #
|
# ContentGrabbingJi - 色图姬 #
|
||||||
一个以高性能、高效率为目标,多平台/框架支持、持续维护的Pixiv聊天机器人
|
一个以高性能、高效率为目标,多平台/框架支持、持续维护的 Pixiv 聊天机器人;
|
||||||
|
|
||||||
色图姬存在的目的最初是作为**爬虫 + 机器人**的形式开发,在开发过程中逐渐以多聊天平台,高效率为目标进行。
|
色图姬存在的目的最初是作为**爬虫 + 机器人**的形式开发,在开发过程中逐渐以多聊天平台,高效率为目标进行。
|
||||||
|
|
||||||
## 安装 ##
|
## 安装 ##
|
||||||
### 通过Jar文件部署 ###
|
### 通过 Jar 文件部署 ###
|
||||||
1. 从项目的[版本页面](https://github.com/LamGC/ContentGrabbingJi/releases)下载最新版色图姬主程序jar文件
|
1. 从项目的[版本页面](https://github.com/LamGC/ContentGrabbingJi/releases)下载最新版色图姬主程序 jar 文件。
|
||||||
2. 准备一个目录, 用于存放运行数据(这里以`./runData`为例子).
|
2. 准备一个目录,用于存放运行数据(这里以 `./runData` 为例子)。
|
||||||
3. 将通过PixivLoginProxyServer获得的Pixiv登录会话文件放置在目录中(`./runData/cookies.store`).
|
3. 将通过 PixivLoginProxyServer 获得的 Pixiv 登录会话文件放置在目录中(`./runData/cookies.store`)。
|
||||||
4. 使用命令`java -jar <CGJ.jar> buildPassword -password "QQ机器人账号的密码"`构造一个登录用的密码.
|
4. 使用命令 `java -jar <CGJ.jar> buildPassword -password "QQ机器人账号的密码"` 构造一个登录用的密码。
|
||||||
5. 在数据目录创建一个配置文件`bot.properties`, 并添加如下内容:
|
5. 在数据目录创建一个配置文件 `bot.properties`,并添加如下内容:
|
||||||
```properties
|
```properties
|
||||||
bot.qq=<机器人QQ账号>
|
bot.qq=<机器人QQ账号>
|
||||||
bot.password=<通过buildPassword获得的密码>
|
bot.password=<通过buildPassword获得的密码>
|
||||||
```
|
```
|
||||||
6. 在数据目录创建新文件夹`setting`, 并创建一个全局配置文件`global.properties`, 然后设置如下内容:
|
6. 在数据目录创建新文件夹 `setting`,并创建一个全局配置文件 `global.properties`,然后设置如下内容:
|
||||||
```properties
|
```properties
|
||||||
# 该配置为全局配置文件, 当群组没有特定配置时, 将使用全局配置.
|
# 该配置为全局配置文件, 当群组没有特定配置时, 将使用全局配置.
|
||||||
# 管理员QQ (必填)
|
# 管理员QQ (必填)
|
||||||
@ -30,12 +29,14 @@
|
|||||||
# 搜索结果长度. 该选项请适当调整, 设置过长可能导致超出聊天平台的最长消息长度, 导致发送失败!
|
# 搜索结果长度. 该选项请适当调整, 设置过长可能导致超出聊天平台的最长消息长度, 导致发送失败!
|
||||||
search.itemCountLimit=8
|
search.itemCountLimit=8
|
||||||
```
|
```
|
||||||
7. 配置完成后, 准备一台Redis服务端, 用于缓存数据.
|
(管理员 QQ 的作用/用法将在下面详细说明。)
|
||||||
8. Redis服务器准备好后, 使用命令启动色图姬:`java -jar <CGJ.jar> botMode -botDataDir <数据目录> -redisAddress <Redis服务器地址> [-proxy 代理服务器地址]`
|
7. 配置完成后,准备一台 Redis 服务端,用于缓存数据。
|
||||||
|
8. Redis 服务器准备好后,使用命令启动色图姬:
|
||||||
|
`java -jar <CGJ.jar> botMode -botDataDir <数据目录> -redisAddress <Redis服务器地址> [-proxy 代理服务器地址]`
|
||||||
9. 完成!好好享受!
|
9. 完成!好好享受!
|
||||||
|
|
||||||
### 通过Docker部署 ###
|
### 通过 Docker 部署 ###
|
||||||
使用Docker将可以更好的管理色图姬所使用的资源,和管理色图姬的运行。
|
使用 Docker 将可以更好的管理色图姬所使用的资源,和管理色图姬的运行。
|
||||||
(正在完善中...)
|
(正在完善中...)
|
||||||
|
|
||||||
## 使用 ##
|
## 使用 ##
|
||||||
@ -51,14 +52,17 @@
|
|||||||
如果色图姬无法识别你的命令,那么它会发送一次帮助信息给你。
|
如果色图姬无法识别你的命令,那么它会发送一次帮助信息给你。
|
||||||
|
|
||||||
### 管理员用户 ###
|
### 管理员用户 ###
|
||||||
你应该注意到了,在部署过程中,你需要设置一个管理员QQ的配置,色图姬支持通过命令来管理色图姬的运行。
|
你应该注意到了,在部署过程中,你需要设置一个管理员 QQ 的配置,色图姬支持通过命令来管理色图姬的运行。
|
||||||
目前支持的管理员命令:
|
目前支持的管理员命令:
|
||||||
```bash
|
```bash
|
||||||
# 清除缓存
|
# 清除缓存(慎用)
|
||||||
|
# 该操作将会清除Redis服务器内的所有数据, 以及色图姬下载到本地的所有图片缓存.
|
||||||
.cgjadmin cleanCache
|
.cgjadmin cleanCache
|
||||||
|
|
||||||
# 设置配置项
|
# 设置配置项
|
||||||
# 如果不使用group参数, 则设置全局配置
|
# 如果不使用group参数, 则设置全局配置
|
||||||
|
# 注意: 配置项设置后需要使用`.cgjadmin saveProperties`才会保存到文件中,
|
||||||
|
# 如不保存, 则仅能在本次运行中生效(或使用`.cgjadmin loadProperties`重新加载后失效).
|
||||||
.cgjadmin setProperty <-key 配置项名> <-value 配置项新值> [-group 指定群组]
|
.cgjadmin setProperty <-key 配置项名> <-value 配置项新值> [-group 指定群组]
|
||||||
|
|
||||||
# 查询配置项
|
# 查询配置项
|
||||||
@ -79,7 +83,8 @@
|
|||||||
# 增加群组作品推送
|
# 增加群组作品推送
|
||||||
# 如果增加了original参数, 则图片为原图发送
|
# 如果增加了original参数, 则图片为原图发送
|
||||||
# 如果不指定group参数, 则群组为命令发送所在群组
|
# 如果不指定group参数, 则群组为命令发送所在群组
|
||||||
.cgjadmin addPushGroup [-group 指定群组号] [-minTime 最小] [-floatTime 随机时间范围] [-rankingStart 排行榜起始排名]
|
# 最长发送时间 = 最短发送时间 + 随机时间范围
|
||||||
|
.cgjadmin addPushGroup [-group 指定群组号] [-minTime 最短发送时间] [-floatTime 随机时间范围] [-rankingStart 排行榜起始排名]
|
||||||
[-rankingStop 排行榜结束排名] [-mode 排行榜模式] [-type 排行榜类型] [-original]
|
[-rankingStop 排行榜结束排名] [-mode 排行榜模式] [-type 排行榜类型] [-original]
|
||||||
|
|
||||||
# 删除群组推送功能
|
# 删除群组推送功能
|
||||||
@ -102,13 +107,13 @@
|
|||||||
```
|
```
|
||||||
|
|
||||||
## 贡献 ##
|
## 贡献 ##
|
||||||
向色图姬贡献不一定需要编程知识,向色图姬项目提出意见,反馈问题同样会为色图姬项目提供很大的帮助!
|
**向色图姬贡献不一定需要编程知识,向色图姬项目提出意见,反馈问题同样会为色图姬项目提供很大的帮助!**
|
||||||
如果你在使用色图姬的过程中,遇到了Bug,可以通过色图姬项目的**Issues**使用[Bug反馈模板](https://github.com/LamGC/ContentGrabbingJi/issues/new?assignees=&labels=bug&template=Bug_Report.md&title=)向色图姬提供Bug信息。
|
如果你在使用色图姬的过程中,遇到了 Bug,可以通过色图姬项目的 **Issues** 使用[ Bug 反馈模板](https://github.com/LamGC/ContentGrabbingJi/issues/new?assignees=&labels=bug&template=Bug_Report.md&title=)向色图姬提供 Bug 信息。
|
||||||
如果是为色图姬提供一些新功能想法,或者对色图姬有什么意见,则可以直接通过Issues发起讨论。
|
如果是为色图姬提供一些新功能想法,或者对色图姬有什么意见,则可以使用[功能/意见提议模板](https://github.com/LamGC/ContentGrabbingJi/issues/new?assignees=&labels=function%2C+question&template=Feature_Report.md&title=)反馈你的想法!
|
||||||
|
|
||||||
如果你会Java开发,又想为色图姬提供一些新功能,可以通过Fork仓库的方法,实现后发起PR,合并到色图姬项目中!
|
如果你会 Java 开发,又想为色图姬提供一些新功能,可以通过 Fork 仓库的方法,实现后发起 PR,合并到色图姬项目中!
|
||||||
向色图姬贡献代码,需要遵循一些贡献事项,如果你的代码不符合这些事项,PR有可能会被关闭!
|
向色图姬贡献代码,需要遵循一些贡献事项,如果你的代码不符合这些事项,PR有可能会被关闭!
|
||||||
> 注意:色图姬的初衷并没有任何恶意的意图,如果尝试向色图姬提供恶意功能或代码,PR将会被拒绝、关闭。
|
> 注意:色图姬的初衷并没有任何恶意的意图,如果尝试向色图姬提供恶意功能或代码,PR 将会被拒绝、关闭。
|
||||||
|
|
||||||
## LICENSE ##
|
## LICENSE ##
|
||||||
本项目基于 `GNU Affero General Public License 3.0` 开源许可协议开源,
|
本项目基于 `GNU Affero General Public License 3.0` 开源许可协议开源,
|
||||||
|
@ -41,16 +41,15 @@ GET https://www.pixiv.net/ranking.php
|
|||||||
:-: |:-:| :-: | :-: | :-:
|
:-: |:-:| :-: | :-: | :-:
|
||||||
daily |`√`|`√`|`√`|`√`
|
daily |`√`|`√`|`√`|`√`
|
||||||
weekly |`√`|`√`|`√`|`√`
|
weekly |`√`|`√`|`√`|`√`
|
||||||
monthly |`√`|`√`|×|`√`
|
monthly |`√`|`√`| × |`√`
|
||||||
rookie |`√`|`√`|×|`√`
|
rookie |`√`|`√`| × |`√`
|
||||||
original |`√`|×|×|×
|
original |`√`| × | × | ×
|
||||||
male |`√`|×|×|×
|
male |`√`| × | × | ×
|
||||||
female |`√`|×|×|×
|
female |`√`| × | × | ×
|
||||||
daily_r18 |`√`|`√`|`√`|`√`
|
daily_r18 |`√`|`√`|`√`|`√`
|
||||||
weekly_r18|`√`|`√`|`√`|`√`
|
weekly_r18|`√`|`√`|`√`|`√`
|
||||||
male_r18 |`√`|×|×|×
|
male_r18 |`√`| × | × | ×
|
||||||
female_r18|`√`|×|×|×
|
female_r18|`√`| × | × | ×
|
||||||
|
|
||||||
|
|
||||||
### 返回数据 ###
|
### 返回数据 ###
|
||||||
#### 数据示例 ####
|
#### 数据示例 ####
|
||||||
|
@ -16,14 +16,17 @@ GET https://www.pixiv.net/ajax/search/{Type}/{Content}?{Param...}
|
|||||||
### 参数 ###
|
### 参数 ###
|
||||||
#### Url参数 ####
|
#### Url参数 ####
|
||||||
- `Type`: 内容类型
|
- `Type`: 内容类型
|
||||||
- illustrations(插画)
|
- `artworks` - 所有类型
|
||||||
- top(推荐)
|
- `top` - 推荐
|
||||||
- manga(漫画)
|
- `illustrations` - 插画
|
||||||
- novels(小说)
|
- `manga` - 漫画
|
||||||
|
- `novels` - 小说
|
||||||
|
- `tags` - 查询标签信息
|
||||||
- `Content`: 搜索内容
|
- `Content`: 搜索内容
|
||||||
|
|
||||||
#### GET参数 ####
|
#### GET参数 ####
|
||||||
##### 必填 #####
|
##### 必填 #####
|
||||||
|
> 注意:除 `tags` 类型外,其他内容类型都需要以下参数。
|
||||||
- `word`: 与搜索内容一致 (经测试似乎可以省略)
|
- `word`: 与搜索内容一致 (经测试似乎可以省略)
|
||||||
- `s_mode`: 匹配模式
|
- `s_mode`: 匹配模式
|
||||||
- `s_tag`: 标签,部分一致
|
- `s_tag`: 标签,部分一致
|
||||||
@ -82,7 +85,8 @@ GET https://www.pixiv.net/ajax/search/{Type}/{Content}?{Param...}
|
|||||||
"風景",
|
"風景",
|
||||||
"空",
|
"空",
|
||||||
"草",
|
"草",
|
||||||
"雲"],
|
"雲"
|
||||||
|
],
|
||||||
"userId":"31507675",
|
"userId":"31507675",
|
||||||
"userName":"昏omeme",
|
"userName":"昏omeme",
|
||||||
"width":1600,
|
"width":1600,
|
||||||
@ -155,7 +159,8 @@ GET https://www.pixiv.net/ajax/search/{Type}/{Content}?{Param...}
|
|||||||
"女の子",
|
"女の子",
|
||||||
"カラス",
|
"カラス",
|
||||||
"风景",
|
"风景",
|
||||||
"線路"],
|
"線路"
|
||||||
|
],
|
||||||
"userId":"1069005",
|
"userId":"1069005",
|
||||||
"userName":"へちま",
|
"userName":"へちま",
|
||||||
"width":2000,
|
"width":2000,
|
||||||
@ -310,24 +315,10 @@ GET https://www.pixiv.net/ajax/search/{Type}/{Content}?{Param...}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
> 注意:根据 Url 参数中 `Type` 的不同,返回数据的属性也会出现差异,
|
||||||
|
详见字段说明下的【请求 Url 中的 Type 与返回数据中属性的关系】表格
|
||||||
|
|
||||||
#### 字段说明 ####
|
#### 字段说明 ####
|
||||||
- `novel`: (`Object`) 小说搜索结果
|
|
||||||
- `data`: (`Object`) 搜索结果(仅当前页数)
|
|
||||||
- (待补充)
|
|
||||||
- `total`: (`number`) 搜索结果总量
|
|
||||||
- `popular`: (`Object`) 受欢迎的搜索结果
|
|
||||||
- `relatedTags`: (`string[]`) 与搜索结果相关的标签
|
|
||||||
- `tagTranslation`: (`Object`) 相关标签的翻译信息
|
|
||||||
- `{Attr: 标签名}`: 标签名为属性名
|
|
||||||
- `语言名(例如 中文是 zh)`: (`string`) 标签翻译名
|
|
||||||
- `zoneConfig`: (`Object`) 猜测是广告相关信息?
|
|
||||||
- `extraData`: (`Object`) 扩展信息
|
|
||||||
- `meta`: (`Object`) 网页元数据
|
|
||||||
- `title`: (`string`) 网页标题
|
|
||||||
- `description`: 搜索结果说明内容
|
|
||||||
- `descriptionHeader`: (`string`) 说明内容的Html代码
|
|
||||||
- `alternateLanguages`: (`Object`) 不明链接?
|
|
||||||
- `{语言名}`: 对应语言的链接
|
|
||||||
- `illustManga`: (`Object`) 漫画和插画的搜索结果
|
- `illustManga`: (`Object`) 漫画和插画的搜索结果
|
||||||
- `total`: (`number`) 搜索结果总量
|
- `total`: (`number`) 搜索结果总量
|
||||||
- `data`: (`Object[]`) 搜索结果(仅当前页数)
|
- `data`: (`Object[]`) 搜索结果(仅当前页数)
|
||||||
@ -362,4 +353,45 @@ GET https://www.pixiv.net/ajax/search/{Type}/{Content}?{Param...}
|
|||||||
- `createDate`: (`string`) 作品创建时间(或者是完成时间?)
|
- `createDate`: (`string`) 作品创建时间(或者是完成时间?)
|
||||||
- `updateDate`: (`string`) 作品上传时间
|
- `updateDate`: (`string`) 作品上传时间
|
||||||
- `profileImageUrl`: (`string`) 作者用户头像图片链接
|
- `profileImageUrl`: (`string`) 作者用户头像图片链接
|
||||||
|
- `bookmarkRanges`: (`Object[]`) 收藏数范围(推测是用于按收藏数搜索而使用)
|
||||||
|
- `min`: (`number`) 最小收藏数, 值为 `null` 则无限制
|
||||||
|
- `max`: (`number`) 最大收藏数, 值为 `null` 则无限制
|
||||||
|
- `illust`: (`Object`) 插画作品搜索结果
|
||||||
|
- **与`illustManga`结构相同**
|
||||||
|
- `manga`: (`Object`) 漫画作品搜索结果
|
||||||
|
- **与`illustManga`结构相同**
|
||||||
|
- `novel`: (`Object`) 小说搜索结果
|
||||||
|
- **与`illustManga`结构相同**
|
||||||
|
- `popular`: (`Object`) 受欢迎的搜索结果
|
||||||
|
- `recent`: (`Object[]`) 近期推荐
|
||||||
|
- **与`illustManga.data.{element}`结构相同**
|
||||||
|
- `permanent`: (`Object[]`) 旧作品推荐
|
||||||
|
- **与`illustManga.data.{element}`结构相同**
|
||||||
|
- `relatedTags`: (`string[]`) 与搜索结果相关的原始标签名
|
||||||
|
- `tagTranslation`: (`Object`) 相关标签的翻译信息
|
||||||
|
- `{Attr: 标签名}`: 标签名为属性名, 对应 `relatedTags` 中的原始标签名
|
||||||
|
- `语言名(例如 中文是 zh)`: (`string`) 标签翻译名
|
||||||
|
- `zoneConfig`: (`Object`) 猜测是广告相关信息?
|
||||||
|
- `extraData`: (`Object`) 扩展信息
|
||||||
|
- `meta`: (`Object`) 网页元数据
|
||||||
|
- `title`: (`string`) 网页标题
|
||||||
|
- `description`: 搜索结果说明内容
|
||||||
|
- `descriptionHeader`: (`string`) 说明内容的Html代码
|
||||||
|
- `alternateLanguages`: (`Object`) 不明链接?
|
||||||
|
- `{语言名}`: 对应语言的链接
|
||||||
|
|
||||||
|
##### 请求 Url 中的 Type 与返回数据中属性的关系 #####
|
||||||
|
> 表中数据可能有错误,如发现问题,可在发起 Issue 并附上不在该表中情况(例如)的请求信息和返回数据,经确认后将会更新文档。
|
||||||
|
|
||||||
|
类型|illustManga|illust|manga|novel
|
||||||
|
:--|:-:|:-:|:-:|:-:
|
||||||
|
`artworks` |√|×|×|×
|
||||||
|
`top` |√|×|×|?
|
||||||
|
`illustrations`|×|√|×|×
|
||||||
|
`manga` |×|×|√|×
|
||||||
|
`novels` |×|×|×|√
|
||||||
|
|
||||||
|
符号解释:
|
||||||
|
- `√`: 该属性一定存在
|
||||||
|
- `?`: 该属性可能存在
|
||||||
|
- `×`: 该属性不存在
|
||||||
|
2
pom.xml
2
pom.xml
@ -100,7 +100,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>4.13.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -13,8 +13,10 @@ import net.lamgc.cgj.bot.sort.PreLoadDataAttribute;
|
|||||||
import net.lamgc.cgj.bot.sort.PreLoadDataAttributeComparator;
|
import net.lamgc.cgj.bot.sort.PreLoadDataAttributeComparator;
|
||||||
import net.lamgc.cgj.pixiv.PixivDownload;
|
import net.lamgc.cgj.pixiv.PixivDownload;
|
||||||
import net.lamgc.cgj.pixiv.PixivDownload.PageQuality;
|
import net.lamgc.cgj.pixiv.PixivDownload.PageQuality;
|
||||||
|
import net.lamgc.cgj.pixiv.PixivSearchAttribute;
|
||||||
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||||
import net.lamgc.cgj.pixiv.PixivURL;
|
import net.lamgc.cgj.pixiv.PixivURL;
|
||||||
|
import net.lamgc.cgj.util.PixivUtils;
|
||||||
import net.lamgc.utils.base.runner.Argument;
|
import net.lamgc.utils.base.runner.Argument;
|
||||||
import net.lamgc.utils.base.runner.Command;
|
import net.lamgc.utils.base.runner.Command;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -40,6 +42,8 @@ public class BotCommandProcess {
|
|||||||
|
|
||||||
private final static RankingUpdateTimer updateTimer = new RankingUpdateTimer();
|
private final static RankingUpdateTimer updateTimer = new RankingUpdateTimer();
|
||||||
|
|
||||||
|
private final static int SEARCH_PAGE_MAX_ITEM = 60;
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
log.info("正在初始化...");
|
log.info("正在初始化...");
|
||||||
|
|
||||||
@ -143,8 +147,13 @@ public class BotCommandProcess {
|
|||||||
@Argument(force = false, name = "date") Date queryTime,
|
@Argument(force = false, name = "date") Date queryTime,
|
||||||
@Argument(force = false, name = "force") boolean force,
|
@Argument(force = false, name = "force") boolean force,
|
||||||
@Argument(force = false, name = "mode", defaultValue = "DAILY") String contentMode,
|
@Argument(force = false, name = "mode", defaultValue = "DAILY") String contentMode,
|
||||||
@Argument(force = false, name = "type", defaultValue = "ALL") String contentType
|
@Argument(force = false, name = "type", defaultValue = "ALL") String contentType,
|
||||||
|
@Argument(force = false, name = "p", defaultValue = "1") int pageIndex
|
||||||
) throws InterruptedException {
|
) throws InterruptedException {
|
||||||
|
if(pageIndex <= 0) {
|
||||||
|
return "色图姬找不到指定页数的排行榜!";
|
||||||
|
}
|
||||||
|
|
||||||
Date queryDate = queryTime;
|
Date queryDate = queryTime;
|
||||||
if (queryDate == null) {
|
if (queryDate == null) {
|
||||||
queryDate = new Date();
|
queryDate = new Date();
|
||||||
@ -212,8 +221,10 @@ public class BotCommandProcess {
|
|||||||
log.warn("配置项 {} 的参数值格式有误!", imageLimitPropertyKey);
|
log.warn("配置项 {} 的参数值格式有误!", imageLimitPropertyKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int startsIndex = itemLimit * pageIndex - (itemLimit - 1);
|
||||||
List<JsonObject> rankingInfoList = CacheStoreCentral.getCentral()
|
List<JsonObject> rankingInfoList = CacheStoreCentral.getCentral()
|
||||||
.getRankingInfoByCache(type, mode, queryDate, 1, Math.max(0, itemLimit), false);
|
.getRankingInfoByCache(type, mode, queryDate,
|
||||||
|
Math.max(1, startsIndex), Math.max(0, itemLimit), false);
|
||||||
if(rankingInfoList.isEmpty()) {
|
if(rankingInfoList.isEmpty()) {
|
||||||
return "无法查询排行榜,可能排行榜尚未更新。";
|
return "无法查询排行榜,可能排行榜尚未更新。";
|
||||||
}
|
}
|
||||||
@ -314,12 +325,9 @@ public class BotCommandProcess {
|
|||||||
@Argument(name = "option", force = false) String contentOption,
|
@Argument(name = "option", force = false) String contentOption,
|
||||||
@Argument(name = "p", force = false, defaultValue = "1") int pagesIndex
|
@Argument(name = "p", force = false, defaultValue = "1") int pagesIndex
|
||||||
) throws IOException, InterruptedException {
|
) throws IOException, InterruptedException {
|
||||||
|
PixivSearchLinkBuilder searchLinkBuilder = PixivUtils.buildSearchLinkBuilderFromString(content, type, area,
|
||||||
|
includeKeywords, excludeKeywords, contentOption, pagesIndex);
|
||||||
log.debug("正在执行搜索...");
|
log.debug("正在执行搜索...");
|
||||||
JsonObject resultBody = CacheStoreCentral.getCentral()
|
|
||||||
.getSearchBody(content, type, area, includeKeywords, excludeKeywords, contentOption, pagesIndex);
|
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder("内容 " + content + " 的搜索结果:\n");
|
|
||||||
log.debug("正在处理信息...");
|
|
||||||
int limit = 8;
|
int limit = 8;
|
||||||
try {
|
try {
|
||||||
limit = Integer.parseInt(SettingProperties.
|
limit = Integer.parseInt(SettingProperties.
|
||||||
@ -327,95 +335,112 @@ public class BotCommandProcess {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("参数转换异常!将使用默认值(" + limit + ")", e);
|
log.warn("参数转换异常!将使用默认值(" + limit + ")", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalCount = 0;
|
int totalCount = 0;
|
||||||
for (PixivSearchLinkBuilder.SearchArea searchArea : PixivSearchLinkBuilder.SearchArea.values()) {
|
StringBuilder result = new StringBuilder("内容 " + content + " 的搜索结果:\n");
|
||||||
if (!resultBody.has(searchArea.jsonKey) ||
|
List<JsonObject> artworkList = getSearchResult(searchLinkBuilder, fromGroup, limit, pagesIndex);
|
||||||
resultBody.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data").size() == 0) {
|
artworkList.sort(new PreLoadDataAttributeComparator(PreLoadDataAttribute.LIKE));
|
||||||
log.debug("返回数据不包含 {}", searchArea.jsonKey);
|
int startIndex = limit * pagesIndex - limit + 1;
|
||||||
continue;
|
int pageStartIndex = startIndex % SEARCH_PAGE_MAX_ITEM;
|
||||||
}
|
for(int index = pageStartIndex; totalCount < limit && index < artworkList.size(); index++) {
|
||||||
JsonArray illustsArray = resultBody
|
int illustId = artworkList.get(index - 1).get("illustId").getAsInt();
|
||||||
.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data");
|
// 预加载数据有更多信息可以提供
|
||||||
ArrayList<JsonElement> illustsList = new ArrayList<>();
|
JsonObject artworkPreLoadData = CacheStoreCentral.getCentral()
|
||||||
illustsArray.forEach(illustsList::add);
|
.getIllustPreLoadData(illustId, false);
|
||||||
illustsList.sort(new PreLoadDataAttributeComparator(PreLoadDataAttribute.BOOKMARK));
|
|
||||||
|
|
||||||
log.debug("已找到与 {} 相关插图信息({}):", content, searchArea.name().toLowerCase());
|
// 构造消息内容
|
||||||
int count = 1;
|
result.append(startIndex++).append(". (").append(artworkPreLoadData.get("illustId").getAsInt()).append(") ")
|
||||||
for (JsonElement jsonElement : illustsList) {
|
.append(artworkPreLoadData.get("illustTitle").getAsString());
|
||||||
if (count > limit) {
|
result.append("\n\t").append("作者:").append(artworkPreLoadData.get("userName").getAsString());
|
||||||
break;
|
result.append("\n\t").append("作品页数:").append(artworkPreLoadData.get("pageCount").getAsInt()).append(" 页");
|
||||||
}
|
result.append("\n\t").append("点赞数:")
|
||||||
JsonObject illustObj = jsonElement.getAsJsonObject();
|
.append(artworkPreLoadData.get(PreLoadDataAttribute.LIKE.attrName).getAsInt()).append(" 页");
|
||||||
if (!illustObj.has("illustId")) {
|
result.append("\n\t").append("收藏数:")
|
||||||
continue;
|
.append(artworkPreLoadData.get(PreLoadDataAttribute.BOOKMARK.attrName).getAsInt()).append(" 页");
|
||||||
}
|
result.append("\n\t").append("围观数:")
|
||||||
int illustId = illustObj.get("illustId").getAsInt();
|
.append(artworkPreLoadData.get(PreLoadDataAttribute.VIEW.attrName).getAsInt()).append(" 页");
|
||||||
StringBuilder builder = new StringBuilder("[");
|
result.append("\n\t").append("评论数:")
|
||||||
illustObj.get("tags").getAsJsonArray().forEach(el -> builder.append(el.getAsString()).append(", "));
|
.append(artworkPreLoadData.get(PreLoadDataAttribute.COMMENT.attrName).getAsInt()).append(" 页");
|
||||||
builder.replace(builder.length() - 2, builder.length(), "]");
|
result.append(CacheStoreCentral.getCentral()
|
||||||
log.debug("{} ({} / {})\n\t作品id: {}, \n\t作者名(作者id): {} ({}), \n\t" +
|
.getImageById(fromGroup, illustId, PageQuality.REGULAR, 1)).append("\n");
|
||||||
"作品标题: {}, \n\t作品Tags: {}, \n\t页数: {}页, \n\t作品链接: {}",
|
totalCount++;
|
||||||
searchArea.name(),
|
|
||||||
count,
|
|
||||||
illustsList.size(),
|
|
||||||
illustId,
|
|
||||||
illustObj.get("userName").getAsString(),
|
|
||||||
illustObj.get("userId").getAsInt(),
|
|
||||||
illustObj.get("illustTitle").getAsString(),
|
|
||||||
builder,
|
|
||||||
illustObj.get("pageCount").getAsInt(),
|
|
||||||
PixivURL.getPixivRefererLink(illustId)
|
|
||||||
);
|
|
||||||
|
|
||||||
String imageMsg;
|
|
||||||
try {
|
|
||||||
imageMsg = CacheStoreCentral.getCentral()
|
|
||||||
.getImageById(fromGroup, illustId, PixivDownload.PageQuality.REGULAR, 1);
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
if(e.getMessage().startsWith("No work found: ")) {
|
|
||||||
log.warn("作品 {} 不存在, 跳过该作品...", illustId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (isNoSafe(illustId, SettingProperties.getProperties(fromGroup), false)) {
|
|
||||||
log.warn("作品Id {} 为R-18作品, 跳过.", illustId);
|
|
||||||
continue;
|
|
||||||
} else if(isReported(illustId)) {
|
|
||||||
log.warn("作品Id {} 被报告, 正在等待审核, 跳过该作品.", illustId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject illustPreLoadData = CacheStoreCentral.getCentral()
|
|
||||||
.getIllustPreLoadData(illustId, false);
|
|
||||||
result.append(searchArea.name()).append(" (").append(count).append(" / ")
|
|
||||||
.append(limit).append(")\n\t作品id: ").append(illustId)
|
|
||||||
.append(", \n\t作者名: ").append(illustObj.get("userName").getAsString())
|
|
||||||
.append("\n\t作品标题: ").append(illustObj.get("illustTitle").getAsString())
|
|
||||||
.append("\n\t作品页数: ").append(illustObj.get("pageCount").getAsInt()).append("页")
|
|
||||||
.append("\n\t点赞数:")
|
|
||||||
.append(illustPreLoadData.get(PreLoadDataAttribute.LIKE.attrName).getAsInt())
|
|
||||||
.append("\n\t收藏数:")
|
|
||||||
.append(illustPreLoadData.get(PreLoadDataAttribute.BOOKMARK.attrName).getAsInt())
|
|
||||||
.append("\n\t围观数:")
|
|
||||||
.append(illustPreLoadData.get(PreLoadDataAttribute.VIEW.attrName).getAsInt())
|
|
||||||
.append("\n\t评论数:")
|
|
||||||
.append(illustPreLoadData.get(PreLoadDataAttribute.COMMENT.attrName).getAsInt())
|
|
||||||
.append("\n").append(imageMsg).append("\n");
|
|
||||||
count++;
|
|
||||||
totalCount++;
|
|
||||||
}
|
|
||||||
if (count > limit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalCount <= 0 ?
|
return totalCount <= 0 ?
|
||||||
"搜索完成,未找到相关作品。" :
|
"搜索完成,未找到相关作品。" :
|
||||||
Strings.nullToEmpty(result.toString()) + "预览图片并非原图,使用“.cgj image -id 作品id”获取原图\n" +
|
Strings.nullToEmpty(result.toString()) + "预览图片并非原图,使用“.cgj image -id 作品id”获取原图\n" +
|
||||||
"如有不当作品,可使用\".cgj report -id 作品id\"向色图姬反馈。";
|
"如有不当作品,可使用\".cgj report -id 作品id\"向色图姬反馈。";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 length 涉及的多个页的搜索结果.
|
||||||
|
* 例如:
|
||||||
|
* pageMaxItem = 60;
|
||||||
|
* length = 150;
|
||||||
|
* page = 3;
|
||||||
|
* 那么:
|
||||||
|
* endItemIndex = length * page = 450;
|
||||||
|
* startItemIndex = endItemIndex - length + 1 = 301;
|
||||||
|
* startPageIndex = ceil(startItemIndex / pageMaxItem) = 6;
|
||||||
|
* pageRange = ceil((endItemIndex - length + 1) / pageMaxItem) = 3;
|
||||||
|
* endPageIndex = startPageIndex - pageRange - 1 = 8;
|
||||||
|
* 该方法将会取搜索结果的 6 ~ 8 页结果并返回;
|
||||||
|
* @param searchLinkBuilder 已构造好除 Page 参数外其他参数的 {@link PixivSearchLinkBuilder}
|
||||||
|
* @param length 所需结果的范围
|
||||||
|
* @param page 所需结果的页数
|
||||||
|
* @return 返回包含范围的涉及页面所有搜索结果.
|
||||||
|
* @throws IOException 如获取发生异常则抛出.
|
||||||
|
*/
|
||||||
|
private static List<JsonObject> getSearchResult(PixivSearchLinkBuilder searchLinkBuilder, long groupId, int length, int page) throws IOException {
|
||||||
|
List<JsonObject> artworkList = new ArrayList<>(length);
|
||||||
|
|
||||||
|
int endsItemIndex = length * page;
|
||||||
|
int startsItemIndex = endsItemIndex - length + 1;
|
||||||
|
int startPageIndex = (int) Math.ceil(startsItemIndex / (double) SEARCH_PAGE_MAX_ITEM);
|
||||||
|
int pageRange = (int) Math.ceil((endsItemIndex - startsItemIndex) / (double) SEARCH_PAGE_MAX_ITEM);
|
||||||
|
PixivSearchAttribute areaAttribute = PixivSearchAttribute.valueOf(searchLinkBuilder.getSearchArea().toString());
|
||||||
|
Properties properties = SettingProperties.getProperties(groupId);
|
||||||
|
int expectedQuantity = pageRange * SEARCH_PAGE_MAX_ITEM;
|
||||||
|
for(int pageIndex = startPageIndex;
|
||||||
|
pageIndex <= startPageIndex + pageRange - 1 || artworkList.size() < length || artworkList.size() < expectedQuantity;
|
||||||
|
pageIndex++) {
|
||||||
|
searchLinkBuilder.setPage(pageIndex);
|
||||||
|
JsonObject searchBody = CacheStoreCentral.getCentral().getSearchBody(searchLinkBuilder);
|
||||||
|
for(String areaAttributeName : areaAttribute.attributeNames) {
|
||||||
|
JsonObject areaResult = searchBody.getAsJsonObject(areaAttributeName);
|
||||||
|
if(areaResult == null || !areaResult.has("data")) {
|
||||||
|
log.debug("作品类型属性 {} 无搜索结果, 跳过...", areaAttributeName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray areaArray = areaResult.getAsJsonArray("data");
|
||||||
|
for(JsonElement element : areaArray) {
|
||||||
|
JsonObject artworkInfo = element.getAsJsonObject();
|
||||||
|
if(!artworkInfo.has("illustId")) {
|
||||||
|
log.warn("发现未含有illustId的JsonObject: '{}'", artworkInfo.toString());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final int illustId = artworkInfo.get("illustId").getAsInt();
|
||||||
|
if(isNoSafe(illustId, properties, false)) {
|
||||||
|
log.warn("作品 {} 为R18作品, 跳过.", illustId);
|
||||||
|
continue;
|
||||||
|
} else if(isReported(illustId)) {
|
||||||
|
log.warn("作品 {} 被报告, 跳过.", illustId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
artworkList.add(artworkInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 去重
|
||||||
|
Set<JsonObject> hashSet = new HashSet<>(artworkList.size());
|
||||||
|
hashSet.addAll(artworkList);
|
||||||
|
artworkList.clear();
|
||||||
|
artworkList.addAll(hashSet);
|
||||||
|
return artworkList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取作品页面的下载链接
|
* 获取作品页面的下载链接
|
||||||
* @param illustId 作品Id
|
* @param illustId 作品Id
|
||||||
|
@ -402,84 +402,28 @@ public final class CacheStoreCentral {
|
|||||||
result = rankingCache.getCache(requestSign, start - 1, range);
|
result = rankingCache.getCache(requestSign, start - 1, range);
|
||||||
log.trace("RequestSign [{}] 缓存命中.", requestSign);
|
log.trace("RequestSign [{}] 缓存命中.", requestSign);
|
||||||
}
|
}
|
||||||
return PixivDownload.getRanking(result, start - 1, range);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取搜索结果
|
* 获取搜索结果
|
||||||
* @param content 搜索内容
|
* @param searchBuilder 需要执行搜索的搜索链接构造器
|
||||||
* @param type 类型
|
|
||||||
* @param area 范围
|
|
||||||
* @param includeKeywords 包含关键词
|
|
||||||
* @param excludeKeywords 排除关键词
|
|
||||||
* @param contentOption 内容类型
|
|
||||||
* @return 返回完整搜索结果
|
* @return 返回完整搜索结果
|
||||||
* @throws IOException 当请求发生异常, 或接口返回异常信息时抛出.
|
* @throws IOException 当请求发生异常, 或接口返回异常信息时抛出.
|
||||||
*/
|
*/
|
||||||
public JsonObject getSearchBody(
|
public JsonObject getSearchBody(PixivSearchLinkBuilder searchBuilder) throws IOException {
|
||||||
String content,
|
|
||||||
String type,
|
|
||||||
String area,
|
|
||||||
String includeKeywords,
|
|
||||||
String excludeKeywords,
|
|
||||||
String contentOption,
|
|
||||||
int pageIndex
|
|
||||||
) throws IOException {
|
|
||||||
PixivSearchLinkBuilder searchBuilder = new PixivSearchLinkBuilder(Strings.isNullOrEmpty(content) ? "" : content);
|
|
||||||
if (type != null) {
|
|
||||||
try {
|
|
||||||
searchBuilder.setSearchType(PixivSearchLinkBuilder.SearchType.valueOf(type.toUpperCase()));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
log.warn("不支持的SearchType: {}", type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (area != null) {
|
|
||||||
try {
|
|
||||||
searchBuilder.setSearchArea(PixivSearchLinkBuilder.SearchArea.valueOf(area));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
log.warn("不支持的SearchArea: {}", area);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (contentOption != null) {
|
|
||||||
try {
|
|
||||||
searchBuilder.setSearchContentOption(
|
|
||||||
PixivSearchLinkBuilder.SearchContentOption.valueOf(contentOption.trim().toUpperCase()));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
log.warn("不支持的SearchContentOption: {}", contentOption);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Strings.isNullOrEmpty(includeKeywords)) {
|
|
||||||
for (String keyword : includeKeywords.split(";")) {
|
|
||||||
searchBuilder.removeExcludeKeyword(keyword.trim());
|
|
||||||
searchBuilder.addIncludeKeyword(keyword.trim());
|
|
||||||
log.trace("已添加关键字: {}", keyword);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!Strings.isNullOrEmpty(excludeKeywords)) {
|
|
||||||
for (String keyword : excludeKeywords.split(";")) {
|
|
||||||
searchBuilder.removeIncludeKeyword(keyword.trim());
|
|
||||||
searchBuilder.addExcludeKeyword(keyword.trim());
|
|
||||||
log.trace("已添加排除关键字: {}", keyword);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pageIndex > 0) {
|
|
||||||
searchBuilder.setPage(pageIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("正在搜索作品, 条件: {}", searchBuilder.getSearchCondition());
|
log.debug("正在搜索作品, 条件: {}", searchBuilder.getSearchCondition());
|
||||||
|
String requestUrl = searchBuilder.buildURL();
|
||||||
|
String searchIdentify = requestUrl.substring(requestUrl.lastIndexOf("/", requestUrl.lastIndexOf("/") - 1) + 1);
|
||||||
Locker<String> locker
|
Locker<String> locker
|
||||||
= buildSyncKey(searchBuilder.buildURL());
|
= buildSyncKey(searchIdentify);
|
||||||
String requestUrl = locker.getKey();
|
|
||||||
log.debug("RequestUrl: {}", requestUrl);
|
log.debug("RequestUrl: {}", requestUrl);
|
||||||
JsonObject resultBody = null;
|
JsonObject resultBody = null;
|
||||||
if(!searchBodyCache.exists(requestUrl)) {
|
if(!searchBodyCache.exists(searchIdentify)) {
|
||||||
try {
|
try {
|
||||||
locker.lock();
|
locker.lock();
|
||||||
synchronized (locker) {
|
synchronized (locker) {
|
||||||
if (!searchBodyCache.exists(requestUrl)) {
|
if (!searchBodyCache.exists(searchIdentify)) {
|
||||||
log.trace("searchBody缓存失效, 正在更新...");
|
log.trace("searchBody缓存失效, 正在更新...");
|
||||||
JsonObject jsonObject;
|
JsonObject jsonObject;
|
||||||
HttpGet httpGetRequest = BotGlobal.getGlobal().getPixivDownload().
|
HttpGet httpGetRequest = BotGlobal.getGlobal().getPixivDownload().
|
||||||
@ -504,8 +448,8 @@ public final class CacheStoreCentral {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("全局配置项 \"{}\" 值非法, 已使用默认值: {}", propValue, expire);
|
log.warn("全局配置项 \"{}\" 值非法, 已使用默认值: {}", propValue, expire);
|
||||||
}
|
}
|
||||||
resultBody = jsonObject.getAsJsonObject().getAsJsonObject("body");
|
resultBody = jsonObject;
|
||||||
searchBodyCache.update(requestUrl, jsonObject, expire);
|
searchBodyCache.update(searchIdentify, jsonObject, expire);
|
||||||
log.trace("searchBody缓存已更新(有效时间: {})", expire);
|
log.trace("searchBody缓存已更新(有效时间: {})", expire);
|
||||||
} else {
|
} else {
|
||||||
log.trace("搜索缓存命中.");
|
log.trace("搜索缓存命中.");
|
||||||
@ -519,9 +463,9 @@ public final class CacheStoreCentral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(Objects.isNull(resultBody)) {
|
if(Objects.isNull(resultBody)) {
|
||||||
resultBody = searchBodyCache.getCache(requestUrl).getAsJsonObject().getAsJsonObject("body");
|
resultBody = searchBodyCache.getCache(searchIdentify).getAsJsonObject();
|
||||||
}
|
}
|
||||||
return resultBody;
|
return resultBody.getAsJsonObject("body");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ImageChecksum getImageChecksum(int illustId, int pageIndex) {
|
protected ImageChecksum getImageChecksum(int illustId, int pageIndex) {
|
||||||
|
@ -92,11 +92,14 @@ public class MiraiMain implements Closeable {
|
|||||||
private void executeMessageEvent(MessageEvent message) {
|
private void executeMessageEvent(MessageEvent message) {
|
||||||
log.debug("Mirai Message: {}", message);
|
log.debug("Mirai Message: {}", message);
|
||||||
if(message instanceof GroupMessageEvent) {
|
if(message instanceof GroupMessageEvent) {
|
||||||
GroupMessageEvent GroupMessageEvent = (GroupMessageEvent) message;
|
GroupMessageEvent groupMessageEvent = (GroupMessageEvent) message;
|
||||||
Boolean muteState = muteManager.isMute(GroupMessageEvent.getGroup().getId(), true);
|
Boolean muteState = muteManager.isMute(groupMessageEvent.getGroup().getId(), true);
|
||||||
if(muteState == null) {
|
if(muteState == null) {
|
||||||
muteManager.setMuteState(GroupMessageEvent.getGroup().getId(),
|
boolean mute = groupMessageEvent.getGroup().getBotMuteRemaining() != 0;
|
||||||
((GroupMessageEvent) message).getGroup().getBotMuteRemaining() != 0);
|
muteManager.setMuteState(groupMessageEvent.getGroup().getId(), mute);
|
||||||
|
if(mute) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else if(muteState) {
|
} else if(muteState) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||||
import net.lamgc.cgj.exception.HttpRequestException;
|
import net.lamgc.cgj.exception.HttpRequestException;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
@ -32,7 +31,6 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
|
||||||
public class PixivDownload {
|
public class PixivDownload {
|
||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(PixivDownload.class);
|
private final static Logger log = LoggerFactory.getLogger(PixivDownload.class);
|
||||||
@ -249,43 +247,6 @@ public class PixivDownload {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 从JsonArray获取数据
|
|
||||||
* @param rankingList JsonArray对象
|
|
||||||
* @param rankStart 开始索引, 从0开始
|
|
||||||
* @param range 范围
|
|
||||||
* @return 返回List对象
|
|
||||||
*/
|
|
||||||
public static List<JsonObject> getRanking(List<JsonObject> rankingList, int rankStart, int range) {
|
|
||||||
log.debug("正在读取JsonArray...(rankStart: {}, range: {})", rankStart, range);
|
|
||||||
ArrayList<JsonObject> results = new ArrayList<>(rankingList.size());
|
|
||||||
for (int rankIndex = rankStart; rankIndex < rankStart + range; rankIndex++) {
|
|
||||||
JsonElement jsonElement = rankingList.get(rankIndex - rankStart);
|
|
||||||
JsonObject rankInfo = jsonElement.getAsJsonObject();
|
|
||||||
int rank = rankInfo.get("rank").getAsInt();
|
|
||||||
int illustId = rankInfo.get("illust_id").getAsInt();
|
|
||||||
int authorId = rankInfo.get("user_id").getAsInt();
|
|
||||||
String authorName = rankInfo.get("user_name").getAsString();
|
|
||||||
String title = rankInfo.get("title").getAsString();
|
|
||||||
log.trace("Array-当前到第 {}/{} 名(总共 {} 名), IllustID: {}, Author: ({}) {}, Title: {}", rank, rankStart + range, range, illustId, authorId, authorName, title);
|
|
||||||
results.add(rankInfo);
|
|
||||||
}
|
|
||||||
log.debug("JsonArray读取完成.");
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从JsonArray获取数据
|
|
||||||
* @param rankingArray JsonArray对象
|
|
||||||
* @param rankStart 开始索引, 从0开始
|
|
||||||
* @param range 范围
|
|
||||||
* @return 返回List对象
|
|
||||||
*/
|
|
||||||
public static List<JsonObject> getRanking(JsonArray rankingArray, int rankStart, int range) {
|
|
||||||
List<JsonObject> list = new Gson().fromJson(rankingArray, new TypeToken<List<JsonObject>>(){}.getType());
|
|
||||||
return getRanking(list, rankStart, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取排行榜.
|
* 获取排行榜.
|
||||||
* <p>注意: 如果范围实际上没超出, 但返回排行榜不足, 会导致与实际请求的数量不符, 需要检查</p>
|
* <p>注意: 如果范围实际上没超出, 但返回排行榜不足, 会导致与实际请求的数量不符, 需要检查</p>
|
||||||
@ -421,6 +382,7 @@ public class PixivDownload {
|
|||||||
/**
|
/**
|
||||||
* 插图质量
|
* 插图质量
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public enum PageQuality{
|
public enum PageQuality{
|
||||||
/**
|
/**
|
||||||
* 原图画质
|
* 原图画质
|
||||||
|
22
src/main/java/net/lamgc/cgj/pixiv/PixivSearchAttribute.java
Normal file
22
src/main/java/net/lamgc/cgj/pixiv/PixivSearchAttribute.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package net.lamgc.cgj.pixiv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索结果的属性枚举类.
|
||||||
|
* <p>按照请求的{@link PixivSearchLinkBuilder.SearchArea}获取所支持的属性数组</p>
|
||||||
|
*/
|
||||||
|
public enum PixivSearchAttribute {
|
||||||
|
|
||||||
|
ARTWORKS("illustManga"),
|
||||||
|
TOP("illustManga", "novel"),
|
||||||
|
ILLUSTRATIONS("illust"),
|
||||||
|
MANGA("manga"),
|
||||||
|
NOVELS("novel")
|
||||||
|
;
|
||||||
|
|
||||||
|
public final String[] attributeNames;
|
||||||
|
|
||||||
|
PixivSearchAttribute(String... attributeNames) {
|
||||||
|
this.attributeNames = attributeNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pixiv搜索URL构造器
|
* Pixiv搜索URL构造器
|
||||||
@ -15,7 +16,7 @@ import java.util.Objects;
|
|||||||
* @author LamGC
|
* @author LamGC
|
||||||
* @see PixivURL#PIXIV_SEARCH_CONTENT_URL
|
* @see PixivURL#PIXIV_SEARCH_CONTENT_URL
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings({"unused", "UnusedReturnValue"})
|
||||||
public class PixivSearchLinkBuilder {
|
public class PixivSearchLinkBuilder {
|
||||||
|
|
||||||
private final String content;
|
private final String content;
|
||||||
@ -26,8 +27,8 @@ public class PixivSearchLinkBuilder {
|
|||||||
private SearchOrder searchOrder = SearchOrder.DATE_D;
|
private SearchOrder searchOrder = SearchOrder.DATE_D;
|
||||||
private SearchContentOption searchContentOption = SearchContentOption.ALL;
|
private SearchContentOption searchContentOption = SearchContentOption.ALL;
|
||||||
|
|
||||||
private final HashSet<String> includeKeywords = new HashSet<>(0);
|
private final Set<String> includeKeywords = new HashSet<>(0);
|
||||||
private final HashSet<String> excludeKeywords = new HashSet<>(0);
|
private final Set<String> excludeKeywords = new HashSet<>(0);
|
||||||
|
|
||||||
private int page = 1;
|
private int page = 1;
|
||||||
|
|
||||||
@ -161,11 +162,19 @@ public class PixivSearchLinkBuilder {
|
|||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder setSearchArea(SearchArea searchArea) {
|
public PixivSearchLinkBuilder setSearchArea(SearchArea searchArea) {
|
||||||
this.searchArea = Objects.requireNonNull(searchArea);
|
this.searchArea = Objects.requireNonNull(searchArea);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchArea getSearchArea() {
|
||||||
|
return searchArea;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取搜索条件.
|
* 获取搜索条件.
|
||||||
* @return 搜索条件内容
|
* @return 搜索条件内容
|
||||||
@ -199,32 +208,60 @@ public class PixivSearchLinkBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchMode getSearchMode() {
|
||||||
|
return searchMode;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder setSearchType(SearchType searchType) {
|
public PixivSearchLinkBuilder setSearchType(SearchType searchType) {
|
||||||
this.searchType = Objects.requireNonNull(searchType);
|
this.searchType = Objects.requireNonNull(searchType);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchType getSearchType() {
|
||||||
|
return searchType;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder setSearchOrder(SearchOrder searchOrder) {
|
public PixivSearchLinkBuilder setSearchOrder(SearchOrder searchOrder) {
|
||||||
this.searchOrder = Objects.requireNonNull(searchOrder);
|
this.searchOrder = Objects.requireNonNull(searchOrder);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchOrder getSearchOrder() {
|
||||||
|
return searchOrder;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder setSearchContentOption(SearchContentOption searchContentOption) {
|
public PixivSearchLinkBuilder setSearchContentOption(SearchContentOption searchContentOption) {
|
||||||
this.searchContentOption = Objects.requireNonNull(searchContentOption);
|
this.searchContentOption = Objects.requireNonNull(searchContentOption);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SearchContentOption getSearchContentOption() {
|
||||||
|
return searchContentOption;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder setRatioOption(RatioOption ratioOption) {
|
public PixivSearchLinkBuilder setRatioOption(RatioOption ratioOption) {
|
||||||
this.ratioOption = Objects.requireNonNull(ratioOption);
|
this.ratioOption = Objects.requireNonNull(ratioOption);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RatioOption getRatioOption() {
|
||||||
|
return ratioOption;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder setDateRange(Date startDate, Date endDate) {
|
public PixivSearchLinkBuilder setDateRange(Date startDate, Date endDate) {
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getStartDate() {
|
||||||
|
return startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getEndDate() {
|
||||||
|
return endDate;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder setMaxSize(int width, int height) {
|
public PixivSearchLinkBuilder setMaxSize(int width, int height) {
|
||||||
this.wgt = width;
|
this.wgt = width;
|
||||||
this.hgt = height;
|
this.hgt = height;
|
||||||
@ -245,6 +282,10 @@ public class PixivSearchLinkBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPage() {
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
public PixivSearchLinkBuilder addExcludeKeyword(String keyword) {
|
public PixivSearchLinkBuilder addExcludeKeyword(String keyword) {
|
||||||
excludeKeywords.add(keyword);
|
excludeKeywords.add(keyword);
|
||||||
return this;
|
return this;
|
||||||
@ -265,6 +306,14 @@ public class PixivSearchLinkBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getIncludeKeywords() {
|
||||||
|
return new HashSet<>(includeKeywords);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getExcludeKeywords() {
|
||||||
|
return new HashSet<>(excludeKeywords);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索区域
|
* 搜索区域
|
||||||
*/
|
*/
|
||||||
@ -296,13 +345,18 @@ public class PixivSearchLinkBuilder {
|
|||||||
*/
|
*/
|
||||||
NOVELS("novel");
|
NOVELS("novel");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可用的Json属性名
|
||||||
|
* @deprecated 该属性信息以移至 {@link PixivSearchAttribute}
|
||||||
|
* @see PixivSearchAttribute
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public final String jsonKey;
|
public final String jsonKey;
|
||||||
|
|
||||||
SearchArea(String jsonKey) {
|
SearchArea(String jsonKey) {
|
||||||
this.jsonKey = jsonKey;
|
this.jsonKey = jsonKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -401,5 +455,4 @@ public class PixivSearchLinkBuilder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
84
src/main/java/net/lamgc/cgj/util/PixivUtils.java
Normal file
84
src/main/java/net/lamgc/cgj/util/PixivUtils.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package net.lamgc.cgj.util;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pixiv工具类
|
||||||
|
*/
|
||||||
|
public final class PixivUtils {
|
||||||
|
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(PixivUtils.class);
|
||||||
|
|
||||||
|
private PixivUtils() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 快速构造一个PixivSearchLinkBuilder
|
||||||
|
* @param content 搜索内容
|
||||||
|
* @param type 搜索类型
|
||||||
|
* @param area 搜索范围
|
||||||
|
* @param includeKeywords 包含关键词
|
||||||
|
* @param excludeKeywords 排除关键词
|
||||||
|
* @param contentOption 内容级别选项
|
||||||
|
* @param pageIndex 搜索页数
|
||||||
|
* @return 返回PixivSearchLinkBuilder对象
|
||||||
|
* @see PixivSearchLinkBuilder
|
||||||
|
*/
|
||||||
|
public static PixivSearchLinkBuilder buildSearchLinkBuilderFromString(
|
||||||
|
String content,
|
||||||
|
String type,
|
||||||
|
String area,
|
||||||
|
String includeKeywords,
|
||||||
|
String excludeKeywords,
|
||||||
|
String contentOption,
|
||||||
|
int pageIndex
|
||||||
|
) {
|
||||||
|
PixivSearchLinkBuilder searchBuilder = new PixivSearchLinkBuilder(Strings.isNullOrEmpty(content) ? "" : content);
|
||||||
|
if (type != null) {
|
||||||
|
try {
|
||||||
|
searchBuilder.setSearchType(PixivSearchLinkBuilder.SearchType.valueOf(type.trim().toUpperCase()));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.warn("不支持的SearchType: {}", type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (area != null) {
|
||||||
|
try {
|
||||||
|
searchBuilder.setSearchArea(PixivSearchLinkBuilder.SearchArea.valueOf(area.trim().toUpperCase()));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.warn("不支持的SearchArea: {}", area);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (contentOption != null) {
|
||||||
|
try {
|
||||||
|
searchBuilder.setSearchContentOption(
|
||||||
|
PixivSearchLinkBuilder.SearchContentOption.valueOf(contentOption.trim().toUpperCase()));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.warn("不支持的SearchContentOption: {}", contentOption);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Strings.isNullOrEmpty(includeKeywords)) {
|
||||||
|
for (String keyword : includeKeywords.split(";")) {
|
||||||
|
searchBuilder.removeExcludeKeyword(keyword.trim());
|
||||||
|
searchBuilder.addIncludeKeyword(keyword.trim());
|
||||||
|
log.trace("已添加关键字: {}", keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Strings.isNullOrEmpty(excludeKeywords)) {
|
||||||
|
for (String keyword : excludeKeywords.split(";")) {
|
||||||
|
searchBuilder.removeIncludeKeyword(keyword.trim());
|
||||||
|
searchBuilder.addExcludeKeyword(keyword.trim());
|
||||||
|
log.trace("已添加排除关键字: {}", keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pageIndex > 0) {
|
||||||
|
searchBuilder.setPage(pageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user