koishi-plugin-cocoyyy-console 1.0.6 → 1.0.8-beta.0
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 -36
- package/lib/services/test_command.d.ts +3 -1
- package/lib/utils/common.d.ts +3 -1
- package/package.json +2 -4
- 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,10 +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
|
-
|
|
372
|
+
ctx.command("help <参数>", "帮助菜单").action(async ({ session }, ...args) => {
|
|
373
|
+
if (!dev_mode) {
|
|
374
|
+
if (!connected) return;
|
|
375
|
+
if (!is_at_bot(session)) return;
|
|
376
|
+
}
|
|
375
377
|
const command = args?.[0];
|
|
376
378
|
return getMenuList(command, functionConfig);
|
|
377
379
|
});
|
|
@@ -670,10 +672,11 @@ __name(getTagList, "getTagList");
|
|
|
670
672
|
var import_url = require("url");
|
|
671
673
|
var uid_tag_map = /* @__PURE__ */ new Map();
|
|
672
674
|
function registerTagCommands(ctx, connected, savePath2) {
|
|
673
|
-
ctx.command("maketag <参数>", "创建一个标签").
|
|
674
|
-
if (!
|
|
675
|
-
|
|
676
|
-
|
|
675
|
+
ctx.command("maketag <参数>", "创建一个标签").action(async ({ session }, ...args) => {
|
|
676
|
+
if (!dev_mode) {
|
|
677
|
+
if (!connected) return;
|
|
678
|
+
if (!is_at_bot(session)) return;
|
|
679
|
+
}
|
|
677
680
|
const tag = args?.[0];
|
|
678
681
|
if (!tag) return "请提供正确格式,如:@bot maketag [标签]";
|
|
679
682
|
let exec = await createorUpdateTag(tag, session.guildId, savePath2);
|
|
@@ -681,10 +684,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
681
684
|
return `创建标签失败:${exec.error}`;
|
|
682
685
|
return `已创建标签:${tag}`;
|
|
683
686
|
});
|
|
684
|
-
ctx.command("add <参数>", "给标签添加图片").
|
|
685
|
-
if (!
|
|
686
|
-
|
|
687
|
-
|
|
687
|
+
ctx.command("add <参数>", "给标签添加图片").action(async ({ session }, ...args) => {
|
|
688
|
+
if (!dev_mode) {
|
|
689
|
+
if (!connected) return;
|
|
690
|
+
if (!is_at_bot(session)) return;
|
|
691
|
+
}
|
|
688
692
|
const tag = args?.[0];
|
|
689
693
|
const img = args?.[1];
|
|
690
694
|
if (!tag || !img) return "请提供正确格式,如:@bot add [标签] [图片]";
|
|
@@ -693,10 +697,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
693
697
|
return `保存图片失败:${exec.error}`;
|
|
694
698
|
return "保存图片成功";
|
|
695
699
|
});
|
|
696
|
-
ctx.command("get <参数>", "获取标签对应图片").
|
|
697
|
-
if (!
|
|
698
|
-
|
|
699
|
-
|
|
700
|
+
ctx.command("get <参数>", "获取标签对应图片").action(async ({ session }, ...args) => {
|
|
701
|
+
if (!dev_mode) {
|
|
702
|
+
if (!connected) return;
|
|
703
|
+
if (!is_at_bot(session)) return;
|
|
704
|
+
}
|
|
700
705
|
const tag = args?.[0];
|
|
701
706
|
if (!tag) return "请提供正确格式,如:@bot get [标签]";
|
|
702
707
|
let exec = await randomImgByTag(tag, session.guildId);
|
|
@@ -705,10 +710,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
705
710
|
let path = (0, import_url.pathToFileURL)(exec).href;
|
|
706
711
|
return import_koishi7.h.image(path);
|
|
707
712
|
});
|
|
708
|
-
ctx.command("bind <参数>", "标签绑定别名").
|
|
709
|
-
if (!
|
|
710
|
-
|
|
711
|
-
|
|
713
|
+
ctx.command("bind <参数>", "标签绑定别名").action(async ({ session }, ...args) => {
|
|
714
|
+
if (!dev_mode) {
|
|
715
|
+
if (!connected) return;
|
|
716
|
+
if (!is_at_bot(session)) return;
|
|
717
|
+
}
|
|
712
718
|
const tag = args?.[0];
|
|
713
719
|
const alia = args?.[1];
|
|
714
720
|
if (!tag || !alia) return "请提供正确格式,如:@bot bind [标签] [别名]";
|
|
@@ -717,10 +723,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
717
723
|
return `绑定别名失败:${exec.error}`;
|
|
718
724
|
return `绑定别名成功`;
|
|
719
725
|
});
|
|
720
|
-
ctx.command("unbind <参数>", "标签取消别名").
|
|
721
|
-
if (!
|
|
722
|
-
|
|
723
|
-
|
|
726
|
+
ctx.command("unbind <参数>", "标签取消别名").action(async ({ session }, ...args) => {
|
|
727
|
+
if (!dev_mode) {
|
|
728
|
+
if (!connected) return;
|
|
729
|
+
if (!is_at_bot(session)) return;
|
|
730
|
+
}
|
|
724
731
|
const tag = args?.[0];
|
|
725
732
|
const alia = args?.[1];
|
|
726
733
|
if (!tag || !alia) return "请提供正确格式,如:@bot unbind [标签] [别名]";
|
|
@@ -729,10 +736,11 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
729
736
|
return `取消绑定失败:${exec.error}`;
|
|
730
737
|
return `取消绑定成功`;
|
|
731
738
|
});
|
|
732
|
-
ctx.command("addstart <参数>", "开始给标签批量添加图片").
|
|
733
|
-
if (!
|
|
734
|
-
|
|
735
|
-
|
|
739
|
+
ctx.command("addstart <参数>", "开始给标签批量添加图片").action(async ({ session }, ...args) => {
|
|
740
|
+
if (!dev_mode) {
|
|
741
|
+
if (!connected) return;
|
|
742
|
+
if (!is_at_bot(session)) return;
|
|
743
|
+
}
|
|
736
744
|
const tag = args?.[0];
|
|
737
745
|
if (!tag) return "请提供正确格式,如:@bot addstart [标签]";
|
|
738
746
|
let exec = await startBatchAddImg(ctx, tag, session, savePath2);
|
|
@@ -740,19 +748,21 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
740
748
|
return exec.error;
|
|
741
749
|
return "[开始记录图片]";
|
|
742
750
|
});
|
|
743
|
-
ctx.command("addend", "结束给标签批量添加图片").
|
|
744
|
-
if (!
|
|
745
|
-
|
|
746
|
-
|
|
751
|
+
ctx.command("addend", "结束给标签批量添加图片").action(async ({ session }) => {
|
|
752
|
+
if (!dev_mode) {
|
|
753
|
+
if (!connected) return;
|
|
754
|
+
if (!is_at_bot(session)) return;
|
|
755
|
+
}
|
|
747
756
|
let exec = await endBatchAddImg(ctx, session);
|
|
748
757
|
if (!exec.result)
|
|
749
758
|
return exec.error;
|
|
750
759
|
return "[停止记录图片]";
|
|
751
760
|
});
|
|
752
|
-
ctx.command("taglist", "获取标签列表").
|
|
753
|
-
if (!
|
|
754
|
-
|
|
755
|
-
|
|
761
|
+
ctx.command("taglist", "获取标签列表").action(async ({ session }) => {
|
|
762
|
+
if (!dev_mode) {
|
|
763
|
+
if (!connected) return;
|
|
764
|
+
if (!is_at_bot(session)) return;
|
|
765
|
+
}
|
|
756
766
|
let exec = await getTagList(session.guildId);
|
|
757
767
|
if (exec == null)
|
|
758
768
|
return `查询失败`;
|
|
@@ -766,6 +776,7 @@ ${exec.map((item) => "标签:" + item.tag + " 黑历史数:" + item.count + "\n
|
|
|
766
776
|
const img = session.content;
|
|
767
777
|
const srcMatch = img.match(/src="([^"]+)"/);
|
|
768
778
|
if (!srcMatch) return "请给出图片,如需停止记录图片,请输入@bot addend [标签]";
|
|
779
|
+
logger.error("[input content]: " + img);
|
|
769
780
|
let exec = await saveImg(ctx, tag, session.guildId, img, savePath2);
|
|
770
781
|
if (!exec.result)
|
|
771
782
|
return `保存失败:${exec.error}`;
|
|
@@ -865,6 +876,30 @@ function registerRbqMiddleware(ctx, config) {
|
|
|
865
876
|
}
|
|
866
877
|
__name(registerRbqMiddleware, "registerRbqMiddleware");
|
|
867
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
|
+
|
|
868
903
|
// src/index.ts
|
|
869
904
|
var name = "cocoyyy-console";
|
|
870
905
|
var Config = import_koishi9.Schema.object({
|
|
@@ -893,6 +928,8 @@ async function apply(ctx, config) {
|
|
|
893
928
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
894
929
|
if (config.function_config.rbq_flag)
|
|
895
930
|
registerRbqMiddleware(ctx, config?.rbq_config);
|
|
931
|
+
if (dev_mode)
|
|
932
|
+
registerTestCommands(ctx);
|
|
896
933
|
}
|
|
897
934
|
__name(apply, "apply");
|
|
898
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
3
|
"description": "for self using, function console",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8-beta.0",
|
|
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 };
|