mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-01 21:07:25 +00:00
Compare commits
29 Commits
v2.5.2-202
...
optimize-s
Author | SHA1 | Date | |
---|---|---|---|
f976017a89
|
|||
575dc0c7fb
|
|||
56ef463c63
|
|||
4387da37f5
|
|||
0fc3e3ab48
|
|||
a606ec0423
|
|||
210aa84ed5 | |||
6fbbe522db | |||
6d55325fc7 | |||
d1c7f6f973
|
|||
0727ef4f93
|
|||
73a1caaf46
|
|||
4784f8773b
|
|||
f80b6e72e0
|
|||
05e933838e
|
|||
3045b571a8
|
|||
553212e556
|
|||
5383de7450
|
|||
9964205dc2
|
|||
394c3940e4
|
|||
d3d6f151d4
|
|||
62e3affef1
|
|||
51efc95c1c
|
|||
d5c3a438b0
|
|||
792bfcb1bd
|
|||
cbd7db3570
|
|||
467e7065fa
|
|||
d2240e56fd | |||
eef9f285ca
|
37
.github/ISSUE_TEMPLATE/Bug_Report.md
vendored
37
.github/ISSUE_TEMPLATE/Bug_Report.md
vendored
@ -1,26 +1,35 @@
|
|||||||
---
|
---
|
||||||
name: Bug Report
|
name: Bug 反馈
|
||||||
about: Use this template to feedback bugs.
|
about: 使用这个模板反馈应用问题。
|
||||||
title: ''
|
title: ''
|
||||||
labels: bug
|
labels: bug
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Environmental information ##
|
## 环境信息 ##
|
||||||
OS(e.g: Windows 10 1909):
|
系统(例如: Windows 10 1909): ``
|
||||||
Java(e.g: Oracle Jdk 8.242):
|
Java版本(例如: Oracle Jdk 8.242): ``
|
||||||
Issue version(versionTag or commitId):
|
<!-- 如果直接使用发布版,那么就填写发布版版本号(v开头) -->
|
||||||
|
<!-- 如果你通过编译运行的方式运行开发版,请你填写运行所使用的Commit Id -->
|
||||||
|
发生问题所在的版本: ``
|
||||||
|
|
||||||
## Problem description ##
|
## 问题描述 ##
|
||||||
// Describe the problem in as much detail as possible here
|
<!-- 尽可能的清晰描述问题的信息 -->
|
||||||
|
|
||||||
## Expected behavior ##
|
## 预期行为 ##
|
||||||
// What will this function do under normal circumstances?
|
<!-- 你觉得正常情况下应该会发生什么? -->
|
||||||
|
|
||||||
## Actual behavior ##
|
## 实际行为 ##
|
||||||
// But what does this feature actually look like?
|
<!-- 实际上这个功能做了什么? -->
|
||||||
|
|
||||||
## Recurrence steps ##
|
## 复现步骤 ##
|
||||||
// What can we do to recreate this situation?
|
<!-- 将复现步骤详细的写出,如果是偶发问题,可以写已知的,触发几率高的方法 -->
|
||||||
1.
|
1.
|
||||||
|
|
||||||
|
## 相关信息 ##
|
||||||
|
### 日志 ###
|
||||||
|
<!-- 如果日志涉及了问题,请务必将日志一同提交,这对排查问题非常有用 -->
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
11
.github/ISSUE_TEMPLATE/Feature_Report.md
vendored
Normal file
11
.github/ISSUE_TEMPLATE/Feature_Report.md
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
name: 功能/想法 提议
|
||||||
|
about: 使用这个模板将你对应用的想法提出来,或许我们会采纳!
|
||||||
|
title: ''
|
||||||
|
labels: function, question
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- 如果可以,尽可能的清晰、详细的表达你的想法 -->
|
||||||
|
<!-- 没关系的,我们会进一步向你交流以尝试了解你的想法! -->
|
@ -5,6 +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/
|
||||||
CMD [java, "-Dcgj.logsPath=/data/logs", "-jar", "/CGJ.jar", "botMode", "-botDataDir=/data"]
|
ENTRYPOINT ["/usr/java/openjdk-14/bin/java", "-Duser.timezone=Aisa/Shanghai"]
|
||||||
|
CMD ["-Dcgj.logsPath=/data/logs", "-jar", "/CGJ.jar", "botMode", "-botDataDir=/data"]
|
||||||
|
|
||||||
COPY ${jarFileName} /CGJ.jar
|
COPY ${jarFileName} /CGJ.jar
|
||||||
|
135
README.md
135
README.md
@ -1,41 +1,114 @@
|
|||||||
# ContentGrabbingJi #
|
# ContentGrabbingJi - 色图姬 #
|
||||||
Pixiv爬虫一只,同时也是一个机器人/插件!
|
一个以高性能、高效率为目标,多平台/框架支持、持续维护的Pixiv聊天机器人
|
||||||
|
|
||||||
## 支持的机器人平台 ##
|
色图姬存在的目的最初是作为**爬虫 + 机器人**的形式开发,在开发过程中逐渐以多聊天平台,高效率为目标进行。
|
||||||
- [Mirai](https://github.com/mamoe/mirai)
|
|
||||||
- [CoolQ](https://cqp.cc)(基于[`SpringCQ`](https://github.com/lz1998/spring-cq), 不支持多账号使用, 需要使用[`CQHttp`](https://cqhttp.cc/)插件)
|
|
||||||
|
|
||||||
## Usage ##
|
## 安装 ##
|
||||||
> 注意: 运行色图姬前, 你需要准备一个Pixiv账号的会话Cookie存储文件, 否则色图姬将无法运行.
|
### 通过Jar文件部署 ###
|
||||||
> 详见[PixivLoginProxyServer](https://github.com/LamGC/PixivLoginProxyServer)项目的[Readme](https://github.com/LamGC/PixivLoginProxyServer/blob/master/README.md).
|
1. 从项目的[版本页面](https://github.com/LamGC/ContentGrabbingJi/releases)下载最新版色图姬主程序jar文件
|
||||||
|
2. 准备一个目录, 用于存放运行数据(这里以`./runData`为例子).
|
||||||
|
3. 将通过PixivLoginProxyServer获得的Pixiv登录会话文件放置在目录中(`./runData/cookies.store`).
|
||||||
|
4. 使用命令`java -jar <CGJ.jar> buildPassword -password "QQ机器人账号的密码"`构造一个登录用的密码.
|
||||||
|
5. 在数据目录创建一个配置文件`bot.properties`, 并添加如下内容:
|
||||||
|
```properties
|
||||||
|
bot.qq=<机器人QQ账号>
|
||||||
|
bot.password=<通过buildPassword获得的密码>
|
||||||
|
```
|
||||||
|
6. 在数据目录创建新文件夹`setting`, 并创建一个全局配置文件`global.properties`, 然后设置如下内容:
|
||||||
|
```properties
|
||||||
|
# 该配置为全局配置文件, 当群组没有特定配置时, 将使用全局配置.
|
||||||
|
# 管理员QQ (必填)
|
||||||
|
admin.adminId=<管理员QQ号>
|
||||||
|
# 是否允许r18作品
|
||||||
|
image.allowR18=false
|
||||||
|
# 查询排行榜默认的长度(比如15就是发送1~15名的作品), 该选项请适当调整, 设置过长可能导致超出聊天平台的最长消息长度, 导致发送失败!
|
||||||
|
ranking.itemCountLimit=15
|
||||||
|
# 排行榜图片数量(比如排行榜长度为15, 可以设置前10名有图片, 后5名没有图片), 调整该配置可有效控制消息发送所需时间.
|
||||||
|
ranking.imageCountLimit=15
|
||||||
|
# 搜索结果缓存时间, 默认2小时, 单位毫秒
|
||||||
|
cache.searchBody.expire=7200000
|
||||||
|
# 搜索结果长度. 该选项请适当调整, 设置过长可能导致超出聊天平台的最长消息长度, 导致发送失败!
|
||||||
|
search.itemCountLimit=8
|
||||||
|
```
|
||||||
|
7. 配置完成后, 准备一台Redis服务端, 用于缓存数据.
|
||||||
|
8. Redis服务器准备好后, 使用命令启动色图姬:`java -jar <CGJ.jar> botMode -botDataDir <数据目录> -redisAddress <Redis服务器地址> [-proxy 代理服务器地址]`
|
||||||
|
9. 完成!好好享受!
|
||||||
|
|
||||||
### Arguments ###
|
### 通过Docker部署 ###
|
||||||
> ENV参数名为环境变量名, 用于给Docker容器提供设置方式.
|
使用Docker将可以更好的管理色图姬所使用的资源,和管理色图姬的运行。
|
||||||
|
(正在完善中...)
|
||||||
|
|
||||||
- 通用参数
|
## 使用 ##
|
||||||
- `-proxy` / `ENV: CGJ_PROXY`: (**可选**) 设置代理
|
### 普通用户 ###
|
||||||
- 格式: `协议://地址:端口`
|
将色图姬部署完成,并且让色图姬在某个平台登录完成后,你就可以通过聊天平台向色图姬发起会话了!
|
||||||
- 示例: `socks5://127.0.0.1:1080`
|
使用 `.cgj` 向色图姬询问帮助信息!
|
||||||
- 机器人参数
|
|
||||||
- `-botDataDir` / `ENV: CGJ_BOT_DATA_DIR`: (**可选**) 设置`botMode`运行模式下机器人数据存储目录
|
|
||||||
- 格式: `路径`
|
|
||||||
- 示例: `./data`
|
|
||||||
- 默认: `./`
|
|
||||||
- `-redisAddress` / `ENV: CGJ_REDIS_URI`: (**必填, 计划支持可选**) Redis服务器地址
|
|
||||||
- 格式: `地址:端口`
|
|
||||||
- 示例: `127.0.0.1:6379`
|
|
||||||
|
|
||||||
> 例如以BotMode启动应用: `java -jar CGJ.jar botMode -proxy "socks5://127.0.0.1:1080 -redisAddress 127.0.0.1:6379`
|
另外,由于色图姬在开发过程中直接使用了原本应用在命令行中的参数解析工具,所以你需要了解一下色图姬命令的格式,
|
||||||
|
色图姬的命令格式为:
|
||||||
|
```bash
|
||||||
|
.cgj <命令> -<参数名> <参数值> ...
|
||||||
|
```
|
||||||
|
如果色图姬无法识别你的命令,那么它会发送一次帮助信息给你。
|
||||||
|
|
||||||
### Commands ###
|
### 管理员用户 ###
|
||||||
- `pluginMode`: CoolQ插件模式(依赖[酷Q机器人](https://cqp.cc/), 支持与CoolQ其他插件共存, 性能耗损大)
|
你应该注意到了,在部署过程中,你需要设置一个管理员QQ的配置,色图姬支持通过命令来管理色图姬的运行。
|
||||||
- `botMode`: Mirai独立模式(机器人独立运行, 不支持与其他插件共存, 性能耗损小)
|
目前支持的管理员命令:
|
||||||
- `collectionDownload`: 收藏下载, 以原图画质下载Cookie所属账号的所有收藏作品
|
```bash
|
||||||
- `getRecommends`: 将访问主页获得的推荐作品全部以原图画质下载
|
# 清除缓存
|
||||||
- `getRankingIllust`: 以原图画质下载指定排行榜类型的全部作品
|
.cgjadmin cleanCache
|
||||||
- `search`: 搜索指定内容并获取相关作品信息(不下载)
|
|
||||||
|
|
||||||
> 注意: 除去机器人模式外, 其他功能后续可能会出现改动.
|
# 设置配置项
|
||||||
|
# 如果不使用group参数, 则设置全局配置
|
||||||
|
.cgjadmin setProperty <-key 配置项名> <-value 配置项新值> [-group 指定群组]
|
||||||
|
|
||||||
|
# 查询配置项
|
||||||
|
# 如果不使用group参数, 则查询全局配置
|
||||||
|
.cgjadmin getProperty <-key 配置项名> [-group 指定群组]
|
||||||
|
|
||||||
|
# 保存所有配置
|
||||||
|
.cgjadmin saveProperties
|
||||||
|
|
||||||
|
# 读取所有配置
|
||||||
|
# 使用 reload 参数将会重载所有配置, 而不是覆盖读取
|
||||||
|
.cgjadmin loadProperties [-reload]
|
||||||
|
|
||||||
|
# 运行定时更新任务
|
||||||
|
# 可指定要更新数据的日期
|
||||||
|
.cgjadmin runUpdateTask [-date yyyy-MM-dd]
|
||||||
|
|
||||||
|
# 增加群组作品推送
|
||||||
|
# 如果增加了original参数, 则图片为原图发送
|
||||||
|
# 如果不指定group参数, 则群组为命令发送所在群组
|
||||||
|
.cgjadmin addPushGroup [-group 指定群组号] [-minTime 最小] [-floatTime 随机时间范围] [-rankingStart 排行榜起始排名]
|
||||||
|
[-rankingStop 排行榜结束排名] [-mode 排行榜模式] [-type 排行榜类型] [-original]
|
||||||
|
|
||||||
|
# 删除群组推送功能
|
||||||
|
# 如果不指定group参数, 则群组为命令发送所在群组
|
||||||
|
.cgjadmin removePushGroup [-group 指定群组号]
|
||||||
|
|
||||||
|
# 加载作品推送配置
|
||||||
|
.cgjadmin loadPushList
|
||||||
|
|
||||||
|
# 保存作品推送配置
|
||||||
|
.cgjadmin savePushList
|
||||||
|
|
||||||
|
# 获取被报告的作品列表
|
||||||
|
# 该命令会返回被其他用户报告其存在问题的作品列表
|
||||||
|
.cgjadmin getReportList
|
||||||
|
|
||||||
|
# 解封被报告的作品
|
||||||
|
.cgjadmin unBanArtwork <-id 被ban作品的Id>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 贡献 ##
|
||||||
|
向色图姬贡献不一定需要编程知识,向色图姬项目提出意见,反馈问题同样会为色图姬项目提供很大的帮助!
|
||||||
|
如果你在使用色图姬的过程中,遇到了Bug,可以通过色图姬项目的**Issues**使用[Bug反馈模板](https://github.com/LamGC/ContentGrabbingJi/issues/new?assignees=&labels=bug&template=Bug_Report.md&title=)向色图姬提供Bug信息。
|
||||||
|
如果是为色图姬提供一些新功能想法,或者对色图姬有什么意见,则可以直接通过Issues发起讨论。
|
||||||
|
|
||||||
|
如果你会Java开发,又想为色图姬提供一些新功能,可以通过Fork仓库的方法,实现后发起PR,合并到色图姬项目中!
|
||||||
|
向色图姬贡献代码,需要遵循一些贡献事项,如果你的代码不符合这些事项,PR有可能会被关闭!
|
||||||
|
> 注意:色图姬的初衷并没有任何恶意的意图,如果尝试向色图姬提供恶意功能或代码,PR将会被拒绝、关闭。
|
||||||
|
|
||||||
## LICENSE ##
|
## LICENSE ##
|
||||||
本项目基于 `GNU Affero General Public License 3.0` 开源许可协议开源,
|
本项目基于 `GNU Affero General Public License 3.0` 开源许可协议开源,
|
||||||
|
47
documents/interfaces/Pixiv搜索推荐候选接口.md
Normal file
47
documents/interfaces/Pixiv搜索推荐候选接口.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
## 搜索推荐接口 ##
|
||||||
|
### 说明 ###
|
||||||
|
可用于优化搜索内容。
|
||||||
|
|
||||||
|
### 接口地址 ###
|
||||||
|
```
|
||||||
|
GET https://www.pixiv.net/rpc/cps.php?
|
||||||
|
```
|
||||||
|
|
||||||
|
- 是否需要登录: `否`
|
||||||
|
- 是否为Pixiv标准接口返回格式: `否`
|
||||||
|
- 是否需要Referer请求头: `是`
|
||||||
|
|
||||||
|
> 补充: Referer请求头只要是Pixiv的就可以了.
|
||||||
|
|
||||||
|
### 参数 ###
|
||||||
|
Url参数:
|
||||||
|
- `keyword`: 搜索内容
|
||||||
|
|
||||||
|
> 注意: 搜索内容需要进行Url编码(空格要转换成`%20`而不是`+`)
|
||||||
|
### 请求示例 ###
|
||||||
|
```
|
||||||
|
GET https://www.pixiv.net/rpc/cps.php?keyword=幸运星
|
||||||
|
```
|
||||||
|
|
||||||
|
### 返回数据 ###
|
||||||
|
#### 数据示例 ####
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"candidates":[
|
||||||
|
{
|
||||||
|
"tag_name":"\u3089\u304d\u2606\u3059\u305f",
|
||||||
|
"access_count":"68286498",
|
||||||
|
"tag_translation":"\u5e78\u8fd0\u661f",
|
||||||
|
"type":"tag_translation"
|
||||||
|
}, // ...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### 字段说明 ####
|
||||||
|
- `candidates`: (`Object[]`) 搜索推荐候选列表
|
||||||
|
- `tag_name`: (`string`) 推荐词原名
|
||||||
|
- `access_count`: (`string` -> `number`) 推荐词访问量
|
||||||
|
- `tag_translation`: (`string`) 推荐词对应翻译名
|
||||||
|
- `type`: (`string`) 推荐词类型
|
||||||
|
- `tag_translation`: 标签翻译信息
|
||||||
|
- `prefix`: 前缀
|
319
documents/interfaces/Pixiv预加载数据.md
Normal file
319
documents/interfaces/Pixiv预加载数据.md
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
## Pixiv预加载数据 ##
|
||||||
|
### 说明 ###
|
||||||
|
作品预加载数据仅在加载作品页面时存在,处理后删除。
|
||||||
|
### 接口地址 ###
|
||||||
|
```
|
||||||
|
GET https://www.pixiv.net/artworks/{IllustId}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 是否需要登录: `是`
|
||||||
|
- 是否为Pixiv标准接口返回格式: `否`
|
||||||
|
- 是否需要Referer请求头: `否`
|
||||||
|
|
||||||
|
### 参数 ###
|
||||||
|
Url参数:
|
||||||
|
- `IllustId`: 作品Id
|
||||||
|
|
||||||
|
### 请求示例 ###
|
||||||
|
```
|
||||||
|
GET https://www.pixiv.net/artworks/82647306
|
||||||
|
```
|
||||||
|
|
||||||
|
### 返回数据 ###
|
||||||
|
> 注意: 该接口返回HTML格式数据,并不是JSON格式数据。
|
||||||
|
预加载数据需要对返回的Html数据进行解析,路径如下:
|
||||||
|
- CSS Select: meta#meta-preload-data
|
||||||
|
- html>head>meta#meta-preload-data
|
||||||
|
|
||||||
|
获得标签后,获取`content`属性即可获得预加载数据内容
|
||||||
|
|
||||||
|
#### 数据示例 ####
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"timestamp":"2020-07-01T11:32:30+09:00",
|
||||||
|
"illust":{
|
||||||
|
"82647306":{
|
||||||
|
"illustId":"82647306",
|
||||||
|
"illustTitle":"水着キャルちゃん!",
|
||||||
|
"illustComment":"水着のキャルちゃんはかわいいぞ!!",
|
||||||
|
"id":"82647306",
|
||||||
|
"title":"水着キャルちゃん!",
|
||||||
|
"description":"水着のキャルちゃんはかわいいぞ!!",
|
||||||
|
"illustType":0,
|
||||||
|
"createDate":"2020-06-29T12:28:06+00:00",
|
||||||
|
"uploadDate":"2020-06-29T12:28:06+00:00",
|
||||||
|
"restrict":0,
|
||||||
|
"xRestrict":0,
|
||||||
|
"sl":2,
|
||||||
|
"urls":{
|
||||||
|
"mini":"https://i.pximg.net/c/48x48/img-master/img/2020/06/29/21/28/06/82647306_p0_square1200.jpg",
|
||||||
|
"thumb":"https://i.pximg.net/c/250x250_80_a2/img-master/img/2020/06/29/21/28/06/82647306_p0_square1200.jpg",
|
||||||
|
"small":"https://i.pximg.net/c/540x540_70/img-master/img/2020/06/29/21/28/06/82647306_p0_master1200.jpg",
|
||||||
|
"regular":"https://i.pximg.net/img-master/img/2020/06/29/21/28/06/82647306_p0_master1200.jpg",
|
||||||
|
"original":"https://i.pximg.net/img-original/img/2020/06/29/21/28/06/82647306_p0.jpg"
|
||||||
|
},
|
||||||
|
"tags":{
|
||||||
|
"authorId":"55859246",
|
||||||
|
"isLocked":false,
|
||||||
|
"tags":[
|
||||||
|
{
|
||||||
|
"tag":"プリンセスコネクト!Re:Dive",
|
||||||
|
"locked":true,
|
||||||
|
"deletable":false,
|
||||||
|
"userId":"55859246",
|
||||||
|
"translation":{
|
||||||
|
"en":"公主连结Re:Dive"
|
||||||
|
},
|
||||||
|
"userName":"秋鳩むぎ"
|
||||||
|
}, // ...
|
||||||
|
],
|
||||||
|
"writable":true
|
||||||
|
},
|
||||||
|
"alt":"#プリンセスコネクト!Re:Dive 水着キャルちゃん! - 秋鳩むぎ的插画",
|
||||||
|
"storableTags":[
|
||||||
|
"_bee-JX46i",
|
||||||
|
"nAtxkwJ5Sy",
|
||||||
|
"q303ip6Ui5"
|
||||||
|
],
|
||||||
|
"userId":"55859246",
|
||||||
|
"userName":"秋鳩むぎ",
|
||||||
|
"userAccount":"pigeonwheat",
|
||||||
|
"userIllusts":{
|
||||||
|
"82647306":{
|
||||||
|
"illustId":"82647306",
|
||||||
|
"illustTitle":"水着キャルちゃん!",
|
||||||
|
"id":"82647306",
|
||||||
|
"title":"水着キャルちゃん!",
|
||||||
|
"illustType":0,
|
||||||
|
"xRestrict":0,
|
||||||
|
"restrict":0,
|
||||||
|
"sl":2,
|
||||||
|
"url":"https://i.pximg.net/c/250x250_80_a2/img-master/img/2020/06/29/21/28/06/82647306_p0_square1200.jpg",
|
||||||
|
"description":"水着のキャルちゃんはかわいいぞ!!",
|
||||||
|
"tags":[
|
||||||
|
"プリンセスコネクト!Re:Dive",
|
||||||
|
"キャル(プリコネ)",
|
||||||
|
"おへそ"
|
||||||
|
],
|
||||||
|
"userId":"55859246",
|
||||||
|
"userName":"秋鳩むぎ",
|
||||||
|
"width":2000,
|
||||||
|
"height":3000,
|
||||||
|
"pageCount":1,
|
||||||
|
"isBookmarkable":true,
|
||||||
|
"bookmarkData":null,
|
||||||
|
"alt":"#プリンセスコネクト!Re:Dive 水着キャルちゃん! - 秋鳩むぎ的插画",
|
||||||
|
"isAdContainer":false,
|
||||||
|
"titleCaptionTranslation":{
|
||||||
|
"workTitle":null,
|
||||||
|
"workCaption":null
|
||||||
|
},
|
||||||
|
"createDate":"2020-06-29T21:28:06+09:00",
|
||||||
|
"updateDate":"2020-06-29T21:28:06+09:00",
|
||||||
|
"seriesId":null,
|
||||||
|
"seriesTitle":null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"likeData":false,
|
||||||
|
"width":2000,
|
||||||
|
"height":3000,
|
||||||
|
"pageCount":1,
|
||||||
|
"bookmarkCount":39,
|
||||||
|
"likeCount":31,
|
||||||
|
"commentCount":2,
|
||||||
|
"responseCount":0,
|
||||||
|
"viewCount":239,
|
||||||
|
"isHowto":false,
|
||||||
|
"isOriginal":false,
|
||||||
|
"imageResponseOutData":[
|
||||||
|
],
|
||||||
|
"imageResponseData":[
|
||||||
|
],
|
||||||
|
"imageResponseCount":0,
|
||||||
|
"pollData":null,
|
||||||
|
"seriesNavData":null,
|
||||||
|
"descriptionBoothId":null,
|
||||||
|
"descriptionYoutubeId":null,
|
||||||
|
"comicPromotion":null,
|
||||||
|
"fanboxPromotion":null,
|
||||||
|
"contestBanners":[
|
||||||
|
],
|
||||||
|
"isBookmarkable":true,
|
||||||
|
"bookmarkData":null,
|
||||||
|
"contestData":null,
|
||||||
|
"zoneConfig":{
|
||||||
|
"responsive":{
|
||||||
|
"url":"https://pixon.ads-pixiv.net/show?zone_id=illust_responsive&format=js&s=1&up=0&a=22&ng=w&l=zh&uri=%2Fartworks%2F_PARAM_&is_spa=1&K=59bba275c645c&ab_test_digits_first=32&yuid=NDJ3gQk&suid=Pggb9mua3yznnr7lz&num=5efbf5be273&t=_bee-JX46i&t=b8b4-hqot7&t=kY01H5r3Pd"
|
||||||
|
},
|
||||||
|
"rectangle":{
|
||||||
|
"url":"https://pixon.ads-pixiv.net/show?zone_id=illust_rectangle&format=js&s=1&up=0&a=22&ng=w&l=zh&uri=%2Fartworks%2F_PARAM_&is_spa=1&K=59bba275c645c&ab_test_digits_first=32&yuid=NDJ3gQk&suid=Pggb9mua42776dfuu&num=5efbf5be810&t=_bee-JX46i&t=b8b4-hqot7&t=kY01H5r3Pd"
|
||||||
|
},
|
||||||
|
"500x500":{
|
||||||
|
"url":"https://pixon.ads-pixiv.net/show?zone_id=bigbanner&format=js&s=1&up=0&a=22&ng=w&l=zh&uri=%2Fartworks%2F_PARAM_&is_spa=1&K=59bba275c645c&ab_test_digits_first=32&yuid=NDJ3gQk&suid=Pggb9mua442sjsueo&num=5efbf5be568&t=_bee-JX46i&t=b8b4-hqot7&t=kY01H5r3Pd"
|
||||||
|
},
|
||||||
|
"header":{
|
||||||
|
"url":"https://pixon.ads-pixiv.net/show?zone_id=header&format=js&s=1&up=0&a=22&ng=w&l=zh&uri=%2Fartworks%2F_PARAM_&is_spa=1&K=59bba275c645c&ab_test_digits_first=32&yuid=NDJ3gQk&suid=Pggb9mua45spzoimt&num=5efbf5be155&t=_bee-JX46i&t=b8b4-hqot7&t=kY01H5r3Pd"
|
||||||
|
},
|
||||||
|
"footer":{
|
||||||
|
"url":"https://pixon.ads-pixiv.net/show?zone_id=footer&format=js&s=1&up=0&a=22&ng=w&l=zh&uri=%2Fartworks%2F_PARAM_&is_spa=1&K=59bba275c645c&ab_test_digits_first=32&yuid=NDJ3gQk&suid=Pggb9mua47f9zcoim&num=5efbf5be400&t=_bee-JX46i&t=b8b4-hqot7&t=kY01H5r3Pd"
|
||||||
|
},
|
||||||
|
"expandedFooter":{
|
||||||
|
"url":"https://pixon.ads-pixiv.net/show?zone_id=multiple_illust_viewer&format=js&s=1&up=0&a=22&ng=w&l=zh&uri=%2Fartworks%2F_PARAM_&is_spa=1&K=59bba275c645c&ab_test_digits_first=32&yuid=NDJ3gQk&suid=Pggb9mua4928ct0yw&num=5efbf5be471&t=_bee-JX46i&t=b8b4-hqot7&t=kY01H5r3Pd"
|
||||||
|
},
|
||||||
|
"logo":{
|
||||||
|
"url":"https://pixon.ads-pixiv.net/show?zone_id=logo_side&format=js&s=1&up=0&a=22&ng=w&l=zh&uri=%2Fartworks%2F_PARAM_&is_spa=1&K=59bba275c645c&ab_test_digits_first=32&yuid=NDJ3gQk&suid=Pggb9mua4aqu6i4sr&num=5efbf5be844&t=_bee-JX46i&t=b8b4-hqot7&t=kY01H5r3Pd"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extraData":{
|
||||||
|
"meta":{
|
||||||
|
"title":"#プリンセスコネクト!Re:Dive 水着キャルちゃん! - 秋鳩むぎ的插画 - pixiv",
|
||||||
|
"description":"この作品 「水着キャルちゃん!」 は 「プリンセスコネクト!Re:Dive」「キャル(プリコネ)」 等のタグがつけられた「秋鳩むぎ」さんのイラストです。 「水着のキャルちゃんはかわいいぞ!!」",
|
||||||
|
"canonical":"https://www.pixiv.net/artworks/82647306",
|
||||||
|
"alternateLanguages":{
|
||||||
|
"ja":"https://www.pixiv.net/artworks/82647306",
|
||||||
|
"en":"https://www.pixiv.net/en/artworks/82647306"
|
||||||
|
},
|
||||||
|
"descriptionHeader":"本作「水着キャルちゃん!」为附有「プリンセスコネクト!Re:Dive」「キャル(プリコネ)」等标签的插画。",
|
||||||
|
"ogp":{
|
||||||
|
"description":"水着のキャルちゃんはかわいいぞ!!",
|
||||||
|
"image":"https://embed.pixiv.net/decorate.php?illust_id=82647306",
|
||||||
|
"title":"#プリンセスコネクト!Re:Dive 水着キャルちゃん! - 秋鳩むぎ的插画 - pixiv",
|
||||||
|
"type":"article"
|
||||||
|
},
|
||||||
|
"twitter":{
|
||||||
|
"description":"水着のキャルちゃんはかわいいぞ!!",
|
||||||
|
"image":"https://embed.pixiv.net/decorate.php?illust_id=82647306",
|
||||||
|
"title":"水着キャルちゃん!",
|
||||||
|
"card":"summary_large_image"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"titleCaptionTranslation":{
|
||||||
|
"workTitle":null,
|
||||||
|
"workCaption":null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"user":{
|
||||||
|
"55859246":{
|
||||||
|
"userId":"55859246",
|
||||||
|
"name":"秋鳩むぎ",
|
||||||
|
"image":"https://i.pximg.net/user-profile/img/2020/06/29/21/20/14/18907670_b3f87d819f705ec418f120cd57f9dc41_50.jpg",
|
||||||
|
"imageBig":"https://i.pximg.net/user-profile/img/2020/06/29/21/20/14/18907670_b3f87d819f705ec418f120cd57f9dc41_170.jpg",
|
||||||
|
"premium":false,
|
||||||
|
"isFollowed":false,
|
||||||
|
"isMypixiv":false,
|
||||||
|
"isBlocking":false,
|
||||||
|
"background":null,
|
||||||
|
"partial":0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### 字段说明 ####
|
||||||
|
- `timestamp`: (`string`) 请求时间
|
||||||
|
- `illust`: (`Object`) 作品预加载信息
|
||||||
|
- `{illustId}`: 作品ID(跟页面请求的IllustId一样)
|
||||||
|
- `illustId`: (`string` -> `number`) 作品Id
|
||||||
|
- `illustTitle`: (`string`) 作品标题
|
||||||
|
- `illustComment`: (`string`) 作品说明
|
||||||
|
- `id`: (`string` -> `number`) 与`illustId`一致, 猜测是以兼容旧版本为目录而存在
|
||||||
|
- `title`: (`string`) 与`illustTitle`一致, 猜测是以兼容旧版本为目录而存在
|
||||||
|
- `description`: (`string`) 作品说明
|
||||||
|
- `illustType`: (`number`) 作品类型
|
||||||
|
- `0`: 插画作品
|
||||||
|
- `1`: 漫画作品
|
||||||
|
- `2`: 动图作品
|
||||||
|
- `createDate`: (`string`) 作品创建时间(或者是完成时间?)
|
||||||
|
- `updateDate`: (`string`) 作品上传时间
|
||||||
|
- `restrict`: (`number`) 作品限制级(意义不明, 可能是兼容性问题?)?
|
||||||
|
- `xRestrict`: (`number`) 作品是否为限制级, 基本准确, 少部分不一定(看Pixiv审核怎么理解了)
|
||||||
|
- `0`: 非限制级内容(即非R18作品)
|
||||||
|
- `1`: 限制级内容(即R18作品)
|
||||||
|
- `sl`: (`number`) 不明?
|
||||||
|
- `urls`: (`string`) 作品图片链接, 需要`Referer`请求头
|
||||||
|
- `mini`: (`string`) 小尺寸预览图
|
||||||
|
- `thumb`: (`string`) 小尺寸预览图
|
||||||
|
- `small`: (`string`) 小尺寸预览图
|
||||||
|
- `regular`: (`string`) 经压缩,没啥画质损失的原尺寸预览图
|
||||||
|
- `original`: (`string`) 原图
|
||||||
|
- `tags`: (`Object`) 作品标签信息
|
||||||
|
- `authorId`: (`string` -> `number`) 作者用户Id
|
||||||
|
- `isLocked`: (`boolean`) 标签是否锁定(即不可被访客更改)
|
||||||
|
- `tags`: (`Object[]`) 标签信息数组
|
||||||
|
- `tag`: (`string`) 标签原始名
|
||||||
|
- `locked`: (`boolean`) 标签是否不可更改
|
||||||
|
- `deletable`: (`boolean`) 标签能否被删除?
|
||||||
|
- `userId`: (`string` -> `number`) 用户Id
|
||||||
|
- `translation`: (`Object`) 标签翻译
|
||||||
|
- `{语种}`: 翻译名
|
||||||
|
- `userName`: (`string`) 用户名
|
||||||
|
- `alt`: (`string`) 简略介绍信息(在图片加载失败时可提供给`img`标签使用)
|
||||||
|
- `storableTags`: (`string[]`) 不明?
|
||||||
|
- `userId`: (`string` -> `number`) 作者用户Id
|
||||||
|
- `userName`: (`string`) 作者用户名
|
||||||
|
- `userAccount`: (`string`) 作者登录名
|
||||||
|
- `userIllusts`: (`Object`) 作品信息?
|
||||||
|
- `{IllustId}`: 与请求IllustId一样
|
||||||
|
- (请转到:Pixiv作品信息获取接口.md)
|
||||||
|
- `likeData`: (`boolean?`) 不明?
|
||||||
|
- `width`: (`number`) 作品长度
|
||||||
|
- `height`: (`number`) 作品高度
|
||||||
|
- `pageCount`: (`number`) 作品页数
|
||||||
|
- `bookmarkCount`: (`number`) 作品公开的收藏数
|
||||||
|
- `likeCount`: (`number`) 作品喜欢(点赞)数
|
||||||
|
- `commentCount`: (`number`) 作品评论数
|
||||||
|
- `responseCount`: (`number`) 作品响应数?
|
||||||
|
- `viewCount`: (`number`) 作品阅览数
|
||||||
|
- `isHowto`: (`boolean`) 不明?
|
||||||
|
- `isOriginal`: (`boolean`) 不明?
|
||||||
|
- `imageResponseOutData`: (`Unknown[]`) 不明?
|
||||||
|
- `imageResponseData`: (`Unknown[]`) 不明?
|
||||||
|
- `imageResponseCount`: (`number`) 不明?
|
||||||
|
- `pollData`: (`Unknown`) 不明?
|
||||||
|
- `seriesNavData`: (`Unknown`) 不明?
|
||||||
|
- `descriptionBoothId`: (`Unknown`) 不明?
|
||||||
|
- `descriptionYoutubeId`: (`Unknown`) 不明?
|
||||||
|
- `comicPromotion`: (`Unknown`) 不明?
|
||||||
|
- `fanboxPromotion`: (`Unknown`) 不明?
|
||||||
|
- `contestBanners`: (`Unknown[]`) 不明?
|
||||||
|
// TODO 待补充
|
||||||
|
|
||||||
|
- `isBookmarkable`: (`boolean`) 不明?
|
||||||
|
- `bookmarkData`: (`Unknown`) 不明?
|
||||||
|
- `contestData`: (`Unknown`) 不明?
|
||||||
|
- `zoneConfig`: (`Object`) 猜测是广告信息?
|
||||||
|
- (基本不用, 忽略...)
|
||||||
|
- `extraData`: (`Object`) 扩展数据
|
||||||
|
- `meta`: (`Object`) 元数据
|
||||||
|
- `title`: (`string`) 网页标题
|
||||||
|
- `description`: (`string`) Pixiv生成的作品说明
|
||||||
|
- `canonical`: (`string`) 作品页面链接
|
||||||
|
- `alternateLanguages`: (`Object`) 不同语言的作品页面链接
|
||||||
|
- `{语种}`: (`string`) 对应语种的作品链接
|
||||||
|
- `descriptionHeader`: (`string`) 说明文档(不过似乎是对应了会话所属账号的语种?)
|
||||||
|
- `ogp`: (`Object`) 猜测是某平台的分享数据?
|
||||||
|
- `description`: (`string`) 说明内容
|
||||||
|
- `image`: (`string`) 预览图链接
|
||||||
|
- `title`: (`string`) 分享标题
|
||||||
|
- `type`: (`string`) 分享类型?
|
||||||
|
- `twitter`: (`Object`)
|
||||||
|
- `description`: (`string`) 说明内容
|
||||||
|
- `image`: (`string`) 预览图链接
|
||||||
|
- `title`: (`string`) 分享标题
|
||||||
|
- `card`: (`string`) 分享类型?
|
||||||
|
- `titleCaptionTranslation`: (`Object`) 不明?
|
||||||
|
- `workTitle`: (`Unknown`) 不明?
|
||||||
|
- `workCaption`: (`Unknown`) 不明?
|
||||||
|
- `user`: (`Object`) 作者预加载信息
|
||||||
|
- `{userId}`: 可通过`illust.{illustId}.userId`获得
|
||||||
|
- `userId`: (`string` -> `number`) 作者用户Id
|
||||||
|
- `name`: (`string`) 作者用户名
|
||||||
|
- `image`: (`string`) 作者用户头像(小尺寸)
|
||||||
|
- `imageBig`: (`string`) 作者用户头像(大尺寸)
|
||||||
|
- `premium`: (`boolean`) 作者是否为Pixiv会员
|
||||||
|
- `isFollowed`: (`boolean`) 当前会话用户是否已关注
|
||||||
|
- `isMypixiv`: (`boolean`) 是否为当前会话本人?
|
||||||
|
- `isBlocking`: (`boolean`) 是否正在被封禁
|
||||||
|
- `background`: (`Object`) 背景图片?
|
||||||
|
- `partial`: (`number`) 不明?
|
8
pom.xml
8
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>net.lamgc</groupId>
|
<groupId>net.lamgc</groupId>
|
||||||
<artifactId>ContentGrabbingJi</artifactId>
|
<artifactId>ContentGrabbingJi</artifactId>
|
||||||
<version>2.5.2-20200630.2-SNAPSHOT</version>
|
<version>2.5.2-20200709.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
<mirai.CoreVersion>1.0.2</mirai.CoreVersion>
|
<mirai.CoreVersion>1.0.4</mirai.CoreVersion>
|
||||||
<mirai.JaptVersion>1.1.1</mirai.JaptVersion>
|
<mirai.JaptVersion>1.1.1</mirai.JaptVersion>
|
||||||
<kotlin.version>1.3.71</kotlin.version>
|
<kotlin.version>1.3.71</kotlin.version>
|
||||||
<ktor.version>1.3.2</ktor.version>
|
<ktor.version>1.3.2</ktor.version>
|
||||||
@ -94,7 +94,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.lamgc</groupId>
|
<groupId>net.lamgc</groupId>
|
||||||
<artifactId>java-utils</artifactId>
|
<artifactId>java-utils</artifactId>
|
||||||
<version>1.2.0_20200517.1-SNAPSHOT</version>
|
<version>1.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -121,7 +121,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.lz1998</groupId>
|
<groupId>net.lz1998</groupId>
|
||||||
<artifactId>spring-cq</artifactId>
|
<artifactId>spring-cq</artifactId>
|
||||||
<version>4.14.0.6</version>
|
<version>4.15.0.1</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
@ -8,7 +8,7 @@ import com.google.gson.JsonObject;
|
|||||||
import net.lamgc.cgj.bot.boot.ApplicationBoot;
|
import net.lamgc.cgj.bot.boot.ApplicationBoot;
|
||||||
import net.lamgc.cgj.bot.boot.BotGlobal;
|
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||||
import net.lamgc.cgj.bot.framework.cli.ConsoleMain;
|
import net.lamgc.cgj.bot.framework.cli.ConsoleMain;
|
||||||
import net.lamgc.cgj.bot.framework.coolq.CQConfig;
|
import net.lamgc.cgj.bot.framework.coolq.SpringCQApplication;
|
||||||
import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
|
import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
|
||||||
import net.lamgc.cgj.pixiv.PixivDownload;
|
import net.lamgc.cgj.pixiv.PixivDownload;
|
||||||
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||||
@ -25,20 +25,15 @@ import org.apache.http.util.EntityUtils;
|
|||||||
import org.apache.tomcat.util.http.fileupload.util.Streams;
|
import org.apache.tomcat.util.http.fileupload.util.Streams;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(Main.class);
|
private final static Logger log = LoggerFactory.getLogger(Main.class);
|
||||||
@ -105,17 +100,7 @@ public class Main {
|
|||||||
|
|
||||||
@Command
|
@Command
|
||||||
public static void pluginMode(@Argument(name = "args", force = false) String argsStr) {
|
public static void pluginMode(@Argument(name = "args", force = false) String argsStr) {
|
||||||
log.info("酷Q机器人根目录: {}", BotGlobal.getGlobal().getDataStoreDir().getPath());
|
new SpringCQApplication().start(argsStr);
|
||||||
CQConfig.init();
|
|
||||||
Pattern pattern = Pattern.compile("/\\s*(\".+?\"|[^:\\s])+((\\s*:\\s*(\".+?\"|[^\\s])+)|)|(\".+?\"|[^\"\\s])+");
|
|
||||||
Matcher matcher = pattern.matcher(Strings.nullToEmpty(argsStr));
|
|
||||||
ArrayList<String> argsList = new ArrayList<>();
|
|
||||||
while (matcher.find()) {
|
|
||||||
argsList.add(matcher.group());
|
|
||||||
}
|
|
||||||
String[] args = new String[argsList.size()];
|
|
||||||
argsList.toArray(args);
|
|
||||||
SpringApplication.run(Main.class, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
|
@ -11,12 +11,17 @@ import net.lamgc.cgj.bot.cache.JsonRedisCacheStore;
|
|||||||
import net.lamgc.cgj.bot.event.BufferedMessageSender;
|
import net.lamgc.cgj.bot.event.BufferedMessageSender;
|
||||||
import net.lamgc.cgj.bot.sort.PreLoadDataAttribute;
|
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.bot.util.PixivUtils;
|
||||||
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.PixivSearchLinkBuilder;
|
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||||
import net.lamgc.cgj.pixiv.PixivURL;
|
import net.lamgc.cgj.pixiv.PixivURL;
|
||||||
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.apache.http.HttpHeaders;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -315,6 +320,16 @@ public class BotCommandProcess {
|
|||||||
@Argument(name = "p", force = false, defaultValue = "1") int pagesIndex
|
@Argument(name = "p", force = false, defaultValue = "1") int pagesIndex
|
||||||
) throws IOException, InterruptedException {
|
) throws IOException, InterruptedException {
|
||||||
log.debug("正在执行搜索...");
|
log.debug("正在执行搜索...");
|
||||||
|
PixivSearchLinkBuilder linkBuilder = PixivUtils.buildSearchLinkBuilder(content, type, area, includeKeywords,
|
||||||
|
excludeKeywords, contentOption, pagesIndex);
|
||||||
|
int recommendKeywordCount = 0;
|
||||||
|
try {
|
||||||
|
recommendKeywordCount = Integer.parseInt(SettingProperties.getProperties(fromGroup)
|
||||||
|
.getProperty("search.recommendKeywordCount", "0"));
|
||||||
|
} catch(NumberFormatException e) {
|
||||||
|
log.warn("配置项 search.recommendKeywordCount 的值无效");
|
||||||
|
}
|
||||||
|
addRecommendKeywords(linkBuilder, recommendKeywordCount);
|
||||||
JsonObject resultBody = CacheStoreCentral.getCentral()
|
JsonObject resultBody = CacheStoreCentral.getCentral()
|
||||||
.getSearchBody(content, type, area, includeKeywords, excludeKeywords, contentOption, pagesIndex);
|
.getSearchBody(content, type, area, includeKeywords, excludeKeywords, contentOption, pagesIndex);
|
||||||
|
|
||||||
@ -525,6 +540,43 @@ public class BotCommandProcess {
|
|||||||
return "色图姬收到了你的报告,将屏蔽该作品并对作品违规情况进行核实,感谢你的反馈!";
|
return "色图姬收到了你的报告,将屏蔽该作品并对作品违规情况进行核实,感谢你的反馈!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据Pixiv搜索推荐列表补充关键词.
|
||||||
|
* <p>该操作可能会优化搜索效果.</p>
|
||||||
|
* @param searchLinkBuilder PixivSearchLinkBuilder对象
|
||||||
|
* @param includeKeywordsCount 需要添加的关键词数量
|
||||||
|
* @throws IOException 当获取推荐列表发生异常时抛出.
|
||||||
|
*/
|
||||||
|
private static void addRecommendKeywords(PixivSearchLinkBuilder searchLinkBuilder, int includeKeywordsCount)
|
||||||
|
throws IOException {
|
||||||
|
if(includeKeywordsCount <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HttpGet request = BotGlobal.getGlobal().getPixivDownload()
|
||||||
|
.createHttpGetRequest(PixivURL.PIXIV_SEARCH_RECOMMENDS
|
||||||
|
.replace("{content}", searchLinkBuilder.getContent()));
|
||||||
|
request.addHeader(HttpHeaders.REFERER, "https://www.pixiv.net/");
|
||||||
|
|
||||||
|
HttpResponse response = BotGlobal.getGlobal().getPixivDownload().getHttpClient().execute(request);
|
||||||
|
String responseBody = EntityUtils.toString(response.getEntity());
|
||||||
|
if(response.getStatusLine().getStatusCode() != 200) {
|
||||||
|
throw new IOException("Interface request failure: " + response.getStatusLine() +
|
||||||
|
", response body: '" + responseBody + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject resultObject = BotGlobal.getGlobal().getGson()
|
||||||
|
.fromJson(responseBody, JsonObject.class);
|
||||||
|
if(!resultObject.has("candidates")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray recommendsArr = resultObject.getAsJsonArray("candidates");
|
||||||
|
for (int count = 0; count < includeKeywordsCount && count < recommendsArr.size(); count++) {
|
||||||
|
searchLinkBuilder.addIncludeKeyword(
|
||||||
|
recommendsArr.get(count).getAsJsonObject().get("tag_name").getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查某一作品是否被报告
|
* 检查某一作品是否被报告
|
||||||
* @param illustId 作品Id
|
* @param illustId 作品Id
|
||||||
|
@ -4,7 +4,6 @@ import com.google.common.base.Throwables;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ public class RandomIntervalSendTimer extends TimerTask {
|
|||||||
private final long time;
|
private final long time;
|
||||||
private final int floatTime;
|
private final int floatTime;
|
||||||
private final AtomicBoolean loop = new AtomicBoolean();
|
private final AtomicBoolean loop = new AtomicBoolean();
|
||||||
private final AtomicBoolean start = new AtomicBoolean();
|
private final AtomicBoolean running = new AtomicBoolean();
|
||||||
private final String hashId = Integer.toHexString(this.hashCode());
|
private final String hashId = Integer.toHexString(this.hashCode());
|
||||||
|
|
||||||
|
|
||||||
@ -88,7 +87,6 @@ public class RandomIntervalSendTimer extends TimerTask {
|
|||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.floatTime = floatTime;
|
this.floatTime = floatTime;
|
||||||
timerMap.put(timerId, this);
|
|
||||||
if(startNow) {
|
if(startNow) {
|
||||||
start(loop);
|
start(loop);
|
||||||
}
|
}
|
||||||
@ -108,21 +106,18 @@ public class RandomIntervalSendTimer extends TimerTask {
|
|||||||
Date nextDate = new Date();
|
Date nextDate = new Date();
|
||||||
nextDate.setTime(nextDate.getTime() + nextDelay);
|
nextDate.setTime(nextDate.getTime() + nextDelay);
|
||||||
log.info("定时器 {} 下一延迟: {}ms ({})", hashId, nextDelay, nextDate);
|
log.info("定时器 {} 下一延迟: {}ms ({})", hashId, nextDelay, nextDate);
|
||||||
if(start.get()) {
|
if(running.get()) {
|
||||||
try {
|
reset();
|
||||||
Field state = this.getClass().getSuperclass().getDeclaredField("state");
|
return;
|
||||||
state.setAccessible(true);
|
|
||||||
state.setInt(this, 0);
|
|
||||||
state.setAccessible(false);
|
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
start.set(true);
|
running.set(true);
|
||||||
timer.schedule(this, nextDelay);
|
timer.schedule(this, nextDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
timerMap.put(timerId, (RandomIntervalSendTimer) clone());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
log.info("定时器 {} 开始执行...(Sender: {}@{})", this.hashId, sender.getClass().getSimpleName(), sender.hashCode());
|
log.info("定时器 {} 开始执行...(Sender: {}@{})", this.hashId, sender.getClass().getSimpleName(), sender.hashCode());
|
||||||
@ -145,7 +140,7 @@ public class RandomIntervalSendTimer extends TimerTask {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel() {
|
public boolean cancel() {
|
||||||
start.set(false);
|
running.set(false);
|
||||||
loop.set(false);
|
loop.set(false);
|
||||||
return super.cancel();
|
return super.cancel();
|
||||||
}
|
}
|
||||||
@ -158,4 +153,18 @@ public class RandomIntervalSendTimer extends TimerTask {
|
|||||||
timerMap.remove(this.timerId);
|
timerMap.remove(this.timerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 克隆一个参数完全一样的TimerTask对象.
|
||||||
|
* @return 返回对象不同, 参数相同的TimerTask对象.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||||
|
public Object clone() {
|
||||||
|
RandomIntervalSendTimer newTimerTask = new RandomIntervalSendTimer(
|
||||||
|
this.timerId, this.sender,
|
||||||
|
time, floatTime,
|
||||||
|
running.get(), loop.get());
|
||||||
|
this.destroy();
|
||||||
|
return newTimerTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import net.lamgc.cgj.bot.BotCode;
|
|||||||
import net.lamgc.cgj.bot.BotCommandProcess;
|
import net.lamgc.cgj.bot.BotCommandProcess;
|
||||||
import net.lamgc.cgj.bot.SettingProperties;
|
import net.lamgc.cgj.bot.SettingProperties;
|
||||||
import net.lamgc.cgj.bot.boot.BotGlobal;
|
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||||
|
import net.lamgc.cgj.bot.util.PixivUtils;
|
||||||
import net.lamgc.cgj.exception.HttpRequestException;
|
import net.lamgc.cgj.exception.HttpRequestException;
|
||||||
import net.lamgc.cgj.pixiv.PixivDownload;
|
import net.lamgc.cgj.pixiv.PixivDownload;
|
||||||
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||||
@ -405,73 +406,11 @@ public final class CacheStoreCentral {
|
|||||||
return PixivDownload.getRanking(result, start - 1, range);
|
return PixivDownload.getRanking(result, start - 1, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public JsonObject getSearchBody(PixivSearchLinkBuilder searchLinkBuilder) throws IOException {
|
||||||
* 获取搜索结果
|
log.debug("正在搜索作品, 条件: {}", searchLinkBuilder.getSearchCondition());
|
||||||
* @param content 搜索内容
|
|
||||||
* @param type 类型
|
|
||||||
* @param area 范围
|
|
||||||
* @param includeKeywords 包含关键词
|
|
||||||
* @param excludeKeywords 排除关键词
|
|
||||||
* @param contentOption 内容类型
|
|
||||||
* @return 返回完整搜索结果
|
|
||||||
* @throws IOException 当请求发生异常, 或接口返回异常信息时抛出.
|
|
||||||
*/
|
|
||||||
public JsonObject getSearchBody(
|
|
||||||
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());
|
|
||||||
|
|
||||||
Locker<String> locker
|
Locker<String> locker
|
||||||
= buildSyncKey(searchBuilder.buildURL());
|
= buildSyncKey(searchLinkBuilder.buildURL());
|
||||||
String requestUrl = locker.getKey();
|
String requestUrl = locker.getKey();
|
||||||
log.debug("RequestUrl: {}", requestUrl);
|
log.debug("RequestUrl: {}", requestUrl);
|
||||||
JsonObject resultBody = null;
|
JsonObject resultBody = null;
|
||||||
@ -524,6 +463,31 @@ public final class CacheStoreCentral {
|
|||||||
return resultBody;
|
return resultBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取搜索结果
|
||||||
|
* @param content 搜索内容
|
||||||
|
* @param type 类型
|
||||||
|
* @param area 范围
|
||||||
|
* @param includeKeywords 包含关键词
|
||||||
|
* @param excludeKeywords 排除关键词
|
||||||
|
* @param contentOption 内容类型
|
||||||
|
* @return 返回完整搜索结果
|
||||||
|
* @throws IOException 当请求发生异常, 或接口返回异常信息时抛出.
|
||||||
|
*/
|
||||||
|
public JsonObject getSearchBody(
|
||||||
|
String content,
|
||||||
|
String type,
|
||||||
|
String area,
|
||||||
|
String includeKeywords,
|
||||||
|
String excludeKeywords,
|
||||||
|
String contentOption,
|
||||||
|
int pageIndex
|
||||||
|
) throws IOException {
|
||||||
|
return getSearchBody(PixivUtils.buildSearchLinkBuilder(content, type, area, includeKeywords,
|
||||||
|
excludeKeywords, contentOption, pageIndex));
|
||||||
|
}
|
||||||
|
|
||||||
protected ImageChecksum getImageChecksum(int illustId, int pageIndex) {
|
protected ImageChecksum getImageChecksum(int illustId, int pageIndex) {
|
||||||
String cacheKey = illustId + ":" + pageIndex;
|
String cacheKey = illustId + ":" + pageIndex;
|
||||||
if(!imageChecksumCache.exists(cacheKey)) {
|
if(!imageChecksumCache.exists(cacheKey)) {
|
||||||
|
@ -158,7 +158,7 @@ public class LocalHashCacheStore<T> implements CacheStore<T>, Cleanable {
|
|||||||
expireKeySet.forEach(cache::remove);
|
expireKeySet.forEach(cache::remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CacheObject<T> implements Comparable<CacheObject<T>> {
|
private static class CacheObject<T> implements Comparable<CacheObject<T>> {
|
||||||
|
|
||||||
private final AtomicReference<T> value;
|
private final AtomicReference<T> value;
|
||||||
private final AtomicReference<Date> expire;
|
private final AtomicReference<Date> expire;
|
||||||
|
@ -26,7 +26,6 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -40,15 +39,13 @@ public class BotEventHandler implements EventHandler {
|
|||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(BotEventHandler.class);
|
private final static Logger log = LoggerFactory.getLogger(BotEventHandler.class);
|
||||||
|
|
||||||
private final static Map<Long, AtomicBoolean> muteStateMap = new Hashtable<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息事件执行器
|
* 消息事件执行器
|
||||||
*/
|
*/
|
||||||
private final static EventExecutor executor = new EventExecutor(new TimeLimitThreadPoolExecutor(
|
private final static EventExecutor executor = new EventExecutor(new TimeLimitThreadPoolExecutor(
|
||||||
180000, // 3minThr
|
180000, // 3min limit
|
||||||
Math.max(Runtime.getRuntime().availableProcessors(), 4),
|
Math.max(Runtime.getRuntime().availableProcessors(), 4), // 4 ~ processors
|
||||||
Math.min(Math.max(Runtime.getRuntime().availableProcessors(), 4), 32),
|
Math.min(Math.max(Runtime.getRuntime().availableProcessors() * 2, 8), 32),// (8 ~ processors * 2) ~ 32
|
||||||
30L,
|
30L,
|
||||||
TimeUnit.SECONDS,
|
TimeUnit.SECONDS,
|
||||||
new LinkedBlockingQueue<>(1536),
|
new LinkedBlockingQueue<>(1536),
|
||||||
@ -167,9 +164,6 @@ public class BotEventHandler implements EventHandler {
|
|||||||
log.debug(event.toString());
|
log.debug(event.toString());
|
||||||
if(mismatch(msg)) {
|
if(mismatch(msg)) {
|
||||||
return;
|
return;
|
||||||
} else if(isMute(event.getFromGroup())) {
|
|
||||||
log.debug("机器人已被禁言, 忽略请求.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("/\\s*(\".+?\"|[^:\\s])+((\\s*:\\s*(\".+?\"|[^\\s])+)|)|(\".+?\"|[^\"\\s])+");
|
Pattern pattern = Pattern.compile("/\\s*(\".+?\"|[^:\\s])+((\\s*:\\s*(\".+?\"|[^\\s])+)|)|(\".+?\"|[^\"\\s])+");
|
||||||
@ -236,7 +230,7 @@ public class BotEventHandler implements EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
long processTime = System.currentTimeMillis() - time;
|
long processTime = System.currentTimeMillis() - time;
|
||||||
if(!Objects.isNull(result) && result instanceof String && !isMute(event.getFromGroup())) {
|
if(!Objects.isNull(result) && result instanceof String) {
|
||||||
try {
|
try {
|
||||||
int sendResult = event.sendMessage((String) result);
|
int sendResult = event.sendMessage((String) result);
|
||||||
if (sendResult < 0) {
|
if (sendResult < 0) {
|
||||||
@ -248,8 +242,6 @@ public class BotEventHandler implements EventHandler {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("发送消息时发生异常", e);
|
log.error("发送消息时发生异常", e);
|
||||||
}
|
}
|
||||||
} else if(isMute(event.getFromGroup())) {
|
|
||||||
log.warn("命令反馈时机器人已被禁言, 跳过反馈.");
|
|
||||||
}
|
}
|
||||||
long totalTime = System.currentTimeMillis() - time;
|
long totalTime = System.currentTimeMillis() - time;
|
||||||
log.info("命令反馈完成.(事件耗时: {}ms, P: {}%({}ms), R: {}%({}ms))", totalTime,
|
log.info("命令反馈完成.(事件耗时: {}ms, P: {}%({}ms), R: {}%({}ms))", totalTime,
|
||||||
@ -266,45 +258,4 @@ public class BotEventHandler implements EventHandler {
|
|||||||
return !message.startsWith(COMMAND_PREFIX) && !message.startsWith(ADMIN_COMMAND_PREFIX);
|
return !message.startsWith(COMMAND_PREFIX) && !message.startsWith(ADMIN_COMMAND_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询某群组中Bot是否被禁言
|
|
||||||
* @param groupId 待查询的群组号
|
|
||||||
* @return 如果被禁言, 返回true, 如果未被禁言或禁言情况未知, 返回false
|
|
||||||
*/
|
|
||||||
private static boolean isMute(long groupId) {
|
|
||||||
Boolean mute = isMute(groupId, false);
|
|
||||||
return mute != null && mute;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询某群是否被禁言.
|
|
||||||
* @param groupId 群组Id
|
|
||||||
* @param rawValue 是否返回原始值(当没有该群状态, 且本参数为true时, 将返回null)
|
|
||||||
* @return 返回状态值, 如无该群禁言记录且rawValue = true, 则返回null
|
|
||||||
*/
|
|
||||||
public static Boolean isMute(long groupId, boolean rawValue) {
|
|
||||||
if(groupId <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
AtomicBoolean state = muteStateMap.get(groupId);
|
|
||||||
if(state == null && rawValue) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return state != null && state.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置机器人禁言状态.
|
|
||||||
* <p>设置该项可防止因机器人在禁言期间反馈请求导致被封号.</p>
|
|
||||||
* @param mute 如果被禁言, 传入true
|
|
||||||
*/
|
|
||||||
public static void setMuteState(long groupId, boolean mute) {
|
|
||||||
if(!muteStateMap.containsKey(groupId)) {
|
|
||||||
muteStateMap.put(groupId, new AtomicBoolean(mute));
|
|
||||||
} else {
|
|
||||||
muteStateMap.get(groupId).set(mute);
|
|
||||||
}
|
|
||||||
log.warn("群组 {} 机器人禁言状态已变更: {}", groupId, mute ? "已禁言" : "已解除");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public abstract class MessageEvent implements EventObject, MessageSender {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.getClass().getSimpleName() + "@" + this.hashCode() + "{" +
|
return this.getClass().getSimpleName() + "@" + Integer.toHexString(this.hashCode()) + "{" +
|
||||||
"fromGroup=" + getFromGroup() +
|
"fromGroup=" + getFromGroup() +
|
||||||
", fromQQ=" + getFromQQ() +
|
", fromQQ=" + getFromQQ() +
|
||||||
", message='" + getMessage() + '\'' +
|
", message='" + getMessage() + '\'' +
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package net.lamgc.cgj.bot.framework.coolq;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
||||||
import net.lz1998.cq.CQGlobal;
|
|
||||||
import net.lz1998.cq.EnableCQ;
|
|
||||||
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
@EnableCQ
|
|
||||||
public class CQConfig {
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
CQGlobal.pluginList.add(CQPluginMain.class);
|
|
||||||
CQGlobal.executor = new ThreadPoolExecutor(
|
|
||||||
(int) Math.ceil(Runtime.getRuntime().availableProcessors() / 2F),
|
|
||||||
Runtime.getRuntime().availableProcessors(),
|
|
||||||
25, TimeUnit.SECONDS,
|
|
||||||
new LinkedBlockingQueue<>(512),
|
|
||||||
new ThreadFactoryBuilder()
|
|
||||||
.setNameFormat("Plugin-ProcessThread-%d")
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -3,6 +3,7 @@ package net.lamgc.cgj.bot.framework.coolq;
|
|||||||
import net.lamgc.cgj.bot.boot.ApplicationBoot;
|
import net.lamgc.cgj.bot.boot.ApplicationBoot;
|
||||||
import net.lamgc.cgj.bot.event.BotEventHandler;
|
import net.lamgc.cgj.bot.event.BotEventHandler;
|
||||||
import net.lamgc.cgj.bot.framework.coolq.message.SpringCQMessageEvent;
|
import net.lamgc.cgj.bot.framework.coolq.message.SpringCQMessageEvent;
|
||||||
|
import net.lamgc.cgj.bot.framework.coolq.message.SpringCQMessageSenderFactory;
|
||||||
import net.lamgc.utils.event.EventHandler;
|
import net.lamgc.utils.event.EventHandler;
|
||||||
import net.lz1998.cq.event.message.CQDiscussMessageEvent;
|
import net.lz1998.cq.event.message.CQDiscussMessageEvent;
|
||||||
import net.lz1998.cq.event.message.CQGroupMessageEvent;
|
import net.lz1998.cq.event.message.CQGroupMessageEvent;
|
||||||
@ -13,13 +14,15 @@ import net.lz1998.cq.robot.CoolQ;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class CQPluginMain extends CQPlugin implements EventHandler {
|
public class CQPluginMain extends CQPlugin implements EventHandler {
|
||||||
|
|
||||||
|
private final static AtomicBoolean initialState = new AtomicBoolean();
|
||||||
|
|
||||||
public CQPluginMain() {
|
public CQPluginMain() {
|
||||||
// TODO(LamGC, 2020.04.21): SpringCQ无法适配MessageSenderBuilder
|
|
||||||
// MessageSenderBuilder.setCurrentMessageSenderFactory(new SpringCQMessageSenderFactory());
|
|
||||||
ApplicationBoot.initialBot();
|
|
||||||
LoggerFactory.getLogger(CQPluginMain.class)
|
LoggerFactory.getLogger(CQPluginMain.class)
|
||||||
.info("BotEventHandler.COMMAND_PREFIX = {}", BotEventHandler.COMMAND_PREFIX);
|
.info("BotEventHandler.COMMAND_PREFIX = {}", BotEventHandler.COMMAND_PREFIX);
|
||||||
}
|
}
|
||||||
@ -46,6 +49,13 @@ public class CQPluginMain extends CQPlugin implements EventHandler {
|
|||||||
* @return 是否拦截消息
|
* @return 是否拦截消息
|
||||||
*/
|
*/
|
||||||
private static int processMessage(CoolQ cq, CQMessageEvent event) {
|
private static int processMessage(CoolQ cq, CQMessageEvent event) {
|
||||||
|
SpringCQMessageSenderFactory.setCoolQ(cq);
|
||||||
|
synchronized (initialState) {
|
||||||
|
if(!initialState.get()) {
|
||||||
|
ApplicationBoot.initialBot();
|
||||||
|
initialState.set(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(BotEventHandler.mismatch(event.getMessage())) {
|
if(BotEventHandler.mismatch(event.getMessage())) {
|
||||||
return MESSAGE_IGNORE;
|
return MESSAGE_IGNORE;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
package net.lamgc.cgj.bot.framework.coolq;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.context.event.ContextClosedEvent;
|
||||||
|
import org.springframework.context.event.ContextStoppedEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringCQApplication {
|
||||||
|
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(SpringCQApplication.class);
|
||||||
|
|
||||||
|
private final Object quitLock = new Object();
|
||||||
|
|
||||||
|
public void start(String argsStr) {
|
||||||
|
log.info("酷Q机器人根目录: {}", BotGlobal.getGlobal().getDataStoreDir().getPath());
|
||||||
|
Pattern pattern = Pattern.compile("/\\s*(\".+?\"|[^:\\s])+((\\s*:\\s*(\".+?\"|[^\\s])+)|)|(\".+?\"|[^\"\\s])+");
|
||||||
|
Matcher matcher = pattern.matcher(Strings.nullToEmpty(argsStr));
|
||||||
|
ArrayList<String> argsList = new ArrayList<>();
|
||||||
|
while (matcher.find()) {
|
||||||
|
argsList.add(matcher.group());
|
||||||
|
}
|
||||||
|
String[] args = new String[argsList.size()];
|
||||||
|
argsList.toArray(args);
|
||||||
|
ConfigurableApplicationContext context = SpringApplication.run(SpringCQApplication.class, args);
|
||||||
|
registerShutdownHook(context);
|
||||||
|
try {
|
||||||
|
synchronized (quitLock) {
|
||||||
|
quitLock.wait();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.warn("发生中断, 退出SpringCQ...", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerShutdownHook(ConfigurableApplicationContext context) {
|
||||||
|
context.addApplicationListener((ApplicationListener<ApplicationFailedEvent>)
|
||||||
|
event -> notifyThread());
|
||||||
|
context.addApplicationListener((ApplicationListener<ContextClosedEvent>)
|
||||||
|
event -> notifyThread());
|
||||||
|
context.addApplicationListener((ApplicationListener<ContextStoppedEvent>)
|
||||||
|
event -> notifyThread());
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(this::notifyThread));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyThread() {
|
||||||
|
synchronized (quitLock) {
|
||||||
|
quitLock.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,13 +6,26 @@ import net.lamgc.cgj.bot.message.MessageSource;
|
|||||||
import net.lz1998.cq.robot.CoolQ;
|
import net.lz1998.cq.robot.CoolQ;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class SpringCQMessageSenderFactory implements MessageSenderFactory {
|
public class SpringCQMessageSenderFactory implements MessageSenderFactory {
|
||||||
|
|
||||||
private final static ThreadLocal<CoolQ> threadCoolQ = new ThreadLocal<>();
|
private final static AtomicReference<CoolQ> coolQ = new AtomicReference<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置CoolQ对象.
|
||||||
|
* <p>该方法仅接受第一次设置的CoolQ对象, 其他对象将会忽略.</p>
|
||||||
|
* @param coolQObj CoolQ对象
|
||||||
|
*/
|
||||||
|
public static void setCoolQ(CoolQ coolQObj) {
|
||||||
|
if(coolQ.get() == null) {
|
||||||
|
coolQ.set(coolQObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageSender createMessageSender(MessageSource source, long id) {
|
public MessageSender createMessageSender(MessageSource source, long id) {
|
||||||
return new SpringCQMessageSender(
|
return new SpringCQMessageSender(
|
||||||
Objects.requireNonNull(threadCoolQ.get(), "CoolQ object is not included in ThreadLocal"), source, id);
|
Objects.requireNonNull(coolQ.get(), "CoolQ object not ready"), source, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import net.lamgc.cgj.bot.event.BotEventHandler;
|
|||||||
import net.lamgc.cgj.bot.framework.mirai.message.MiraiMessageEvent;
|
import net.lamgc.cgj.bot.framework.mirai.message.MiraiMessageEvent;
|
||||||
import net.lamgc.cgj.bot.framework.mirai.message.MiraiMessageSenderFactory;
|
import net.lamgc.cgj.bot.framework.mirai.message.MiraiMessageSenderFactory;
|
||||||
import net.lamgc.cgj.bot.message.MessageSenderBuilder;
|
import net.lamgc.cgj.bot.message.MessageSenderBuilder;
|
||||||
|
import net.lamgc.cgj.bot.util.GroupMuteManager;
|
||||||
import net.mamoe.mirai.Bot;
|
import net.mamoe.mirai.Bot;
|
||||||
import net.mamoe.mirai.BotFactoryJvm;
|
import net.mamoe.mirai.BotFactoryJvm;
|
||||||
import net.mamoe.mirai.event.events.BotMuteEvent;
|
import net.mamoe.mirai.event.events.BotMuteEvent;
|
||||||
@ -30,7 +31,9 @@ public class MiraiMain implements Closeable {
|
|||||||
|
|
||||||
private Bot bot;
|
private Bot bot;
|
||||||
|
|
||||||
private final static Properties botProperties = new Properties();
|
private final Properties botProperties = new Properties();
|
||||||
|
|
||||||
|
private final GroupMuteManager muteManager = new GroupMuteManager();
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(this::close));
|
Runtime.getRuntime().addShutdownHook(new Thread(this::close));
|
||||||
@ -73,9 +76,9 @@ public class MiraiMain implements Closeable {
|
|||||||
Events.subscribeAlways(FriendMessageEvent.class, this::executeMessageEvent);
|
Events.subscribeAlways(FriendMessageEvent.class, this::executeMessageEvent);
|
||||||
Events.subscribeAlways(TempMessageEvent.class, this::executeMessageEvent);
|
Events.subscribeAlways(TempMessageEvent.class, this::executeMessageEvent);
|
||||||
Events.subscribeAlways(BotMuteEvent.class,
|
Events.subscribeAlways(BotMuteEvent.class,
|
||||||
event -> BotEventHandler.setMuteState(event.getGroup().getId(), true));
|
event -> muteManager.setMuteState(event.getGroup().getId(), true));
|
||||||
Events.subscribeAlways(BotUnmuteEvent.class,
|
Events.subscribeAlways(BotUnmuteEvent.class,
|
||||||
event -> BotEventHandler.setMuteState(event.getGroup().getId(), false));
|
event -> muteManager.setMuteState(event.getGroup().getId(), false));
|
||||||
bot.login();
|
bot.login();
|
||||||
MessageSenderBuilder.setCurrentMessageSenderFactory(new MiraiMessageSenderFactory(bot));
|
MessageSenderBuilder.setCurrentMessageSenderFactory(new MiraiMessageSenderFactory(bot));
|
||||||
ApplicationBoot.initialBot();
|
ApplicationBoot.initialBot();
|
||||||
@ -90,9 +93,12 @@ public class MiraiMain implements Closeable {
|
|||||||
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;
|
||||||
if(BotEventHandler.isMute(GroupMessageEvent.getGroup().getId(), true) == null) {
|
Boolean muteState = muteManager.isMute(GroupMessageEvent.getGroup().getId(), true);
|
||||||
BotEventHandler.setMuteState(GroupMessageEvent.getGroup().getId(),
|
if(muteState == null) {
|
||||||
|
muteManager.setMuteState(GroupMessageEvent.getGroup().getId(),
|
||||||
((GroupMessageEvent) message).getGroup().getBotMuteRemaining() != 0);
|
((GroupMessageEvent) message).getGroup().getBotMuteRemaining() != 0);
|
||||||
|
} else if(muteState) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BotEventHandler.executeMessageEvent(MiraiMessageEvent.covertEventObject(message));
|
BotEventHandler.executeMessageEvent(MiraiMessageEvent.covertEventObject(message));
|
||||||
|
48
src/main/java/net/lamgc/cgj/bot/util/GroupMuteManager.java
Normal file
48
src/main/java/net/lamgc/cgj/bot/util/GroupMuteManager.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package net.lamgc.cgj.bot.util;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群禁言管理器.
|
||||||
|
* <p>该管理器用于存取群组禁言状态.</p>
|
||||||
|
*/
|
||||||
|
public class GroupMuteManager {
|
||||||
|
|
||||||
|
private final Map<Long, AtomicBoolean> muteStateMap = new Hashtable<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询某群是否被禁言.
|
||||||
|
* @param groupId 群组Id
|
||||||
|
* @param rawValue 是否返回原始值(当没有该群状态, 且本参数为true时, 将返回null)
|
||||||
|
* @return 返回状态值, 如无该群禁言记录且rawValue = true, 则返回null
|
||||||
|
*/
|
||||||
|
public Boolean isMute(long groupId, boolean rawValue) {
|
||||||
|
if(groupId <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
AtomicBoolean state = muteStateMap.get(groupId);
|
||||||
|
if(state == null && rawValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return state != null && state.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置机器人禁言状态.
|
||||||
|
* <p>设置该项可防止因机器人在禁言期间反馈请求导致被封号.</p>
|
||||||
|
* @param mute 如果被禁言, 传入true
|
||||||
|
*/
|
||||||
|
public void setMuteState(long groupId, boolean mute) {
|
||||||
|
if(groupId <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!muteStateMap.containsKey(groupId)) {
|
||||||
|
muteStateMap.put(groupId, new AtomicBoolean(mute));
|
||||||
|
} else {
|
||||||
|
muteStateMap.get(groupId).set(mute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
86
src/main/java/net/lamgc/cgj/bot/util/PixivUtils.java
Normal file
86
src/main/java/net/lamgc/cgj/bot/util/PixivUtils.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package net.lamgc.cgj.bot.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 buildSearchLinkBuilder(
|
||||||
|
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.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -402,7 +402,7 @@ public class PixivDownload {
|
|||||||
if(resultObject.get("error").getAsBoolean()) {
|
if(resultObject.get("error").getAsBoolean()) {
|
||||||
String message = resultObject.get("message").getAsString();
|
String message = resultObject.get("message").getAsString();
|
||||||
log.warn("作品页面接口请求错误, 错误信息: {}", message);
|
log.warn("作品页面接口请求错误, 错误信息: {}", message);
|
||||||
throw new HttpRequestException(response);
|
throw new HttpRequestException(response.getStatusLine(), resultObject.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray linkArray = resultObject.getAsJsonArray("body");
|
JsonArray linkArray = resultObject.getAsJsonArray("body");
|
||||||
|
@ -161,6 +161,10 @@ 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;
|
||||||
|
@ -194,6 +194,16 @@ public final class PixivURL {
|
|||||||
*/
|
*/
|
||||||
public final static String PIXIV_USER_COLLECTION_PAGE = "https://www.pixiv.net/bookmark.php?rest=show&p={pageIndex}";
|
public final static String PIXIV_USER_COLLECTION_PAGE = "https://www.pixiv.net/bookmark.php?rest=show&p={pageIndex}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索推荐接口.
|
||||||
|
* <p>可返回与搜索内容相关的标签信息, 以优化搜索效果.</p>
|
||||||
|
* 需要替换的文本:
|
||||||
|
* <ul>
|
||||||
|
* <li>{content} - 搜索内容</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
public final static String PIXIV_SEARCH_RECOMMENDS = "https://www.pixiv.net/rpc/cps.php?keywork={content}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取排名榜
|
* 获取排名榜
|
||||||
* @param mode 查询类型, 详细信息看{@link RankingMode}, 如本参数为null, 则为每天
|
* @param mode 查询类型, 详细信息看{@link RankingMode}, 如本参数为null, 则为每天
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.lamgc.cgj.pixiv;
|
package net.lamgc.cgj.pixiv;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@ -12,7 +13,6 @@ import org.apache.http.HttpResponse;
|
|||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.apache.tomcat.util.http.fileupload.util.Streams;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -127,14 +127,13 @@ public final class PixivUgoiraBuilder {
|
|||||||
HashMap<String, InputStream> frameMap = new HashMap<>(frames.size());
|
HashMap<String, InputStream> frameMap = new HashMap<>(frames.size());
|
||||||
while((entry = zipInputStream.getNextEntry()) != null) {
|
while((entry = zipInputStream.getNextEntry()) != null) {
|
||||||
log.trace("ZipEntry {} 正在接收...", entry);
|
log.trace("ZipEntry {} 正在接收...", entry);
|
||||||
Streams.copy(zipInputStream, cacheOutputStream, false);
|
ByteStreams.copy(zipInputStream, cacheOutputStream);
|
||||||
frameMap.put(entry.getName(), new ByteArrayInputStream(cacheOutputStream.toByteArray()));
|
frameMap.put(entry.getName(), new ByteArrayInputStream(cacheOutputStream.toByteArray()));
|
||||||
log.trace("ZipEntry {} 已接收完成.", entry);
|
log.trace("ZipEntry {} 已接收完成.", entry);
|
||||||
cacheOutputStream.reset();
|
cacheOutputStream.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InputStream firstFrameInput = frameMap.get(frames.get(0).getAsJsonObject().get("file").getAsString());
|
||||||
InputStream firstFrameInput = frameMap.get("000000.jpg");
|
|
||||||
BufferedImage firstFrame = ImageIO.read(firstFrameInput);
|
BufferedImage firstFrame = ImageIO.read(firstFrameInput);
|
||||||
firstFrameInput.reset();
|
firstFrameInput.reset();
|
||||||
if(width != firstFrame.getWidth() || height != firstFrame.getHeight()) {
|
if(width != firstFrame.getWidth() || height != firstFrame.getHeight()) {
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
server.port=8081
|
|
||||||
server.tomcat.max-threads=1
|
|
12
src/main/resources/application.yml
Normal file
12
src/main/resources/application.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
server:
|
||||||
|
port: 8081
|
||||||
|
|
||||||
|
spring:
|
||||||
|
cq:
|
||||||
|
plugin-list:
|
||||||
|
- net.lamgc.cgj.bot.framework.coolq.CQPluginMain
|
||||||
|
event:
|
||||||
|
corePoolSize: 8
|
||||||
|
maxPoolSize: 16
|
||||||
|
keepAliveTime: 25000
|
||||||
|
workQueueSize: 1024
|
@ -0,0 +1,30 @@
|
|||||||
|
package net.lamgc.cgj.bot.util;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class GroupMuteManagerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void muteStateTest() {
|
||||||
|
GroupMuteManager manager = new GroupMuteManager();
|
||||||
|
Assert.assertNull(manager.isMute(1, true)); // 未设置的群组返回null
|
||||||
|
Assert.assertFalse(manager.isMute(1, false)); // 未设置就返回false
|
||||||
|
manager.setMuteState(1, true); // mute == true
|
||||||
|
Assert.assertNotNull(manager.isMute(1, true)); // 第一次设置后不为null
|
||||||
|
Assert.assertTrue(manager.isMute(1, false)); // 确保条件正常
|
||||||
|
manager.setMuteState(2, true); // 不能出现不同群号的冲突
|
||||||
|
manager.setMuteState(1, false);
|
||||||
|
Assert.assertTrue(manager.isMute(2, false));
|
||||||
|
Assert.assertNotNull(manager.isMute(1, true)); // 变更为false后依然不能返回null
|
||||||
|
Assert.assertFalse(manager.isMute(1, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invalidGroupIdTest() {
|
||||||
|
GroupMuteManager manager = new GroupMuteManager();
|
||||||
|
manager.setMuteState(-1, true); // 设置应该是无效的
|
||||||
|
Assert.assertFalse(manager.isMute(-1, false)); // 由于设置无效, 返回false即可
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user