koishi-plugin-cocoyyy-console 1.0.3 → 1.0.5

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.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Context, Logger, Schema } from 'koishi';
2
2
  import * as my_config from './utils/config';
3
3
  export declare const name = "cocoyyy-console";
4
+ export declare const inject: string[];
4
5
  export interface Config {
5
6
  function_config?: my_config.FunctionConfig;
6
7
  mysql_config?: my_config.MysqlConfig;
package/lib/index.js CHANGED
@@ -22,6 +22,7 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  Config: () => Config,
24
24
  apply: () => apply,
25
+ inject: () => inject,
25
26
  logger: () => logger,
26
27
  name: () => name,
27
28
  savePath: () => savePath
@@ -344,6 +345,16 @@ var tagFuncMenuList = [
344
345
  description: "标签取消别名",
345
346
  command: "unbind [标签] [别名]"
346
347
  },
348
+ {
349
+ name: "addstart",
350
+ description: "开始给标签批量添加图片",
351
+ command: "addstart [标签]"
352
+ },
353
+ {
354
+ name: "addend",
355
+ description: "结束给标签批量添加图片",
356
+ command: "addend"
357
+ },
347
358
  {
348
359
  name: "taglist",
349
360
  description: "获取标签列表",
@@ -469,6 +480,46 @@ async function getImgCountByTag(tag_id) {
469
480
  return count;
470
481
  }
471
482
  __name(getImgCountByTag, "getImgCountByTag");
483
+ async function startBatchAddImg(ctx, tag_name, session, savePath2) {
484
+ try {
485
+ const guild_id = session.guildId;
486
+ let tag = await getTag(tag_name, guild_id);
487
+ if (tag == null) {
488
+ throw new Error(`not found tag '${tag_name}'!`);
489
+ }
490
+ if (tag.get("status") !== 0) {
491
+ logger.info(`[startBatchAddImg Info]:tag '${tag_name}' is deleted`);
492
+ throw new Error(`tag '${tag_name}' is deleted!`);
493
+ }
494
+ if (savePath2 == null) {
495
+ throw new Error("saving path config wrong!");
496
+ }
497
+ if (uid_tag_map.has(session.userId)) {
498
+ throw new Error("already started");
499
+ }
500
+ let key = session.guildId + "_" + session.userId;
501
+ uid_tag_map.set(key, tag_name);
502
+ return { result: true, error: null };
503
+ } catch (e) {
504
+ logger.error("[startBatchAddImg Error]: " + e?.message || String(e));
505
+ return { result: false, error: e?.message || String(e) };
506
+ }
507
+ }
508
+ __name(startBatchAddImg, "startBatchAddImg");
509
+ async function endBatchAddImg(ctx, session) {
510
+ try {
511
+ let key = session.guildId + "_" + session.userId;
512
+ if (!uid_tag_map.has(key)) {
513
+ throw new Error("not start recording");
514
+ }
515
+ uid_tag_map.delete(key);
516
+ return { result: true, error: null };
517
+ } catch (e) {
518
+ logger.error("[startBatchAddImg Error]: " + e?.message || String(e));
519
+ return { result: false, error: e?.message || String(e) };
520
+ }
521
+ }
522
+ __name(endBatchAddImg, "endBatchAddImg");
472
523
 
473
524
  // src/services/tag_func/tag_service.ts
474
525
  async function findTagByName(tag_name, guild_id) {
@@ -618,6 +669,7 @@ __name(getTagList, "getTagList");
618
669
 
619
670
  // src/services/tag_func/tag_commands.ts
620
671
  var import_url = require("url");
672
+ var uid_tag_map = /* @__PURE__ */ new Map();
621
673
  function registerTagCommands(ctx, connected, savePath2) {
622
674
  ctx.command("maketag <参数>", "创建一个标签").check(({ session }) => {
623
675
  if (!connected) return;
@@ -678,16 +730,48 @@ function registerTagCommands(ctx, connected, savePath2) {
678
730
  return `取消绑定失败:${exec.error}`;
679
731
  return `取消绑定成功`;
680
732
  });
681
- ctx.command("taglist", "获取标签列表").check(({ session }) => {
733
+ ctx.command("addstart <参数>", "开始给标签批量添加图片").check(({ session }) => {
682
734
  if (!connected) return;
683
735
  if (!is_at_bot(session)) return;
684
736
  }).action(async ({ session }, ...args) => {
737
+ const tag = args?.[0];
738
+ if (!tag) return "请提供正确格式,如:@bot addstart [标签]";
739
+ let exec = await startBatchAddImg(ctx, tag, session, savePath2);
740
+ if (!exec.result)
741
+ return exec.error;
742
+ return "[开始记录图片]";
743
+ });
744
+ ctx.command("addend", "结束给标签批量添加图片").check(({ session }) => {
745
+ if (!connected) return;
746
+ if (!is_at_bot(session)) return;
747
+ }).action(async ({ session }) => {
748
+ let exec = await endBatchAddImg(ctx, session);
749
+ if (!exec.result)
750
+ return exec.error;
751
+ return "[停止记录图片]";
752
+ });
753
+ ctx.command("taglist", "获取标签列表").check(({ session }) => {
754
+ if (!connected) return;
755
+ if (!is_at_bot(session)) return;
756
+ }).action(async ({ session }) => {
685
757
  let exec = await getTagList(session.guildId);
686
758
  if (exec == null)
687
759
  return `查询失败`;
688
760
  return `查询成功!
689
761
  ${exec.map((item) => "标签:" + item.tag + " 黑历史数:" + item.count + "\n别名:" + (item.alias ? item.alias : "无")).join("\n\n")}`;
690
762
  });
763
+ ctx.middleware(async (session, next) => {
764
+ let key = session.guildId + "_" + session.userId;
765
+ if (!uid_tag_map.has(key)) return await next();
766
+ const tag = uid_tag_map.get(key);
767
+ const img = session.content;
768
+ const srcMatch = img.match(/src="([^"]+)"/);
769
+ if (!srcMatch) return "请给出图片,如需停止记录图片,请输入@bot addend [标签]";
770
+ let exec = await saveImg(ctx, tag, session.guildId, img, savePath2);
771
+ if (!exec.result)
772
+ return `保存失败:${exec.error}`;
773
+ return "保存成功";
774
+ });
691
775
  }
692
776
  __name(registerTagCommands, "registerTagCommands");
693
777
 
@@ -784,6 +868,7 @@ __name(registerRbqMiddleware, "registerRbqMiddleware");
784
868
 
785
869
  // src/index.ts
786
870
  var name = "cocoyyy-console";
871
+ var inject = ["sequelize", "mysql2"];
787
872
  var Config = import_koishi9.Schema.object({
788
873
  function_config: FunctionConfigSchema.description("功能开关配置"),
789
874
  mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
@@ -816,6 +901,7 @@ __name(apply, "apply");
816
901
  0 && (module.exports = {
817
902
  Config,
818
903
  apply,
904
+ inject,
819
905
  logger,
820
906
  name,
821
907
  savePath
@@ -1,8 +1,16 @@
1
- import { Context } from "koishi";
1
+ import { Context, Session } from "koishi";
2
2
  declare function saveImg(ctx: Context, tag_name: string, guild_id: string, imgurl: string, savePath: string): Promise<{
3
3
  result: boolean;
4
4
  error: string | null;
5
5
  }>;
6
6
  declare function randomImgByTag(tag_name: string, guild_id: string): Promise<string | null>;
7
7
  declare function getImgCountByTag(tag_id: number): Promise<number>;
8
- export { saveImg, randomImgByTag, getImgCountByTag };
8
+ declare function startBatchAddImg(ctx: Context, tag_name: string, session: Session, savePath: string): Promise<{
9
+ result: boolean;
10
+ error: string | null;
11
+ }>;
12
+ declare function endBatchAddImg(ctx: Context, session: Session): Promise<{
13
+ result: boolean;
14
+ error: string | null;
15
+ }>;
16
+ export { saveImg, randomImgByTag, getImgCountByTag, startBatchAddImg, endBatchAddImg };
@@ -1,3 +1,4 @@
1
1
  import { Context } from 'koishi';
2
+ declare let uid_tag_map: Map<string, string>;
2
3
  declare function registerTagCommands(ctx: Context, connected: boolean, savePath: string | null): void;
3
- export { registerTagCommands };
4
+ export { uid_tag_map, registerTagCommands };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cocoyyy-console",
3
3
  "description": "for self using, function console",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [