koishi-plugin-qxgl-satori 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/lib/index.js +72 -24
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -587,7 +587,9 @@ async function apply(ctx, config) {
587
587
  return next();
588
588
  });
589
589
  ctx.command(pluginName);
590
- ctx.command(pluginName + "/群授权 <channelId> <months> [authorizer]", "群授权管理").authority(config.commandAuthority).action(async ({ session }, channelId, months, authorizer = "蒙面人") => {
590
+ ctx.command(pluginName + "/群授权 <channelId> <months> [authorizer]", "群授权管理", {
591
+ authority: config.commandAuthority
592
+ }).action(async ({ session }, channelId, months, authorizer = "蒙面人") => {
591
593
  if (!channelId || !months) return "格式错误:群授权 <群号> <±月数> [授权人]";
592
594
  const monthsNum = parseInt(months);
593
595
  if (isNaN(monthsNum)) return "请输入有效的月份数(正数增加,负数减少)";
@@ -632,7 +634,9 @@ async function apply(ctx, config) {
632
634
  授权人:${authorizer}
633
635
  更新日期:${formatDate(now)}`;
634
636
  });
635
- ctx.command(pluginName + "/私聊授权 <userId> <months> [authorizer]", "私聊授权管理").authority(config.commandAuthority).action(async ({ session }, userId, months, authorizer = "蒙面人") => {
637
+ ctx.command(pluginName + "/私聊授权 <userId> <months> [authorizer]", "私聊授权管理", {
638
+ authority: config.commandAuthority
639
+ }).action(async ({ session }, userId, months, authorizer = "蒙面人") => {
636
640
  if (!userId || !months) return "格式错误:私聊授权 <用户ID> <±月数> [授权人]";
637
641
  const monthsNum = parseInt(months);
638
642
  if (isNaN(monthsNum)) return "请输入有效的月份数";
@@ -668,7 +672,9 @@ async function apply(ctx, config) {
668
672
  到期时间:${formatDate(newExpiry)}
669
673
  授权人:${authorizer}`;
670
674
  });
671
- ctx.command(pluginName + "/取消授权 <targetId>", "取消指定群/私聊授权").authority(config.commandAuthority).action(async ({ session }, targetId) => {
675
+ ctx.command(pluginName + "/取消授权 <targetId>", "取消指定群/私聊授权", {
676
+ authority: config.commandAuthority
677
+ }).action(async ({ session }, targetId) => {
672
678
  if (!targetId) return "请提供目标ID";
673
679
  const channelId = targetId.startsWith("private:") ? targetId : targetId;
674
680
  const { platform } = session;
@@ -677,7 +683,9 @@ async function apply(ctx, config) {
677
683
  await ctx.database.remove("qxgl_satori_auth", { platform, channelId });
678
684
  return `已取消授权:${targetId}`;
679
685
  });
680
- ctx.command(pluginName + "/更换授权 <sourceId> <targetId>", "迁移授权数据").authority(config.commandAuthority).action(async ({ session }, sourceId, targetId) => {
686
+ ctx.command(pluginName + "/更换授权 <sourceId> <targetId>", "迁移授权数据", {
687
+ authority: config.commandAuthority
688
+ }).action(async ({ session }, sourceId, targetId) => {
681
689
  if (!sourceId || !targetId) return "格式:更换授权 <原ID> <新ID>";
682
690
  const sourceChannel = sourceId.startsWith("private:") ? sourceId : sourceId;
683
691
  const targetChannel = targetId.startsWith("private:") ? targetId : targetId;
@@ -696,7 +704,9 @@ async function apply(ctx, config) {
696
704
  await ctx.database.remove("qxgl_satori_auth", { platform, channelId: sourceChannel });
697
705
  return `授权已从 ${sourceId} 迁移到 ${targetId}`;
698
706
  });
699
- ctx.command(pluginName + "/到期时间", "查询当前授权到期时间").authority(0).action(async ({ session }) => {
707
+ ctx.command(pluginName + "/到期时间", "查询当前授权到期时间", {
708
+ authority: 0
709
+ }).action(async ({ session }) => {
700
710
  const { platform, channelId } = session;
701
711
  const record = await ctx.database.get("qxgl_satori_auth", { platform, channelId });
702
712
  if (record.length === 0 || !record[0].expiryDate) {
@@ -706,7 +716,9 @@ async function apply(ctx, config) {
706
716
  授权人:${record[0].authorizer || "未知"}
707
717
  更新于:${formatDate(record[0].updateDate)}`;
708
718
  });
709
- ctx.command(pluginName + "/查询到期 <targetId>", "查询指定目标授权").authority(config.commandAuthority).action(async ({ session }, targetId) => {
719
+ ctx.command(pluginName + "/查询到期 <targetId>", "查询指定目标授权", {
720
+ authority: config.commandAuthority
721
+ }).action(async ({ session }, targetId) => {
710
722
  const channelId = targetId.startsWith("private:") ? targetId : targetId;
711
723
  const record = await ctx.database.get("qxgl_satori_auth", {
712
724
  platform: session.platform,
@@ -717,7 +729,9 @@ async function apply(ctx, config) {
717
729
  到期:${formatDate(record[0].expiryDate)}
718
730
  授权人:${record[0].authorizer || "未知"}`;
719
731
  });
720
- ctx.command(pluginName + "/全局延期 <days>", "为所有授权增加天数").authority(config.commandAuthority).action(async ({ session }, days) => {
732
+ ctx.command(pluginName + "/全局延期 <days>", "为所有授权增加天数", {
733
+ authority: config.commandAuthority
734
+ }).action(async ({ session }, days) => {
721
735
  const d = parseInt(days);
722
736
  if (isNaN(d) || d <= 0) return "请输入正整数天数";
723
737
  const records = await ctx.database.get("qxgl_satori_auth");
@@ -736,7 +750,9 @@ async function apply(ctx, config) {
736
750
  }
737
751
  return `已为 ${count} 个有效授权延期 ${d} 天`;
738
752
  });
739
- ctx.command(pluginName + "/全局减少 <days>", "为所有授权减少天数").authority(config.commandAuthority).action(async ({ session }, days) => {
753
+ ctx.command(pluginName + "/全局减少 <days>", "为所有授权减少天数", {
754
+ authority: config.commandAuthority
755
+ }).action(async ({ session }, days) => {
740
756
  const d = parseInt(days);
741
757
  if (isNaN(d) || d <= 0) return "请输入正整数天数";
742
758
  const records = await ctx.database.get("qxgl_satori_auth");
@@ -755,7 +771,9 @@ async function apply(ctx, config) {
755
771
  }
756
772
  return `已为 ${count} 个授权减少 ${d} 天`;
757
773
  });
758
- ctx.command(pluginName + "/更新名称", "刷新群名称缓存").authority(config.commandAuthority).action(async ({ session }) => {
774
+ ctx.command(pluginName + "/更新名称", "刷新群名称缓存", {
775
+ authority: config.commandAuthority
776
+ }).action(async ({ session }) => {
759
777
  const records = await ctx.database.get("qxgl_satori_auth");
760
778
  let count = 0;
761
779
  for (const r of records) {
@@ -777,7 +795,9 @@ async function apply(ctx, config) {
777
795
  }
778
796
  return `已更新 ${count} 个群名称`;
779
797
  });
780
- ctx.command(pluginName + "/列出已记录群", "列出所有群授权状态").authority(config.commandAuthority).action(async () => {
798
+ ctx.command(pluginName + "/列出已记录群", "列出所有群授权状态", {
799
+ authority: config.commandAuthority
800
+ }).action(async () => {
781
801
  const records = await ctx.database.get("qxgl_satori_auth");
782
802
  const groups = records.filter((r) => !r.channelId.startsWith("private:"));
783
803
  if (groups.length === 0) return "暂无群记录";
@@ -789,7 +809,9 @@ async function apply(ctx, config) {
789
809
  状态:${r.isBlocked ? "已拉黑" : "正常"}`
790
810
  ).join("\n\n");
791
811
  });
792
- ctx.command(pluginName + "/备份数据", "备份数据到JSON").authority(config.commandAuthority).action(async () => {
812
+ ctx.command(pluginName + "/备份数据", "备份数据到JSON", {
813
+ authority: config.commandAuthority
814
+ }).action(async () => {
793
815
  const records = await ctx.database.get("qxgl_satori_auth");
794
816
  const backupPath = path.join(dataDir, `backup_${Date.now()}.json`);
795
817
  await fs.writeFile(backupPath, JSON.stringify(records, null, 2));
@@ -836,11 +858,15 @@ async function apply(ctx, config) {
836
858
  return `关键词 "${keyword}" 添加完成,共 ${data[key].length} 条回复`;
837
859
  }
838
860
  __name(addKeywordLogic, "addKeywordLogic");
839
- ctx.command(pluginName + `/${config.triggerPrefix} [keyword]`, "添加关键词").option("regex", "-x 使用正则匹配").authority(config.commandAuthority).action(async ({ session, options }, keyword) => {
861
+ ctx.command(pluginName + `/${config.triggerPrefix} [keyword]`, "添加关键词", {
862
+ authority: config.commandAuthority
863
+ }).option("regex", "-x 使用正则匹配").action(async ({ session, options }, keyword) => {
840
864
  if (!hasPermission(session, "添加")) return "权限不足";
841
865
  return addKeywordLogic(session, keyword, false, options.regex);
842
866
  });
843
- ctx.command(pluginName + `/${config.globalTriggerPrefix} [keyword]`, "添加全局关键词").option("regex", "-x 使用正则匹配").authority(config.commandAuthority).action(async ({ session, options }, keyword) => {
867
+ ctx.command(pluginName + `/${config.globalTriggerPrefix} [keyword]`, "添加全局关键词", {
868
+ authority: config.commandAuthority
869
+ }).option("regex", "-x 使用正则匹配").action(async ({ session, options }, keyword) => {
844
870
  if (!hasPermission(session, "全局添加")) return "权限不足";
845
871
  return addKeywordLogic(session, keyword, true, options.regex);
846
872
  });
@@ -882,11 +908,15 @@ async function apply(ctx, config) {
882
908
  }
883
909
  }
884
910
  __name(deleteKeywordLogic, "deleteKeywordLogic");
885
- ctx.command(pluginName + `/${config.deletePrefix} [keyword]`, "删除关键词").option("index", "-q <number> 指定回复序号").authority(config.commandAuthority).action(async ({ session, options }, keyword) => {
911
+ ctx.command(pluginName + `/${config.deletePrefix} [keyword]`, "删除关键词", {
912
+ authority: config.commandAuthority
913
+ }).option("index", "-q <number> 指定回复序号").action(async ({ session, options }, keyword) => {
886
914
  if (!hasPermission(session, "删除")) return "权限不足";
887
915
  return deleteKeywordLogic(session, keyword, false, options.index);
888
916
  });
889
- ctx.command(pluginName + `/${config.globalDeletePrefix} [keyword]`, "删除全局关键词").option("index", "-q <number> 指定回复序号").authority(config.commandAuthority).action(async ({ session, options }, keyword) => {
917
+ ctx.command(pluginName + `/${config.globalDeletePrefix} [keyword]`, "删除全局关键词", {
918
+ authority: config.commandAuthority
919
+ }).option("index", "-q <number> 指定回复序号").action(async ({ session, options }, keyword) => {
890
920
  if (!hasPermission(session, "全局删除")) return "权限不足";
891
921
  return deleteKeywordLogic(session, keyword, true, options.index);
892
922
  });
@@ -914,15 +944,21 @@ async function apply(ctx, config) {
914
944
  return "修改完成";
915
945
  }
916
946
  __name(fixKeywordLogic, "fixKeywordLogic");
917
- ctx.command(pluginName + `/${config.fixCommand} [keyword]`, "修改关键词").option("index", "-q <number> 回复序号").authority(config.commandAuthority).action(async ({ session, options }, keyword) => {
947
+ ctx.command(pluginName + `/${config.fixCommand} [keyword]`, "修改关键词", {
948
+ authority: config.commandAuthority
949
+ }).option("index", "-q <number> 回复序号").action(async ({ session, options }, keyword) => {
918
950
  if (!hasPermission(session, "修改")) return "权限不足";
919
951
  return fixKeywordLogic(session, keyword, false, (options.index || 1) - 1);
920
952
  });
921
- ctx.command(pluginName + `/${config.globalFixCommand} [keyword]`, "修改全局关键词").option("index", "-q <number> 回复序号").authority(config.commandAuthority).action(async ({ session, options }, keyword) => {
953
+ ctx.command(pluginName + `/${config.globalFixCommand} [keyword]`, "修改全局关键词", {
954
+ authority: config.commandAuthority
955
+ }).option("index", "-q <number> 回复序号").action(async ({ session, options }, keyword) => {
922
956
  if (!hasPermission(session, "全局修改")) return "权限不足";
923
957
  return fixKeywordLogic(session, keyword, true, (options.index || 1) - 1);
924
958
  });
925
- ctx.command(pluginName + `/${config.searchCommand} [keyword]`, "查找关键词").authority(config.commandAuthority).action(async ({ session }, keyword) => {
959
+ ctx.command(pluginName + `/${config.searchCommand} [keyword]`, "查找关键词", {
960
+ authority: config.commandAuthority
961
+ }).action(async ({ session }, keyword) => {
926
962
  if (!hasPermission(session, "查找关键词")) return "权限不足";
927
963
  if (!keyword) return "请输入搜索词";
928
964
  let files = [];
@@ -945,7 +981,9 @@ async function apply(ctx, config) {
945
981
  }
946
982
  return results.length ? results.slice(0, 10).join("\n") : "未找到";
947
983
  });
948
- ctx.command(pluginName + `/${config.viewListCommand}`, "查看关键词列表").authority(config.commandAuthority).action(async ({ session }) => {
984
+ ctx.command(pluginName + `/${config.viewListCommand}`, "查看关键词列表", {
985
+ authority: config.commandAuthority
986
+ }).action(async ({ session }) => {
949
987
  if (!hasPermission(session, "查看关键词列表")) return "权限不足";
950
988
  const filePath = getFilePath(session.channelId);
951
989
  const globalPath = getFilePath(null, true);
@@ -959,7 +997,9 @@ async function apply(ctx, config) {
959
997
  if (keys.length === 0) return "暂无关键词";
960
998
  return keys.join("\n");
961
999
  });
962
- ctx.command(pluginName + "/测试授权 <targetId...>", "加入测试名单").authority(config.commandAuthority).action(async ({ session }, ...targets) => {
1000
+ ctx.command(pluginName + "/测试授权 <targetId...>", "加入测试名单", {
1001
+ authority: config.commandAuthority
1002
+ }).action(async ({ session }, ...targets) => {
963
1003
  if (!targets.length) return "请提供目标ID";
964
1004
  const allRecords = await ctx.database.get("qxgl_satori_auth");
965
1005
  let testChannels = [];
@@ -979,7 +1019,9 @@ async function apply(ctx, config) {
979
1019
  }
980
1020
  return `已添加测试:${added.join("、") || "无新增"}`;
981
1021
  });
982
- ctx.command(pluginName + "/取消测试授权 <targetId...>", "移出测试名单").authority(config.commandAuthority).action(async ({ session }, ...targets) => {
1022
+ ctx.command(pluginName + "/取消测试授权 <targetId...>", "移出测试名单", {
1023
+ authority: config.commandAuthority
1024
+ }).action(async ({ session }, ...targets) => {
983
1025
  const allRecords = await ctx.database.get("qxgl_satori_auth");
984
1026
  if (!allRecords.length) return "无数据";
985
1027
  let testChannels = allRecords[0].testChannels || [];
@@ -1001,14 +1043,18 @@ async function apply(ctx, config) {
1001
1043
  await ctx.database.set("qxgl_satori_auth", {}, { testChannels });
1002
1044
  return `已移出:${removed.join("、") || "无"}`;
1003
1045
  });
1004
- ctx.command(pluginName + "/测试同步", "正式→测试数据同步").authority(config.commandAuthority).action(async () => {
1046
+ ctx.command(pluginName + "/测试同步", "正式→测试数据同步", {
1047
+ authority: config.commandAuthority
1048
+ }).action(async () => {
1005
1049
  const globalPath = getFilePath(null, true);
1006
1050
  if (!fsSync.existsSync(globalPath)) return "全局文件不存在";
1007
1051
  fsSync.copyFileSync(globalPath, testFilePath);
1008
1052
  const count = Object.keys(JSON.parse(fsSync.readFileSync(testFilePath, "utf-8"))).length;
1009
1053
  return `测试同步完成,共 ${count} 条数据`;
1010
1054
  });
1011
- ctx.command(pluginName + "/测试发布", "测试→正式发布(带备份)").alias("测试转正").authority(config.commandAuthority).action(async () => {
1055
+ ctx.command(pluginName + "/测试发布", "测试→正式发布(带备份)", {
1056
+ authority: config.commandAuthority
1057
+ }).alias("测试转正").action(async () => {
1012
1058
  if (!fsSync.existsSync(testFilePath)) return "测试文件不存在";
1013
1059
  const globalPath = getFilePath(null, true);
1014
1060
  const backupPath = path.join(dataDir, `global.json.bak_${Date.now()}`);
@@ -1019,7 +1065,9 @@ async function apply(ctx, config) {
1019
1065
  const count = Object.keys(JSON.parse(fsSync.readFileSync(globalPath, "utf-8"))).length;
1020
1066
  return `测试发布完成,共 ${count} 条数据,原数据已备份`;
1021
1067
  });
1022
- ctx.command(pluginName + "/测试添加 <keyword>", "测试环境添加").option("regex", "-x").authority(config.commandAuthority).action(async ({ session, options }, keyword) => {
1068
+ ctx.command(pluginName + "/测试添加 <keyword>", "测试环境添加", {
1069
+ authority: config.commandAuthority
1070
+ }).option("regex", "-x").action(async ({ session, options }, keyword) => {
1023
1071
  if (!hasPermission(session, "测试添加")) return "权限不足";
1024
1072
  if (!fsSync.existsSync(testFilePath)) fsSync.writeFileSync(testFilePath, "{}");
1025
1073
  let data = JSON.parse(fsSync.readFileSync(testFilePath, "utf-8"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-qxgl-satori",
3
3
  "description": "开发中",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [