koishi-plugin-bilibili-notify 3.2.9-rc.4 → 3.2.10-alpha.1

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/index.js CHANGED
@@ -862,7 +862,7 @@ var ComRegister = class {
862
862
  bili_cookies: encryptedCookies,
863
863
  bili_refresh_token: encryptedRefreshToken
864
864
  }]);
865
- this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
865
+ this.loginDBData = (await this.ctx.database.get("loginBili", 1))[0];
866
866
  await this.ctx.ba.loadCookiesFromDatabase();
867
867
  await this.checkIfLoginInfoIsLoaded();
868
868
  this.loginTimer();
@@ -1038,6 +1038,34 @@ var ComRegister = class {
1038
1038
  const danmakerRankMsg = this.config.liveSummary.replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
1039
1039
  await session.send(danmakerRankMsg);
1040
1040
  });
1041
+ biliCom.subcommand(".cap").action(async ({ session }) => {
1042
+ const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
1043
+ const data$2 = await this.ctx.ba.getUserInfo("114514");
1044
+ return {
1045
+ code: 0,
1046
+ data: data$2
1047
+ };
1048
+ }).then((content) => content.data);
1049
+ if (userInfoCode !== -352 || !userInfoData.v_voucher) return "不满足验证条件,不需要执行该命令,如果提示风控可以尝试重启插件";
1050
+ const { data: data$1 } = await ctx.ba.v_voucherCaptcha(userInfoData.v_voucher);
1051
+ if (!data$1.geetest) return "当前风控无法通过该验证解除,或许考虑人工申诉?";
1052
+ await session.send("请到该网站进行验证操作:https://kuresaru.github.io/geetest-validator/");
1053
+ await session.send("请手动填入 gt 和 challenge 后点击生成进行验证,验证完成后点击结果,根据提示输入对应validate");
1054
+ await session.send(`gt:${data$1.geetest.gt}`);
1055
+ await session.send(`challenge:${data$1.geetest.challenge}`);
1056
+ await session.send("请输入validate");
1057
+ const validate$1 = await session.prompt();
1058
+ const seccode = `${validate$1}|jordan`;
1059
+ const { data: validateCaptchaData } = await ctx.ba.validateCaptcha(data$1.geetest.challenge, data$1.token, validate$1, seccode);
1060
+ if (validateCaptchaData.is_valid !== 1) return "验证不成功!";
1061
+ ctx.ba.addCookie(`x-bili-gaia-vtoken=${validateCaptchaData.grisk_id}`);
1062
+ const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
1063
+ await ctx.database.upsert("loginBili", [{
1064
+ id: 1,
1065
+ bili_cookies: encryptedCookies
1066
+ }]);
1067
+ return "验证成功!请重启插件";
1068
+ });
1041
1069
  }
1042
1070
  async init(config) {
1043
1071
  this.logger = this.ctx.logger("cr");
@@ -1918,7 +1946,7 @@ var ComRegister = class {
1918
1946
  this.preInitConfig(subs);
1919
1947
  for (const sub of subs) {
1920
1948
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1921
- const { code: userInfoCode, msg: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1949
+ const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1922
1950
  const data$1 = await this.ctx.ba.getUserInfo(sub.uid);
1923
1951
  return {
1924
1952
  code: 0,
@@ -1931,6 +1959,14 @@ var ComRegister = class {
1931
1959
  message: `加载订阅UID:${sub.uid}失败!`
1932
1960
  };
1933
1961
  });
1962
+ if (userInfoCode === -352 && userInfoData.v_voucher) {
1963
+ this.logger.info("账号被风控,请使用指令 bili captcha 进行风控验证");
1964
+ await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1965
+ return {
1966
+ code: userInfoCode,
1967
+ msg: userInfoMsg
1968
+ };
1969
+ }
1934
1970
  if (userInfoCode !== 0) return {
1935
1971
  code: userInfoCode,
1936
1972
  msg: userInfoMsg
@@ -94943,7 +94979,7 @@ var BiliAPI = class extends koishi.Service {
94943
94979
  const csrf = this.getCSRF();
94944
94980
  const ticket = await this.getBiliTicket(csrf);
94945
94981
  if (ticket.code !== 0) throw new Error(`获取BiliTicket失败: ${ticket.message}`);
94946
- this.jar.setCookieSync(`bili_ticket=${ticket.data.ticket}; path=/; domain=.bilibili.com`, "https://www.bilibili.com");
94982
+ this.addCookie(`bili_ticket=${ticket.data.ticket}`);
94947
94983
  this.wbiSign.img_key = ticket.data.nav.img.slice(ticket.data.nav.img.lastIndexOf("/") + 1, ticket.data.nav.img.lastIndexOf("."));
94948
94984
  this.wbiSign.sub_key = ticket.data.nav.sub.slice(ticket.data.nav.sub.lastIndexOf("/") + 1, ticket.data.nav.sub.lastIndexOf("."));
94949
94985
  } catch (e$1) {
@@ -95158,6 +95194,9 @@ var BiliAPI = class extends koishi.Service {
95158
95194
  }
95159
95195
  }));
95160
95196
  }
95197
+ addCookie(cookieStr) {
95198
+ this.jar.setCookieSync(`${cookieStr}; path=/; domain=.bilibili.com`, "https://www.bilibili.com");
95199
+ }
95161
95200
  getCookies() {
95162
95201
  try {
95163
95202
  const cookies = this.jar.serializeSync().cookies.map((cookie) => {
@@ -95361,6 +95400,32 @@ var BiliAPI = class extends koishi.Service {
95361
95400
  case -400: throw new Error("请求错误");
95362
95401
  }
95363
95402
  }
95403
+ async v_voucherCaptcha(v_voucher) {
95404
+ const csrf = this.getCSRF();
95405
+ const { data: data$1 } = await this.client.post("https://api.bilibili.com/x/gaia-vgate/v1/register", {
95406
+ csrf,
95407
+ v_voucher
95408
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } }).catch((e$1) => {
95409
+ this.logger.error(e$1);
95410
+ });
95411
+ if (data$1.code !== 0) this.logger.error("验证码获取失败!");
95412
+ return { data: data$1.data };
95413
+ }
95414
+ async validateCaptcha(challenge, token, validate$1, seccode) {
95415
+ const csrf = this.getCSRF();
95416
+ const { data: data$1 } = await this.client.post("https://api.bilibili.com/x/gaia-vgate/v1/validate", {
95417
+ csrf,
95418
+ challenge,
95419
+ token,
95420
+ validate: validate$1,
95421
+ seccode
95422
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
95423
+ if (data$1.code !== 0) {
95424
+ this.logger.info(`验证失败:错误码=${data$1.code},错误消息:${data$1.message}`);
95425
+ return { data: null };
95426
+ }
95427
+ return { data: data$1.data };
95428
+ }
95364
95429
  };
95365
95430
  (0, import_decorate.default)([Retry({
95366
95431
  attempts: 3,
package/lib/index.mjs CHANGED
@@ -864,7 +864,7 @@ var ComRegister = class {
864
864
  bili_cookies: encryptedCookies,
865
865
  bili_refresh_token: encryptedRefreshToken
866
866
  }]);
867
- this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
867
+ this.loginDBData = (await this.ctx.database.get("loginBili", 1))[0];
868
868
  await this.ctx.ba.loadCookiesFromDatabase();
869
869
  await this.checkIfLoginInfoIsLoaded();
870
870
  this.loginTimer();
@@ -1040,6 +1040,34 @@ var ComRegister = class {
1040
1040
  const danmakerRankMsg = this.config.liveSummary.replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
1041
1041
  await session.send(danmakerRankMsg);
1042
1042
  });
1043
+ biliCom.subcommand(".cap").action(async ({ session }) => {
1044
+ const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
1045
+ const data$2 = await this.ctx.ba.getUserInfo("114514");
1046
+ return {
1047
+ code: 0,
1048
+ data: data$2
1049
+ };
1050
+ }).then((content) => content.data);
1051
+ if (userInfoCode !== -352 || !userInfoData.v_voucher) return "不满足验证条件,不需要执行该命令,如果提示风控可以尝试重启插件";
1052
+ const { data: data$1 } = await ctx.ba.v_voucherCaptcha(userInfoData.v_voucher);
1053
+ if (!data$1.geetest) return "当前风控无法通过该验证解除,或许考虑人工申诉?";
1054
+ await session.send("请到该网站进行验证操作:https://kuresaru.github.io/geetest-validator/");
1055
+ await session.send("请手动填入 gt 和 challenge 后点击生成进行验证,验证完成后点击结果,根据提示输入对应validate");
1056
+ await session.send(`gt:${data$1.geetest.gt}`);
1057
+ await session.send(`challenge:${data$1.geetest.challenge}`);
1058
+ await session.send("请输入validate");
1059
+ const validate$1 = await session.prompt();
1060
+ const seccode = `${validate$1}|jordan`;
1061
+ const { data: validateCaptchaData } = await ctx.ba.validateCaptcha(data$1.geetest.challenge, data$1.token, validate$1, seccode);
1062
+ if (validateCaptchaData.is_valid !== 1) return "验证不成功!";
1063
+ ctx.ba.addCookie(`x-bili-gaia-vtoken=${validateCaptchaData.grisk_id}`);
1064
+ const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
1065
+ await ctx.database.upsert("loginBili", [{
1066
+ id: 1,
1067
+ bili_cookies: encryptedCookies
1068
+ }]);
1069
+ return "验证成功!请重启插件";
1070
+ });
1043
1071
  }
1044
1072
  async init(config) {
1045
1073
  this.logger = this.ctx.logger("cr");
@@ -1920,7 +1948,7 @@ var ComRegister = class {
1920
1948
  this.preInitConfig(subs);
1921
1949
  for (const sub of subs) {
1922
1950
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1923
- const { code: userInfoCode, msg: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1951
+ const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1924
1952
  const data$1 = await this.ctx.ba.getUserInfo(sub.uid);
1925
1953
  return {
1926
1954
  code: 0,
@@ -1933,6 +1961,14 @@ var ComRegister = class {
1933
1961
  message: `加载订阅UID:${sub.uid}失败!`
1934
1962
  };
1935
1963
  });
1964
+ if (userInfoCode === -352 && userInfoData.v_voucher) {
1965
+ this.logger.info("账号被风控,请使用指令 bili captcha 进行风控验证");
1966
+ await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1967
+ return {
1968
+ code: userInfoCode,
1969
+ msg: userInfoMsg
1970
+ };
1971
+ }
1936
1972
  if (userInfoCode !== 0) return {
1937
1973
  code: userInfoCode,
1938
1974
  msg: userInfoMsg
@@ -94945,7 +94981,7 @@ var BiliAPI = class extends Service {
94945
94981
  const csrf = this.getCSRF();
94946
94982
  const ticket = await this.getBiliTicket(csrf);
94947
94983
  if (ticket.code !== 0) throw new Error(`获取BiliTicket失败: ${ticket.message}`);
94948
- this.jar.setCookieSync(`bili_ticket=${ticket.data.ticket}; path=/; domain=.bilibili.com`, "https://www.bilibili.com");
94984
+ this.addCookie(`bili_ticket=${ticket.data.ticket}`);
94949
94985
  this.wbiSign.img_key = ticket.data.nav.img.slice(ticket.data.nav.img.lastIndexOf("/") + 1, ticket.data.nav.img.lastIndexOf("."));
94950
94986
  this.wbiSign.sub_key = ticket.data.nav.sub.slice(ticket.data.nav.sub.lastIndexOf("/") + 1, ticket.data.nav.sub.lastIndexOf("."));
94951
94987
  } catch (e$1) {
@@ -95160,6 +95196,9 @@ var BiliAPI = class extends Service {
95160
95196
  }
95161
95197
  }));
95162
95198
  }
95199
+ addCookie(cookieStr) {
95200
+ this.jar.setCookieSync(`${cookieStr}; path=/; domain=.bilibili.com`, "https://www.bilibili.com");
95201
+ }
95163
95202
  getCookies() {
95164
95203
  try {
95165
95204
  const cookies = this.jar.serializeSync().cookies.map((cookie) => {
@@ -95363,6 +95402,32 @@ var BiliAPI = class extends Service {
95363
95402
  case -400: throw new Error("请求错误");
95364
95403
  }
95365
95404
  }
95405
+ async v_voucherCaptcha(v_voucher) {
95406
+ const csrf = this.getCSRF();
95407
+ const { data: data$1 } = await this.client.post("https://api.bilibili.com/x/gaia-vgate/v1/register", {
95408
+ csrf,
95409
+ v_voucher
95410
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } }).catch((e$1) => {
95411
+ this.logger.error(e$1);
95412
+ });
95413
+ if (data$1.code !== 0) this.logger.error("验证码获取失败!");
95414
+ return { data: data$1.data };
95415
+ }
95416
+ async validateCaptcha(challenge, token, validate$1, seccode) {
95417
+ const csrf = this.getCSRF();
95418
+ const { data: data$1 } = await this.client.post("https://api.bilibili.com/x/gaia-vgate/v1/validate", {
95419
+ csrf,
95420
+ challenge,
95421
+ token,
95422
+ validate: validate$1,
95423
+ seccode
95424
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
95425
+ if (data$1.code !== 0) {
95426
+ this.logger.info(`验证失败:错误码=${data$1.code},错误消息:${data$1.message}`);
95427
+ return { data: null };
95428
+ }
95429
+ return { data: data$1.data };
95430
+ }
95366
95431
  };
95367
95432
  (0, import_decorate.default)([Retry({
95368
95433
  attempts: 3,
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": "3.2.9-rc.4",
4
+ "version": "3.2.10-alpha.1",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -307,6 +307,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
307
307
  > - ver 3.2.9-rc.2 优化:弹幕词云生成效果;
308
308
  > - ver 3.2.9-rc.3 优化:弹幕词云生成效果; 新增:直播总结语,开启弹幕词云后自动发送、选项 `liveSummary` 可自定义直播总结语; 修复:一场直播完成后,如果插件中途没有被关闭过,会影响同一位up主下一次直播词云数据;
309
309
  > - ver 3.2.9-rc.4 优化:弹幕词云生成效果; 新增:直播总结 `-mdn` 变量,代表主播粉丝牌子名
310
+ > - ver 3.2.10-alpha.0 新增:指令 `bili cap` 在遇到风控时,可以手动验证解除风控; 优化:错误消息提示;
311
+ > - ver 3.2.10-alpha.1 优化:使用指令 `bili cap` 后将对应cookie保存到数据库中、 `bili cap` 提示信息;
310
312
 
311
313
  ## 交流群
312
314