koishi-plugin-bilibili-notify 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/comRegister.js +79 -87
- package/package.json +2 -2
- package/readme.md +2 -0
package/lib/comRegister.js
CHANGED
|
@@ -7,8 +7,7 @@ const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
|
|
|
7
7
|
const koishi_1 = require("koishi");
|
|
8
8
|
// 导入qrcode
|
|
9
9
|
const qrcode_1 = __importDefault(require("qrcode"));
|
|
10
|
-
const
|
|
11
|
-
const sharp_1 = __importDefault(require("sharp"));
|
|
10
|
+
const jimp_1 = __importDefault(require("jimp"));
|
|
12
11
|
var LiveType;
|
|
13
12
|
(function (LiveType) {
|
|
14
13
|
LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
|
|
@@ -163,16 +162,9 @@ class ComRegister {
|
|
|
163
162
|
this.logger.info('调用test gimg指令')
|
|
164
163
|
// 获取主播信息
|
|
165
164
|
const { data } = await ctx.biliAPI.getMasterInfo('194484313')
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
url: data.info.face,
|
|
169
|
-
method: 'GET',
|
|
170
|
-
responseType: 'arraybuffer'
|
|
165
|
+
const resizedImage = await Jimp.read(data.info.face).then(async image => {
|
|
166
|
+
return await image.resize(100, 100).getBufferAsync(Jimp.MIME_PNG)
|
|
171
167
|
})
|
|
172
|
-
// 使用sharp调整图片大小
|
|
173
|
-
const resizedImage = await sharp(resp.data)
|
|
174
|
-
.resize(100, 100)
|
|
175
|
-
.toBuffer()
|
|
176
168
|
// 发送下播提示语
|
|
177
169
|
await session.send(
|
|
178
170
|
<>{h.image(resizedImage, 'image/png')} 主播{data.info.uname}已下播</>
|
|
@@ -732,6 +724,8 @@ class ComRegister {
|
|
|
732
724
|
this.logger.info('重启插件成功');
|
|
733
725
|
}
|
|
734
726
|
else {
|
|
727
|
+
// logger
|
|
728
|
+
this.logger.error('已重启插件三次,请检查机器人状态后手动重启');
|
|
735
729
|
// 重启失败,发送消息
|
|
736
730
|
await this.sendPrivateMsg(bot, '已重启插件三次,请检查机器人状态后手动重启');
|
|
737
731
|
// 关闭插件
|
|
@@ -766,7 +760,8 @@ class ComRegister {
|
|
|
766
760
|
}
|
|
767
761
|
catch (e) {
|
|
768
762
|
if (i === attempts - 1) { // 已尝试三次
|
|
769
|
-
|
|
763
|
+
this.logger.error(`发送群组ID:${guildId}消息失败!原因: ` + e.toString());
|
|
764
|
+
this.sendPrivateMsg(bot, `发送群组ID:${guildId}消息失败,请检查机器人状态`);
|
|
770
765
|
}
|
|
771
766
|
}
|
|
772
767
|
}
|
|
@@ -817,58 +812,54 @@ class ComRegister {
|
|
|
817
812
|
continue;
|
|
818
813
|
// 寻找发布时间比时间点更晚的动态
|
|
819
814
|
if (items[num].modules.module_author.pub_ts > timePoint) {
|
|
815
|
+
// 定义变量
|
|
816
|
+
let pic;
|
|
817
|
+
let buffer;
|
|
818
|
+
// 从动态数据中取出UP主名称和动态ID
|
|
819
|
+
const upName = content.data.items[num].modules.module_author.name;
|
|
820
|
+
const dynamicId = content.data.items[num].id_str;
|
|
820
821
|
// 推送该条动态
|
|
821
822
|
let attempts = 3;
|
|
822
823
|
for (let i = 0; i < attempts; i++) {
|
|
824
|
+
// 获取动态推送图片
|
|
823
825
|
try {
|
|
824
|
-
//
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
const upName = content.data.items[num].modules.module_author.name;
|
|
829
|
-
const dynamicId = content.data.items[num].id_str;
|
|
830
|
-
// 判断是否需要发送URL
|
|
831
|
-
const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
|
|
832
|
-
// 获取动态推送图片
|
|
833
|
-
try {
|
|
834
|
-
// 渲染图片
|
|
835
|
-
const { pic: gimgPic, buffer: gimgBuffer } = await ctx.gimg.generateDynamicImg(items[num]);
|
|
836
|
-
pic = gimgPic;
|
|
837
|
-
buffer = gimgBuffer;
|
|
838
|
-
}
|
|
839
|
-
catch (e) {
|
|
840
|
-
// 直播开播动态,不做处理
|
|
841
|
-
if (e.message === '直播开播动态,不做处理')
|
|
842
|
-
break;
|
|
843
|
-
if (e.message === '出现关键词,屏蔽该动态') {
|
|
844
|
-
// 如果需要发送才发送
|
|
845
|
-
this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
846
|
-
break;
|
|
847
|
-
}
|
|
848
|
-
if (e.message === '已屏蔽转发动态') {
|
|
849
|
-
this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
|
|
850
|
-
break;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
// 如果pic存在,则直接返回pic
|
|
854
|
-
if (pic) {
|
|
855
|
-
// pic存在,使用的是render模式
|
|
856
|
-
await this.sendMsg(ctx, guildId, bot, pic + dUrl);
|
|
857
|
-
}
|
|
858
|
-
else {
|
|
859
|
-
// pic不存在,说明使用的是page模式
|
|
860
|
-
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
|
|
861
|
-
}
|
|
862
|
-
// 如果成功,那么跳出循环
|
|
863
|
-
break;
|
|
826
|
+
// 渲染图片
|
|
827
|
+
const { pic: gimgPic, buffer: gimgBuffer } = await ctx.gimg.generateDynamicImg(items[num]);
|
|
828
|
+
pic = gimgPic;
|
|
829
|
+
buffer = gimgBuffer;
|
|
864
830
|
}
|
|
865
831
|
catch (e) {
|
|
866
|
-
|
|
867
|
-
if (
|
|
832
|
+
// 直播开播动态,不做处理
|
|
833
|
+
if (e.message === '直播开播动态,不做处理')
|
|
834
|
+
break;
|
|
835
|
+
if (e.message === '出现关键词,屏蔽该动态') {
|
|
836
|
+
// 如果需要发送才发送
|
|
837
|
+
this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
if (e.message === '已屏蔽转发动态') {
|
|
841
|
+
this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
// 未知错误
|
|
845
|
+
if (i === attempts - 1) {
|
|
846
|
+
this.logger.error('dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:' + e.toString());
|
|
847
|
+
// 发送私聊消息并重启服务
|
|
868
848
|
return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
|
|
869
849
|
}
|
|
870
850
|
}
|
|
871
851
|
}
|
|
852
|
+
// 判断是否需要发送URL
|
|
853
|
+
const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
|
|
854
|
+
// 如果pic存在,则直接返回pic
|
|
855
|
+
if (pic) {
|
|
856
|
+
// pic存在,使用的是render模式
|
|
857
|
+
await this.sendMsg(ctx, guildId, bot, pic + dUrl);
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
// pic不存在,说明使用的是page模式
|
|
861
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
|
|
862
|
+
}
|
|
872
863
|
// 更新时间点为最新发布动态的发布时间
|
|
873
864
|
switch (num) {
|
|
874
865
|
case 1: {
|
|
@@ -892,43 +883,50 @@ class ComRegister {
|
|
|
892
883
|
// 相当于锁的作用,防止上一个循环没处理完
|
|
893
884
|
let flag = true;
|
|
894
885
|
const sendLiveNotifyCard = async (data, uData, liveType, liveStartMsg, atAll) => {
|
|
886
|
+
// 定义变量
|
|
887
|
+
let pic;
|
|
888
|
+
let buffer;
|
|
889
|
+
// 多次尝试生成图片
|
|
895
890
|
let attempts = 3;
|
|
896
891
|
for (let i = 0; i < attempts; i++) {
|
|
897
892
|
try {
|
|
898
893
|
// 获取直播通知卡片
|
|
899
|
-
const { pic, buffer } = await ctx.gimg.generateLiveImg(data, uData, liveType);
|
|
900
|
-
//
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
if (pic)
|
|
904
|
-
return await this.sendMsg(ctx, guildId, bot, pic);
|
|
905
|
-
// pic不存在,说明使用的是page模式
|
|
906
|
-
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png'));
|
|
907
|
-
}
|
|
908
|
-
else if (liveStartMsg && atAll) {
|
|
909
|
-
// pic 存在,使用的是render模式
|
|
910
|
-
if (pic)
|
|
911
|
-
return await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
|
|
912
|
-
// pic不存在,说明使用的是page模式
|
|
913
|
-
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
|
|
914
|
-
}
|
|
915
|
-
else {
|
|
916
|
-
// pic 存在,使用的是render模式
|
|
917
|
-
if (pic)
|
|
918
|
-
return await this.sendMsg(ctx, guildId, bot, pic + liveStartMsg);
|
|
919
|
-
// pic不存在,说明使用的是page模式
|
|
920
|
-
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
|
|
921
|
-
}
|
|
894
|
+
const { pic: picv, buffer: bufferv } = await ctx.gimg.generateLiveImg(data, uData, liveType);
|
|
895
|
+
// 赋值
|
|
896
|
+
pic = picv;
|
|
897
|
+
buffer = bufferv;
|
|
922
898
|
// 成功则跳出循环
|
|
923
899
|
break;
|
|
924
900
|
}
|
|
925
901
|
catch (e) {
|
|
926
|
-
this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
|
|
927
902
|
if (i === attempts - 1) { // 已尝试三次
|
|
903
|
+
this.logger.error('liveDetect generateLiveImg() 推送卡片生成失败,原因:' + e.toString());
|
|
928
904
|
return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
|
|
929
905
|
}
|
|
930
906
|
}
|
|
931
907
|
}
|
|
908
|
+
// 推送直播信息
|
|
909
|
+
if (!liveStartMsg) {
|
|
910
|
+
// pic 存在,使用的是render模式
|
|
911
|
+
if (pic)
|
|
912
|
+
return await this.sendMsg(ctx, guildId, bot, pic);
|
|
913
|
+
// pic不存在,说明使用的是page模式
|
|
914
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png'));
|
|
915
|
+
}
|
|
916
|
+
else if (liveStartMsg && atAll) {
|
|
917
|
+
// pic 存在,使用的是render模式
|
|
918
|
+
if (pic)
|
|
919
|
+
return await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
|
|
920
|
+
// pic不存在,说明使用的是page模式
|
|
921
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
// pic 存在,使用的是render模式
|
|
925
|
+
if (pic)
|
|
926
|
+
return await this.sendMsg(ctx, guildId, bot, pic + liveStartMsg);
|
|
927
|
+
// pic不存在,说明使用的是page模式
|
|
928
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
|
|
929
|
+
}
|
|
932
930
|
};
|
|
933
931
|
return async () => {
|
|
934
932
|
try {
|
|
@@ -1001,16 +999,10 @@ class ComRegister {
|
|
|
1001
999
|
let liveEndMsg = this.config.customLiveEnd
|
|
1002
1000
|
.replace('-name', uData.info.uname)
|
|
1003
1001
|
.replace('-time', await ctx.gimg.getTimeDifference(liveTime));
|
|
1004
|
-
//
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1007
|
-
method: 'GET',
|
|
1008
|
-
responseType: 'arraybuffer'
|
|
1002
|
+
// 获取头像并缩放
|
|
1003
|
+
const resizedImage = await jimp_1.default.read(uData.info.face).then(async (image) => {
|
|
1004
|
+
return await image.resize(100, 100).getBufferAsync(jimp_1.default.MIME_PNG);
|
|
1009
1005
|
});
|
|
1010
|
-
// 使用sharp调整图片大小
|
|
1011
|
-
const resizedImage = await (0, sharp_1.default)(resp.data)
|
|
1012
|
-
.resize(100, 100)
|
|
1013
|
-
.toBuffer();
|
|
1014
1006
|
// 发送下播通知
|
|
1015
1007
|
await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(resizedImage, 'image/png'), " ", liveEndMsg] }));
|
|
1016
1008
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-bilibili-notify",
|
|
3
3
|
"description": "Koishi bilibili notify plugin",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.5",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Akokko <admin@akokko.com>"
|
|
7
7
|
],
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"axios": "^1.6.7",
|
|
31
31
|
"axios-cookiejar-support": "^5.0.0",
|
|
32
|
+
"jimp": "^0.22.12",
|
|
32
33
|
"jsdom": "^24.0.0",
|
|
33
34
|
"luxon": "^3.4.4",
|
|
34
35
|
"md5": "^2.3.0",
|
|
35
36
|
"qrcode": "^1.5.3",
|
|
36
|
-
"sharp": "^0.33.3",
|
|
37
37
|
"tough-cookie": "^4.1.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
package/readme.md
CHANGED
|
@@ -137,6 +137,8 @@
|
|
|
137
137
|
- ver 1.2.3-rc.10 修复不能移除边框的bug,对图片布局进行了调整,新增下播消息发送主播头像
|
|
138
138
|
- ver 1.2.3-rc.11 测试版本,请跳过
|
|
139
139
|
- ver 1.2.3 完善主播下播消息发送头像功能,优化控制台订阅信息显示
|
|
140
|
+
- ver 1.2.4 优化了下播消息发送头像图片的质量和插件重启提示
|
|
141
|
+
- ver 1.2.5 修复了在多群订阅的情况下,其中一个群推送失败会导致其余的群全部重新推送的bug。更换图片处理依赖以解决在插件市场中被标记为不安全插件的问题
|
|
140
142
|
|
|
141
143
|
## 交流群
|
|
142
144
|
|