koishi-plugin-cocoyyy-console 1.0.7 → 1.0.8-beta.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 +73 -45
- package/lib/services/test_command.d.ts +3 -1
- package/lib/utils/common.d.ts +3 -1
- package/package.json +3 -5
- package/lib/services/img_service.d.ts +0 -8
- package/lib/services/rbq_func/random_temp.d.ts +0 -0
- package/lib/services/repeat_func/repeat_temp.d.ts +0 -1
- package/lib/services/tag_service.d.ts +0 -20
package/lib/index.js
CHANGED
|
@@ -262,6 +262,7 @@ function getImgsModel() {
|
|
|
262
262
|
__name(getImgsModel, "getImgsModel");
|
|
263
263
|
|
|
264
264
|
// src/utils/common.ts
|
|
265
|
+
var dev_mode = true;
|
|
265
266
|
function is_at_bot(session) {
|
|
266
267
|
const elements = Array.isArray(session?.elements) ? session.elements : [];
|
|
267
268
|
const atElement = elements.find((element) => element?.type === "at");
|
|
@@ -368,11 +369,11 @@ function getTagFuncMenu(command = null) {
|
|
|
368
369
|
}
|
|
369
370
|
__name(getTagFuncMenu, "getTagFuncMenu");
|
|
370
371
|
function registerMenuCommands(ctx, connected, functionConfig) {
|
|
371
|
-
ctx.command("help <参数>", "帮助菜单").
|
|
372
|
-
if (!
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
372
|
+
ctx.command("help <参数>", "帮助菜单").action(async ({ session }, ...args) => {
|
|
373
|
+
if (!dev_mode) {
|
|
374
|
+
if (!connected) return;
|
|
375
|
+
if (!is_at_bot(session)) return;
|
|
376
|
+
}
|
|
376
377
|
const command = args?.[0];
|
|
377
378
|
return getMenuList(command, functionConfig);
|
|
378
379
|
});
|
|
@@ -671,11 +672,11 @@ __name(getTagList, "getTagList");
|
|
|
671
672
|
var import_url = require("url");
|
|
672
673
|
var uid_tag_map = /* @__PURE__ */ new Map();
|
|
673
674
|
function registerTagCommands(ctx, connected, savePath2) {
|
|
674
|
-
ctx.command("maketag <参数>", "创建一个标签").
|
|
675
|
-
if (!
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
675
|
+
ctx.command("maketag <参数>", "创建一个标签").action(async ({ session }, ...args) => {
|
|
676
|
+
if (!dev_mode) {
|
|
677
|
+
if (!connected) return;
|
|
678
|
+
if (!is_at_bot(session)) return;
|
|
679
|
+
}
|
|
679
680
|
const tag = args?.[0];
|
|
680
681
|
if (!tag) return "请提供正确格式,如:@bot maketag [标签]";
|
|
681
682
|
let exec = await createorUpdateTag(tag, session.guildId, savePath2);
|
|
@@ -683,11 +684,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
683
684
|
return `创建标签失败:${exec.error}`;
|
|
684
685
|
return `已创建标签:${tag}`;
|
|
685
686
|
});
|
|
686
|
-
ctx.command("add <参数>", "给标签添加图片").
|
|
687
|
-
if (!
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
687
|
+
ctx.command("add <参数>", "给标签添加图片").action(async ({ session }, ...args) => {
|
|
688
|
+
if (!dev_mode) {
|
|
689
|
+
if (!connected) return;
|
|
690
|
+
if (!is_at_bot(session)) return;
|
|
691
|
+
}
|
|
691
692
|
const tag = args?.[0];
|
|
692
693
|
const img = args?.[1];
|
|
693
694
|
if (!tag || !img) return "请提供正确格式,如:@bot add [标签] [图片]";
|
|
@@ -696,11 +697,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
696
697
|
return `保存图片失败:${exec.error}`;
|
|
697
698
|
return "保存图片成功";
|
|
698
699
|
});
|
|
699
|
-
ctx.command("get <参数>", "获取标签对应图片").
|
|
700
|
-
if (!
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
700
|
+
ctx.command("get <参数>", "获取标签对应图片").action(async ({ session }, ...args) => {
|
|
701
|
+
if (!dev_mode) {
|
|
702
|
+
if (!connected) return;
|
|
703
|
+
if (!is_at_bot(session)) return;
|
|
704
|
+
}
|
|
704
705
|
const tag = args?.[0];
|
|
705
706
|
if (!tag) return "请提供正确格式,如:@bot get [标签]";
|
|
706
707
|
let exec = await randomImgByTag(tag, session.guildId);
|
|
@@ -709,11 +710,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
709
710
|
let path = (0, import_url.pathToFileURL)(exec).href;
|
|
710
711
|
return import_koishi7.h.image(path);
|
|
711
712
|
});
|
|
712
|
-
ctx.command("bind <参数>", "标签绑定别名").
|
|
713
|
-
if (!
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
713
|
+
ctx.command("bind <参数>", "标签绑定别名").action(async ({ session }, ...args) => {
|
|
714
|
+
if (!dev_mode) {
|
|
715
|
+
if (!connected) return;
|
|
716
|
+
if (!is_at_bot(session)) return;
|
|
717
|
+
}
|
|
717
718
|
const tag = args?.[0];
|
|
718
719
|
const alia = args?.[1];
|
|
719
720
|
if (!tag || !alia) return "请提供正确格式,如:@bot bind [标签] [别名]";
|
|
@@ -722,11 +723,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
722
723
|
return `绑定别名失败:${exec.error}`;
|
|
723
724
|
return `绑定别名成功`;
|
|
724
725
|
});
|
|
725
|
-
ctx.command("unbind <参数>", "标签取消别名").
|
|
726
|
-
if (!
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
726
|
+
ctx.command("unbind <参数>", "标签取消别名").action(async ({ session }, ...args) => {
|
|
727
|
+
if (!dev_mode) {
|
|
728
|
+
if (!connected) return;
|
|
729
|
+
if (!is_at_bot(session)) return;
|
|
730
|
+
}
|
|
730
731
|
const tag = args?.[0];
|
|
731
732
|
const alia = args?.[1];
|
|
732
733
|
if (!tag || !alia) return "请提供正确格式,如:@bot unbind [标签] [别名]";
|
|
@@ -735,11 +736,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
735
736
|
return `取消绑定失败:${exec.error}`;
|
|
736
737
|
return `取消绑定成功`;
|
|
737
738
|
});
|
|
738
|
-
ctx.command("addstart <参数>", "开始给标签批量添加图片").
|
|
739
|
-
if (!
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
739
|
+
ctx.command("addstart <参数>", "开始给标签批量添加图片").action(async ({ session }, ...args) => {
|
|
740
|
+
if (!dev_mode) {
|
|
741
|
+
if (!connected) return;
|
|
742
|
+
if (!is_at_bot(session)) return;
|
|
743
|
+
}
|
|
743
744
|
const tag = args?.[0];
|
|
744
745
|
if (!tag) return "请提供正确格式,如:@bot addstart [标签]";
|
|
745
746
|
let exec = await startBatchAddImg(ctx, tag, session, savePath2);
|
|
@@ -747,21 +748,21 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
747
748
|
return exec.error;
|
|
748
749
|
return "[开始记录图片]";
|
|
749
750
|
});
|
|
750
|
-
ctx.command("addend", "结束给标签批量添加图片").
|
|
751
|
-
if (!
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
751
|
+
ctx.command("addend", "结束给标签批量添加图片").action(async ({ session }) => {
|
|
752
|
+
if (!dev_mode) {
|
|
753
|
+
if (!connected) return;
|
|
754
|
+
if (!is_at_bot(session)) return;
|
|
755
|
+
}
|
|
755
756
|
let exec = await endBatchAddImg(ctx, session);
|
|
756
757
|
if (!exec.result)
|
|
757
758
|
return exec.error;
|
|
758
759
|
return "[停止记录图片]";
|
|
759
760
|
});
|
|
760
|
-
ctx.command("taglist", "获取标签列表").
|
|
761
|
-
if (!
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
761
|
+
ctx.command("taglist", "获取标签列表").action(async ({ session }) => {
|
|
762
|
+
if (!dev_mode) {
|
|
763
|
+
if (!connected) return;
|
|
764
|
+
if (!is_at_bot(session)) return;
|
|
765
|
+
}
|
|
765
766
|
let exec = await getTagList(session.guildId);
|
|
766
767
|
if (exec == null)
|
|
767
768
|
return `查询失败`;
|
|
@@ -775,6 +776,7 @@ ${exec.map((item) => "标签:" + item.tag + " 黑历史数:" + item.count + "\n
|
|
|
775
776
|
const img = session.content;
|
|
776
777
|
const srcMatch = img.match(/src="([^"]+)"/);
|
|
777
778
|
if (!srcMatch) return "请给出图片,如需停止记录图片,请输入@bot addend [标签]";
|
|
779
|
+
logger.error("[input content]: " + img);
|
|
778
780
|
let exec = await saveImg(ctx, tag, session.guildId, img, savePath2);
|
|
779
781
|
if (!exec.result)
|
|
780
782
|
return `保存失败:${exec.error}`;
|
|
@@ -874,6 +876,30 @@ function registerRbqMiddleware(ctx, config) {
|
|
|
874
876
|
}
|
|
875
877
|
__name(registerRbqMiddleware, "registerRbqMiddleware");
|
|
876
878
|
|
|
879
|
+
// src/services/test_command.ts
|
|
880
|
+
function registerTestCommands(ctx) {
|
|
881
|
+
ctx.command("test <参数>", "获取指定群的成员列表").action(async ({ session }, guildId) => {
|
|
882
|
+
if (!guildId) return "请提供群号";
|
|
883
|
+
const bot = ctx.bots[session.uid] || Object.values(ctx.bots)[0];
|
|
884
|
+
if (!bot) return "未找到可用的机器人实例";
|
|
885
|
+
try {
|
|
886
|
+
if (bot.platform !== "onebot") return "当前平台不支持该操作";
|
|
887
|
+
const members = await session.bot.internal.get_group_member_list(guildId);
|
|
888
|
+
if (!members?.length) {
|
|
889
|
+
return `群 ${guildId} 未获取到成员,请检查权限或机器人是否在群中。`;
|
|
890
|
+
}
|
|
891
|
+
const ids = members.map((m) => m.user_id || m.id).join("\n");
|
|
892
|
+
console.log(`[群 ${guildId}] 成员数量: ${members.length}`);
|
|
893
|
+
return `群 ${guildId} 共 ${members.length} 位成员:
|
|
894
|
+
${ids}`;
|
|
895
|
+
} catch (err) {
|
|
896
|
+
console.error(err);
|
|
897
|
+
return `获取群成员失败:${err.message}`;
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
__name(registerTestCommands, "registerTestCommands");
|
|
902
|
+
|
|
877
903
|
// src/index.ts
|
|
878
904
|
var name = "cocoyyy-console";
|
|
879
905
|
var Config = import_koishi9.Schema.object({
|
|
@@ -902,6 +928,8 @@ async function apply(ctx, config) {
|
|
|
902
928
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
903
929
|
if (config.function_config.rbq_flag)
|
|
904
930
|
registerRbqMiddleware(ctx, config?.rbq_config);
|
|
931
|
+
if (dev_mode)
|
|
932
|
+
registerTestCommands(ctx);
|
|
905
933
|
}
|
|
906
934
|
__name(apply, "apply");
|
|
907
935
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/utils/common.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-cocoyyy-console",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "1.0.
|
|
3
|
+
"description": "自用koishi插件,功能包含复读,记录黑历史,*人等",
|
|
4
|
+
"version": "1.0.8-beta.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
|
-
"contributors": [
|
|
7
|
+
"contributors": [
|
|
8
8
|
"黑椰Coco <yyycoconut1130@gmail.com>"
|
|
9
9
|
],
|
|
10
10
|
"files": [
|
|
@@ -12,13 +12,11 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"scripts": {},
|
|
16
15
|
"keywords": [
|
|
17
16
|
"chatbot",
|
|
18
17
|
"koishi",
|
|
19
18
|
"plugin"
|
|
20
19
|
],
|
|
21
|
-
"devDependencies": {},
|
|
22
20
|
"peerDependencies": {
|
|
23
21
|
"koishi": "^4.18.7"
|
|
24
22
|
},
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Context } from "koishi";
|
|
2
|
-
declare function saveImg(ctx: Context, tag_name: string, imgurl: string, savePath: string): Promise<{
|
|
3
|
-
result: boolean;
|
|
4
|
-
error: string | null;
|
|
5
|
-
}>;
|
|
6
|
-
declare function randomImgByTag(tag_name: string): Promise<string | null>;
|
|
7
|
-
declare function getImgCountByTag(tag_id: number): Promise<number>;
|
|
8
|
-
export { saveImg, randomImgByTag, getImgCountByTag };
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { TagsModel } from '../models/tags';
|
|
2
|
-
declare function createorUpdateTag(tag_name: string, savePath?: string | null): Promise<{
|
|
3
|
-
result: boolean;
|
|
4
|
-
error: string | null;
|
|
5
|
-
}>;
|
|
6
|
-
declare function getTag(tag_name: string): Promise<TagsModel | null>;
|
|
7
|
-
declare function bindAlias(tag_name: string, alias: string): Promise<{
|
|
8
|
-
result: boolean;
|
|
9
|
-
error: string | null;
|
|
10
|
-
}>;
|
|
11
|
-
declare function unbindAlias(tag_name: string, alias: string): Promise<{
|
|
12
|
-
result: boolean;
|
|
13
|
-
error: string | null;
|
|
14
|
-
}>;
|
|
15
|
-
declare function getTagList(): Promise<{
|
|
16
|
-
tag: string;
|
|
17
|
-
alias: string;
|
|
18
|
-
count: number;
|
|
19
|
-
}[]>;
|
|
20
|
-
export { createorUpdateTag, getTag, bindAlias, unbindAlias, getTagList };
|