koishi-plugin-sy-bot 0.0.15 → 0.1.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/function/cronTask.d.ts +5 -0
- package/lib/function/everydayShare.d.ts +1 -0
- package/lib/index.d.ts +12 -1
- package/lib/index.js +121 -15
- package/lib/utils/utils.d.ts +2 -1
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function everyDayShare(obj: any): Promise<void>;
|
package/lib/index.d.ts
CHANGED
|
@@ -8,8 +8,19 @@ export interface Config {
|
|
|
8
8
|
api: string;
|
|
9
9
|
model: string;
|
|
10
10
|
prompt: string;
|
|
11
|
-
guild:
|
|
11
|
+
guild: number;
|
|
12
12
|
user: string;
|
|
13
|
+
dailyShares: Array<object>;
|
|
14
|
+
tasks: Task[];
|
|
15
|
+
}
|
|
16
|
+
export interface Task {
|
|
17
|
+
startTime: string;
|
|
18
|
+
endTime: string;
|
|
19
|
+
beforeTip: string;
|
|
20
|
+
afterTip: string;
|
|
21
|
+
lockName: string;
|
|
22
|
+
unlockName: string;
|
|
23
|
+
ifMute: boolean;
|
|
13
24
|
}
|
|
14
25
|
export declare const Config: Schema<Config>;
|
|
15
26
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -236,17 +236,17 @@ async function sendGroupMessageReaction(session, face_id, ifSet = true) {
|
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
__name(sendGroupMessageReaction, "sendGroupMessageReaction");
|
|
239
|
-
async function getAiChatResult({ config, user_query, ctx }) {
|
|
239
|
+
async function getAiChatResult({ config, user_query, ctx, system_prompt }) {
|
|
240
240
|
try {
|
|
241
241
|
const logger = ctx.logger("sy-bot");
|
|
242
|
-
const { model: MODEL, api: API_KEY, prompt:
|
|
242
|
+
const { model: MODEL, api: API_KEY, prompt: system_prompt2 } = config;
|
|
243
243
|
const { data } = await import_axios.default.post(
|
|
244
244
|
`https://api.qingyuntop.top/v1beta/models/${MODEL}?key=${API_KEY}`,
|
|
245
245
|
{
|
|
246
246
|
systemInstruction: {
|
|
247
247
|
parts: [
|
|
248
248
|
{
|
|
249
|
-
text:
|
|
249
|
+
text: system_prompt2
|
|
250
250
|
}
|
|
251
251
|
]
|
|
252
252
|
},
|
|
@@ -277,7 +277,7 @@ async function getAiChatResult({ config, user_query, ctx }) {
|
|
|
277
277
|
"过滤后的parts回复列表:\n",
|
|
278
278
|
data.candidates[0].content.parts.filter((part) => part.text)
|
|
279
279
|
);
|
|
280
|
-
const result = content.parts.filter((part) => part.text).map((part) => part.text).join("");
|
|
280
|
+
const result = content.parts.filter((part) => part.text && !part.thought).map((part) => part.text).join("");
|
|
281
281
|
logger.info("AI回复的文字:", result);
|
|
282
282
|
return result;
|
|
283
283
|
} catch (error) {
|
|
@@ -335,7 +335,7 @@ async function getAiImgUnderstandMultiple({
|
|
|
335
335
|
"过滤后的parts回复列表:\n",
|
|
336
336
|
data.candidates[0].content.parts.filter((part) => part.text)
|
|
337
337
|
);
|
|
338
|
-
const text = data.candidates[0].content.parts.filter((part) => part.text).map((p) => p.text).join("");
|
|
338
|
+
const text = data.candidates[0].content.parts.filter((part) => part.text && !part.thought).map((p) => p.text).join("");
|
|
339
339
|
logger.info("解析出的text:", text);
|
|
340
340
|
return text;
|
|
341
341
|
} catch (error) {
|
|
@@ -365,7 +365,8 @@ async function sendOnlyText({ session, ctx, config, query }) {
|
|
|
365
365
|
const raw_answer = await getAiChatResult({
|
|
366
366
|
config,
|
|
367
367
|
user_query: question,
|
|
368
|
-
ctx
|
|
368
|
+
ctx,
|
|
369
|
+
system_prompt: config.prompt
|
|
369
370
|
});
|
|
370
371
|
if (!raw_answer) {
|
|
371
372
|
return "AI没有回复";
|
|
@@ -515,11 +516,15 @@ __name(registerCountdown, "registerCountdown");
|
|
|
515
516
|
function registerResource(ctx, config) {
|
|
516
517
|
ctx.command("resource [index:number]", "获取26,27做题本/习题册/讲义pdf").action(async (_, index) => {
|
|
517
518
|
const resources = await ctx.database.get("resources");
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
519
|
+
try {
|
|
520
|
+
if (!index) {
|
|
521
|
+
const top = "-------- 资源合集 \n----------------\n";
|
|
522
|
+
return top + resources.map((res, idx) => `${idx + 1} 《${res.title}》`).join(" \n");
|
|
523
|
+
} else {
|
|
524
|
+
return resources[index - 1] ? resources[index - 1].content : "没有这个哦,喵";
|
|
525
|
+
}
|
|
526
|
+
} catch (error) {
|
|
527
|
+
return error.message;
|
|
523
528
|
}
|
|
524
529
|
});
|
|
525
530
|
}
|
|
@@ -560,7 +565,7 @@ function registerTip(ctx, config) {
|
|
|
560
565
|
const tips = await ctx.database.get("tips");
|
|
561
566
|
if (!index) {
|
|
562
567
|
const top = "-------- 经验贴合集 \n----------------\n";
|
|
563
|
-
return top + tips.map((tip, idx) => `${idx} 《${tip.title}》`).join(" \n");
|
|
568
|
+
return top + tips.map((tip, idx) => `${idx + 1} 《${tip.title}》`).join(" \n");
|
|
564
569
|
} else {
|
|
565
570
|
return tips[index - 1] ? tips[index - 1].url : "没有这个哦,喵";
|
|
566
571
|
}
|
|
@@ -610,22 +615,123 @@ function registerTables(ctx) {
|
|
|
610
615
|
}
|
|
611
616
|
__name(registerTables, "registerTables");
|
|
612
617
|
|
|
618
|
+
// src/function/everydayShare.tsx
|
|
619
|
+
async function everyDayShare(obj) {
|
|
620
|
+
const { ctx, bot, config } = obj;
|
|
621
|
+
config.dailyShares.forEach((share) => {
|
|
622
|
+
registerCronShare({
|
|
623
|
+
ctx,
|
|
624
|
+
bot,
|
|
625
|
+
config,
|
|
626
|
+
time: share.time,
|
|
627
|
+
user_query: share.question,
|
|
628
|
+
beforeTip: share.beforeTip,
|
|
629
|
+
system_prompt: share.system_prompt
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
__name(everyDayShare, "everyDayShare");
|
|
634
|
+
function registerCronShare(obj) {
|
|
635
|
+
const { ctx, bot, config, time, beforeTip, user_query, system_prompt } = obj;
|
|
636
|
+
ctx.cron(time, async () => {
|
|
637
|
+
const logger = ctx.logger;
|
|
638
|
+
beforeTip && await bot.sendMessage(config.guild, beforeTip);
|
|
639
|
+
const raw_answer = await getAiChatResult({
|
|
640
|
+
config,
|
|
641
|
+
user_query,
|
|
642
|
+
system_prompt,
|
|
643
|
+
ctx
|
|
644
|
+
});
|
|
645
|
+
if (!raw_answer) {
|
|
646
|
+
logger.info("AI没有回复");
|
|
647
|
+
}
|
|
648
|
+
try {
|
|
649
|
+
logger.info("开始渲染markdown...");
|
|
650
|
+
const h_ans_img = await textToImage(ctx, raw_answer);
|
|
651
|
+
logger.info("markdown渲染完毕!");
|
|
652
|
+
await bot.sendMessage(config.guild, h_ans_img);
|
|
653
|
+
} catch (err) {
|
|
654
|
+
return "调用 textToImage 报错:" + (err instanceof Error ? err.message : String(err));
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
__name(registerCronShare, "registerCronShare");
|
|
659
|
+
|
|
660
|
+
// src/function/cronTask.tsx
|
|
661
|
+
async function cronTask({ ctx, bot, config }) {
|
|
662
|
+
const logger = ctx.logger;
|
|
663
|
+
for (const task of config.tasks) {
|
|
664
|
+
const {
|
|
665
|
+
startTime,
|
|
666
|
+
endTime,
|
|
667
|
+
beforeTip,
|
|
668
|
+
afterTip,
|
|
669
|
+
lockName,
|
|
670
|
+
unlockName,
|
|
671
|
+
ifMute
|
|
672
|
+
} = task;
|
|
673
|
+
ctx.cron(startTime, async () => {
|
|
674
|
+
await bot.sendMessage(config.guild.toString(), beforeTip);
|
|
675
|
+
await bot.muteChannel(config.guild.toString(), ifMute);
|
|
676
|
+
await bot.internal.setGroupName(config.guild, lockName);
|
|
677
|
+
});
|
|
678
|
+
ctx.cron(endTime, async () => {
|
|
679
|
+
await bot.sendMessage(config.guild.toString(), afterTip);
|
|
680
|
+
await bot.muteChannel(config.guild.toString(), false);
|
|
681
|
+
await bot.internal.setGroupName(config.guild, unlockName);
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
__name(cronTask, "cronTask");
|
|
686
|
+
|
|
613
687
|
// src/index.ts
|
|
614
688
|
var name = "sy-bot";
|
|
615
689
|
var usage = "考研群答疑机器人";
|
|
616
690
|
var inject = {
|
|
617
|
-
required: ["database", "puppeteer"]
|
|
691
|
+
required: ["database", "puppeteer", "cron"]
|
|
618
692
|
};
|
|
619
693
|
var Config = import_koishi3.Schema.object({
|
|
620
694
|
api: import_koishi3.Schema.string().required().description("青云☁️ Gemini API(必填)"),
|
|
695
|
+
tasks: import_koishi3.Schema.array(
|
|
696
|
+
import_koishi3.Schema.object({
|
|
697
|
+
startTime: import_koishi3.Schema.string().default("0 0 23 * * *").description("开始 Cron"),
|
|
698
|
+
endTime: import_koishi3.Schema.string().default("0 0 7 * * *").description("结束 Cron"),
|
|
699
|
+
beforeTip: import_koishi3.Schema.string().description("开始公告").role("textarea"),
|
|
700
|
+
afterTip: import_koishi3.Schema.string().description("解放公告").role("textarea"),
|
|
701
|
+
lockName: import_koishi3.Schema.string().description("开始群名"),
|
|
702
|
+
unlockName: import_koishi3.Schema.string().description("解放群名"),
|
|
703
|
+
ifMute: import_koishi3.Schema.boolean().description("禁言")
|
|
704
|
+
})
|
|
705
|
+
).description("定时禁言任务列表"),
|
|
621
706
|
model: import_koishi3.Schema.string().required().description("模型名称(必填)"),
|
|
622
707
|
prompt: import_koishi3.Schema.string().description("预设系统提示词(可以留空)"),
|
|
623
|
-
guild: import_koishi3.Schema.
|
|
624
|
-
|
|
708
|
+
guild: import_koishi3.Schema.number().required().description(
|
|
709
|
+
"在目标群聊启用,留空表示广播所有群聊(填入QQ群号)"
|
|
710
|
+
),
|
|
711
|
+
user: import_koishi3.Schema.string().required().description("在目标用户启用(填入管理员QQ号)"),
|
|
712
|
+
dailyShares: import_koishi3.Schema.array(
|
|
713
|
+
import_koishi3.Schema.object({
|
|
714
|
+
time: import_koishi3.Schema.string().required().description(`时间字符串`),
|
|
715
|
+
question: import_koishi3.Schema.string().role("textarea", { rows: [2, 4] }).required().description(`提示词`),
|
|
716
|
+
beforeTip: import_koishi3.Schema.string().role("textarea", { rows: [2, 4] }).required().description(`发送前的提示语`),
|
|
717
|
+
system_prompt: import_koishi3.Schema.string().required().role("textarea", { rows: [2, 4] }).description(`系统提示词`)
|
|
718
|
+
})
|
|
719
|
+
)
|
|
625
720
|
});
|
|
626
721
|
function apply(ctx, config) {
|
|
722
|
+
const platform = `milky`;
|
|
723
|
+
const bot = ctx.bots.filter((bot2) => bot2.platform == platform)[0];
|
|
724
|
+
ctx.on("ready", () => {
|
|
725
|
+
ctx.bots.forEach((bot2) => {
|
|
726
|
+
ctx.logger.info("milky_bot:", bot2.platform);
|
|
727
|
+
ctx.logger.info("milky_bot:", bot2.selfId);
|
|
728
|
+
ctx.logger.info("milky_bot 加载成功!");
|
|
729
|
+
});
|
|
730
|
+
});
|
|
627
731
|
registerCommand(ctx, config);
|
|
628
732
|
registerTables(ctx);
|
|
733
|
+
cronTask({ ctx, bot, config });
|
|
734
|
+
everyDayShare({ ctx, bot, config });
|
|
629
735
|
}
|
|
630
736
|
__name(apply, "apply");
|
|
631
737
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -7,10 +7,11 @@ import { Context, h, Session } from "koishi";
|
|
|
7
7
|
export declare function getKaoyanCountdownText(targetTime: any): string;
|
|
8
8
|
export declare function getPrompt(): void;
|
|
9
9
|
export declare function sendGroupMessageReaction(session: any, face_id: any, ifSet?: boolean): Promise<void>;
|
|
10
|
-
export declare function getAiChatResult({ config, user_query, ctx }: {
|
|
10
|
+
export declare function getAiChatResult({ config, user_query, ctx, system_prompt }: {
|
|
11
11
|
config: any;
|
|
12
12
|
user_query: any;
|
|
13
13
|
ctx: any;
|
|
14
|
+
system_prompt: any;
|
|
14
15
|
}): Promise<any>;
|
|
15
16
|
export declare function imageUrlToBase64(ctx: Context, url: string): Promise<string>;
|
|
16
17
|
export declare function getAiImgUnderstandMultiple({ ctx, config, url_list, query, }: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-sy-bot",
|
|
3
3
|
"description": "考研群答疑Bot,接入Gemini。",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@satorijs/element": "^3.1.8",
|
|
29
29
|
"@vscode/markdown-it-katex": "^1.1.2",
|
|
30
30
|
"axios": "^1.13.2",
|
|
31
|
+
"corn": "^0.0.1",
|
|
31
32
|
"highlight": "^0.2.4",
|
|
32
33
|
"highlight.js": "^11.11.1",
|
|
33
34
|
"markdown-it": "^14.1.0",
|