koishi-plugin-bilibili-notify 1.2.2-beta.0 → 1.2.2-beta.2
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/biliAPI.js +1 -1
- package/lib/comRegister.js +39 -36
- package/lib/index.js +2 -2
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/biliAPI.js
CHANGED
package/lib/comRegister.js
CHANGED
|
@@ -151,11 +151,17 @@ class ComRegister {
|
|
|
151
151
|
})
|
|
152
152
|
|
|
153
153
|
testCom
|
|
154
|
-
.subcommand('.
|
|
155
|
-
.usage('
|
|
156
|
-
.example('test
|
|
154
|
+
.subcommand('.livestop', '发送下播提示语测试')
|
|
155
|
+
.usage('发送下播提示语测试')
|
|
156
|
+
.example('test livestop')
|
|
157
157
|
.action(async ({ session }) => {
|
|
158
|
-
ctx.biliAPI.
|
|
158
|
+
const { data } = await ctx.biliAPI.getMasterInfo('194484313')
|
|
159
|
+
console.log(data);
|
|
160
|
+
await session.send(
|
|
161
|
+
<>
|
|
162
|
+
<img width="10px" height="10px" src="https://koishi.chat/logo.png"/>
|
|
163
|
+
</>
|
|
164
|
+
)
|
|
159
165
|
}) */
|
|
160
166
|
const biliCom = ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] });
|
|
161
167
|
biliCom.subcommand('.login', '登录B站之后才可以进行之后的操作')
|
|
@@ -725,11 +731,11 @@ class ComRegister {
|
|
|
725
731
|
// 如果pic存在,则直接返回pic
|
|
726
732
|
if (pic) {
|
|
727
733
|
// pic存在,使用的是render模式
|
|
728
|
-
await this.sendMsg(guildId, bot, pic +
|
|
734
|
+
await this.sendMsg(guildId, bot, pic + dUrl);
|
|
729
735
|
}
|
|
730
736
|
else {
|
|
731
737
|
// pic不存在,说明使用的是page模式
|
|
732
|
-
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' +
|
|
738
|
+
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
|
|
733
739
|
}
|
|
734
740
|
// 如果成功,那么跳出循环
|
|
735
741
|
break;
|
|
@@ -769,18 +775,34 @@ class ComRegister {
|
|
|
769
775
|
let uData;
|
|
770
776
|
// 相当于锁的作用,防止上一个循环没处理完
|
|
771
777
|
let flag = true;
|
|
772
|
-
const sendLiveNotifyCard = async (data, uData, liveType) => {
|
|
778
|
+
const sendLiveNotifyCard = async (data, uData, liveType, liveStartMsg, atAll) => {
|
|
773
779
|
let attempts = 3;
|
|
774
780
|
for (let i = 0; i < attempts; i++) {
|
|
775
781
|
try {
|
|
776
782
|
// 获取直播通知卡片
|
|
777
783
|
const { pic, buffer } = await ctx.gimg.generateLiveImg(data, uData, liveType);
|
|
778
784
|
// 推送直播信息
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
785
|
+
if (!liveStartMsg) {
|
|
786
|
+
// pic 存在,使用的是render模式
|
|
787
|
+
if (pic)
|
|
788
|
+
return await this.sendMsg(guildId, bot, pic);
|
|
789
|
+
// pic不存在,说明使用的是page模式
|
|
790
|
+
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png'));
|
|
791
|
+
}
|
|
792
|
+
else if (liveStartMsg && atAll) {
|
|
793
|
+
// pic 存在,使用的是render模式
|
|
794
|
+
if (pic)
|
|
795
|
+
return await this.sendMsg(guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
|
|
796
|
+
// pic不存在,说明使用的是page模式
|
|
797
|
+
await this.sendMsg(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] })));
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
// pic 存在,使用的是render模式
|
|
801
|
+
if (pic)
|
|
802
|
+
return await this.sendMsg(guildId, bot, pic + liveStartMsg);
|
|
803
|
+
// pic不存在,说明使用的是page模式
|
|
804
|
+
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
|
|
805
|
+
}
|
|
784
806
|
// 成功则跳出循环
|
|
785
807
|
break;
|
|
786
808
|
}
|
|
@@ -898,16 +920,16 @@ class ComRegister {
|
|
|
898
920
|
// 定义开播通知语
|
|
899
921
|
let liveStartMsg = this.config.customLiveStart
|
|
900
922
|
.replace('-name', uData.info.uname)
|
|
901
|
-
.replace('-time', await ctx.gimg.getTimeDifference(liveTime))
|
|
902
|
-
|
|
903
|
-
await sendLiveNotifyCard(data, uData, LiveType.StartBroadcasting);
|
|
923
|
+
.replace('-time', await ctx.gimg.getTimeDifference(liveTime))
|
|
924
|
+
.replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`);
|
|
904
925
|
// 判断是否需要@全体成员
|
|
905
926
|
if (this.config.liveStartAtAll) {
|
|
906
927
|
// 发送@全体成员通知
|
|
907
|
-
await
|
|
928
|
+
await sendLiveNotifyCard(data, uData, LiveType.StartBroadcasting, liveStartMsg, true);
|
|
908
929
|
}
|
|
909
930
|
else {
|
|
910
|
-
|
|
931
|
+
// 发送直播通知卡片
|
|
932
|
+
await sendLiveNotifyCard(data, uData, LiveType.StartBroadcasting, liveStartMsg);
|
|
911
933
|
}
|
|
912
934
|
}
|
|
913
935
|
else { // 还在直播
|
|
@@ -1009,7 +1031,6 @@ class ComRegister {
|
|
|
1009
1031
|
});
|
|
1010
1032
|
}
|
|
1011
1033
|
async getSubFromDatabase(ctx) {
|
|
1012
|
-
this.logger.info('开始执行数据库读取操作');
|
|
1013
1034
|
// 判断登录信息是否已加载完毕
|
|
1014
1035
|
await this.checkIfLoginInfoIsLoaded(ctx);
|
|
1015
1036
|
// 如果未登录,则直接返回
|
|
@@ -1018,15 +1039,11 @@ class ComRegister {
|
|
|
1018
1039
|
this.logger.info(`账号未登录,请登录`);
|
|
1019
1040
|
return;
|
|
1020
1041
|
}
|
|
1021
|
-
this.logger.info('已登录账号');
|
|
1022
1042
|
// 已存在订阅管理对象,不再进行订阅操作
|
|
1023
1043
|
if (this.subManager.length !== 0)
|
|
1024
1044
|
return;
|
|
1025
|
-
this.logger.info('不存在订阅管理对象');
|
|
1026
1045
|
// 从数据库中获取数据
|
|
1027
1046
|
const subData = await ctx.database.get('bilibili', { id: { $gt: 0 } });
|
|
1028
|
-
this.logger.info('已从数据库获取到数据,数据为:');
|
|
1029
|
-
this.logger.info(subData);
|
|
1030
1047
|
// 设定订阅数量
|
|
1031
1048
|
this.num = subData.length;
|
|
1032
1049
|
// 如果订阅数量超过三个则数据库被非法修改
|
|
@@ -1093,8 +1110,6 @@ class ComRegister {
|
|
|
1093
1110
|
try {
|
|
1094
1111
|
// 获取用户信息
|
|
1095
1112
|
content = await ctx.biliAPI.getUserInfo(sub.uid);
|
|
1096
|
-
// log
|
|
1097
|
-
this.logger.info(`UID:${sub.uid} 获取到用户信息`);
|
|
1098
1113
|
// 成功则跳出循环
|
|
1099
1114
|
break;
|
|
1100
1115
|
}
|
|
@@ -1140,8 +1155,6 @@ class ComRegister {
|
|
|
1140
1155
|
this.logger.info(`UID:${sub.uid} 房间号被篡改,自动取消订阅`);
|
|
1141
1156
|
return;
|
|
1142
1157
|
}
|
|
1143
|
-
// log
|
|
1144
|
-
this.logger.info(`UID:${sub.uid} 开始构建订阅对象`);
|
|
1145
1158
|
// 构建订阅对象
|
|
1146
1159
|
let subManagerItem = {
|
|
1147
1160
|
id: sub.id,
|
|
@@ -1154,34 +1167,24 @@ class ComRegister {
|
|
|
1154
1167
|
liveDispose: null,
|
|
1155
1168
|
dynamicDispose: null
|
|
1156
1169
|
};
|
|
1157
|
-
// log
|
|
1158
|
-
this.logger.info(`UID:${sub.uid} 订阅对象构建成功,开始进行订阅操作`);
|
|
1159
1170
|
// 判断需要订阅的服务
|
|
1160
1171
|
if (sub.dynamic) { // 需要订阅动态
|
|
1161
1172
|
// 开始循环检测
|
|
1162
1173
|
const dispose = ctx.setInterval(this.dynamicDetect(ctx, bot, sub.uid, targetArr), this.config.dynamicLoopTime * 1000);
|
|
1163
1174
|
// 保存销毁函数
|
|
1164
1175
|
subManagerItem.dynamicDispose = dispose;
|
|
1165
|
-
// log
|
|
1166
|
-
this.logger.info(`UID:${sub.uid} 成功订阅动态`);
|
|
1167
1176
|
}
|
|
1168
1177
|
if (sub.live) { // 需要订阅直播
|
|
1169
1178
|
// 开始循环检测
|
|
1170
1179
|
const dispose = ctx.setInterval(this.liveDetect(ctx, bot, sub.room_id, targetArr), this.config.liveLoopTime * 1000);
|
|
1171
1180
|
// 保存销毁函数
|
|
1172
1181
|
subManagerItem.liveDispose = dispose;
|
|
1173
|
-
// log
|
|
1174
|
-
this.logger.info(`UID:${sub.uid} 成功订阅直播`);
|
|
1175
1182
|
}
|
|
1176
1183
|
// 保存新订阅对象
|
|
1177
1184
|
this.subManager.push(subManagerItem);
|
|
1178
|
-
// log
|
|
1179
|
-
this.logger.info(`UID:${sub.uid} 成功保存订阅对象`);
|
|
1180
1185
|
}
|
|
1181
1186
|
// 在控制台中显示订阅对象
|
|
1182
1187
|
this.updateSubNotifier(ctx);
|
|
1183
|
-
// log
|
|
1184
|
-
this.logger.info(`数据库读取操作已完成`);
|
|
1185
1188
|
}
|
|
1186
1189
|
unsubSingle(ctx, id /* UID或RoomId */, type /* 0取消Live订阅,1取消Dynamic订阅 */) {
|
|
1187
1190
|
let index;
|
package/lib/index.js
CHANGED
|
@@ -80,8 +80,8 @@ exports.Config = koishi_1.Schema.object({
|
|
|
80
80
|
.default(1)
|
|
81
81
|
.description('设定隔多长时间推送一次直播状态,单位为小时,默认为一小时'),
|
|
82
82
|
customLiveStart: koishi_1.Schema.string()
|
|
83
|
-
.default('-name开播啦')
|
|
84
|
-
.description('自定义开播提示语,-name代表UP
|
|
83
|
+
.default('-name开播啦 -link')
|
|
84
|
+
.description('自定义开播提示语,-name代表UP昵称,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用)。例如-name开播啦,会发送为xxxUP开播啦'),
|
|
85
85
|
customLiveEnd: koishi_1.Schema.string()
|
|
86
86
|
.default('-name下播啦,本次直播了-time')
|
|
87
87
|
.description('自定义下播提示语,-name代表UP昵称,-time代表开播时长。例如-name下播啦,本次直播了-time,会发送为xxxUP下播啦,直播时长为xx小时xx分钟xx秒'),
|
package/package.json
CHANGED