Skip to content

Commit

Permalink
optimize: add config mergeTextPic
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Dec 16, 2024
1 parent 45f2467 commit 7480577
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
3 changes: 3 additions & 0 deletions defaultConfig/bilibili/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ banWords:
# 设置B站动态消息模式 0 文字模式 1 图片模式
pushMsgMode: 1

# 文字模式时,文字消息与图片附件是否合并在一起发送,默认 1 合并,0 不合并。如果合并时图片过多导致发送失败,可设置为 0 单独发送图片。
mergeTextPic: 1

# 是否启用九宫格样式:默认 1 启用,0 不启用。此为最高优先级,九宫格为动态模式,特定大小/长宽比的图片资源将会动态启用九宫格/四宫格/无宫格样式。
boxGrid: 1

Expand Down
5 changes: 4 additions & 1 deletion defaultConfig/weibo/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ banWords:
# 设置微博动态消息模式 0 文字模式 1 图片模式
pushMsgMode: 1

# 文字模式时,文字消息与图片附件是否合并在一起发送,默认 1 合并,0 不合并。如果合并时图片过多导致发送失败,可设置为 0 单独发送图片。
mergeTextPic: 1

# 是否启用九宫格样式:默认 1 启用,0 不启用。此为最高优先级,九宫格为动态模式,特定大小/长宽比的图片资源将会动态启用九宫格/四宫格/无宫格样式。
boxGrid: 1

# 微博动态卡片分片截图模式:默认 1 启用 0 不启用。启用,将会推送每条动态的全部内容;不启用,动态内容过长时候将只推送7500px长度的动态卡片,需关闭宫格模式。
# 微博动态卡片分片截图模式:默认 1 启用 0 不启用。启用,将会推送每条动态的全部内容;不启用,动态内容过长时候将只推送noSplitHeight长度的动态卡片,需关闭宫格模式。
isSplit: 1

# 动态卡片非分片模式下的截图高度,默认7500px(仅填数字,无需填入单位),请勿设置过大或过小。关闭分片截图时生效。
Expand Down
30 changes: 22 additions & 8 deletions models/bilibili/bilibili.main.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,15 @@ export class BiliTask {
}
}

/*发送动态*/
/**
* 发送动态消息
* @param chatId 聊天 ID
* @param bot_id 机器人 ID
* @param upName 用户名
* @param pushDynamicData 推送动态数据
* @param biliConfigData 哔哩配置数据
* @param chatType 聊天类型
*/
async sendDynamic(chatId: string | number, bot_id: string | number, upName: string, pushDynamicData: any, biliConfigData: any, chatType: string) {
const id_str = pushDynamicData.id_str;

Expand Down Expand Up @@ -261,15 +269,21 @@ export class BiliTask {
}
}

await this.sendMessage(chatId, bot_id, chatType, dynamicMsg.msg);
const pics = dynamicMsg.pics;
if (pics && pics.length > 0) {
for (let i = 0; i < pics.length; i++) {
await this.sendMessage(chatId, bot_id, chatType, pics[i]);
await this.randomDelay(1000, 2000); // 随机延时1-2秒
let mergeTextPic: boolean = !!biliConfigData.mergeTextPic === false ? false : true; // 是否合并文本和图片,默认为 true
if (mergeTextPic) {
const mergeMsg = [...dynamicMsg.msg, ...dynamicMsg.pics];
await this.sendMessage(chatId, bot_id, chatType, mergeMsg);
} else {
await this.sendMessage(chatId, bot_id, chatType, dynamicMsg.msg);
const pics = dynamicMsg.pics;
if (pics && pics.length > 0) {
for (let i = 0; i < pics.length; i++) {
await this.sendMessage(chatId, bot_id, chatType, pics[i]);
await this.randomDelay(1000, 2000); // 随机延时1-2秒
}
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
}

Expand Down
20 changes: 13 additions & 7 deletions models/weibo/weibo.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,21 @@ export class WeiboTask {
}
}

await this.sendMessage(chatId, bot_id, chatType, dynamicMsg.msg);
const pics = dynamicMsg.pics;
if (pics && pics.length > 0) {
for (let i = 0; i < pics.length; i++) {
await this.sendMessage(chatId, bot_id, chatType, pics[i]);
await this.randomDelay(1000, 2000); // 随机延时1-2秒
let mergeTextPic = !!weiboConfigData.mergeTextPic === false ? false : true; // 是否合并文字和图片,默认为 true
if (mergeTextPic) {
const mergeMsg = [...dynamicMsg.msg, ...dynamicMsg.pics];
await this.sendMessage(chatId, bot_id, chatType, mergeMsg);
} else {
await this.sendMessage(chatId, bot_id, chatType, dynamicMsg.msg);
const pics = dynamicMsg.pics;
if (pics && pics.length > 0) {
for (let i = 0; i < pics.length; i++) {
await this.sendMessage(chatId, bot_id, chatType, pics[i]);
await this.randomDelay(1000, 2000); // 随机延时1-2秒
}
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yuki-plugin",
"version": "2.0.6-0",
"version": "2.0.6-1",
"author": "snowtafir",
"description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件",
"main": "./index",
Expand Down

0 comments on commit 7480577

Please sign in to comment.