node-karin 0.10.0 → 0.10.2

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 (129) hide show
  1. package/config/defSet/group.yaml +40 -2
  2. package/lib/adapter/onebot/11/index.js +1 -1
  3. package/lib/cli/init.js +1 -1
  4. package/lib/cli/karin.js +1 -1
  5. package/lib/core/index.d.ts +9 -9
  6. package/lib/core/index.js +9 -9
  7. package/lib/core/init/dir.js +7 -0
  8. package/lib/core/init/init.js +46 -0
  9. package/lib/core/{karin.d.ts → karin/karin.d.ts} +1 -1
  10. package/lib/core/karin/karin.js +194 -0
  11. package/lib/core/{listener.d.ts → listener/listener.d.ts} +1 -1
  12. package/lib/core/listener/listener.js +213 -0
  13. package/lib/core/{plugin.app.d.ts → plugin/app.d.ts} +1 -1
  14. package/lib/core/plugin/app.js +19 -0
  15. package/lib/core/{plugin.d.ts → plugin/base.d.ts} +1 -1
  16. package/lib/core/plugin/base.js +140 -0
  17. package/lib/core/{plugin.loader.d.ts → plugin/loader.d.ts} +3 -3
  18. package/lib/core/plugin/loader.js +579 -0
  19. package/lib/core/process/process.js +100 -0
  20. package/lib/core/server/server.js +283 -0
  21. package/lib/db/index.d.ts +2 -2
  22. package/lib/db/index.js +2 -2
  23. package/lib/db/level/level.js +36 -0
  24. package/lib/db/redis/redis.js +135 -0
  25. package/lib/db/redis/redis_level.js +287 -0
  26. package/lib/event/{event.handler.d.ts → handler/base.d.ts} +2 -2
  27. package/lib/event/handler/base.js +173 -0
  28. package/lib/event/{message.handler.d.ts → handler/message.d.ts} +3 -3
  29. package/lib/event/handler/message.js +270 -0
  30. package/lib/event/{notice.handler.d.ts → handler/notice.d.ts} +3 -3
  31. package/lib/event/handler/notice.js +212 -0
  32. package/lib/event/{request.handler.d.ts → handler/request.d.ts} +3 -3
  33. package/lib/event/handler/request.js +118 -0
  34. package/lib/event/{review.handler.d.ts → handler/review.d.ts} +3 -3
  35. package/lib/event/handler/review.js +391 -0
  36. package/lib/event/index.d.ts +5 -5
  37. package/lib/event/index.js +5 -5
  38. package/lib/render/base.d.ts +1 -1
  39. package/lib/render/client.d.ts +1 -1
  40. package/lib/render/client.js +2 -12
  41. package/lib/render/client_even.d.ts +1 -1
  42. package/lib/render/client_even.js +2 -12
  43. package/lib/render/http.d.ts +1 -1
  44. package/lib/render/http.js +1 -1
  45. package/lib/render/server.js +1 -1
  46. package/lib/types/adapter/{adapter.d.ts → base.d.ts} +2 -2
  47. package/lib/types/config/config.js +1 -0
  48. package/lib/types/element/element.js +1 -0
  49. package/lib/types/event/message.d.ts +1 -1
  50. package/lib/types/event/reply.d.ts +1 -1
  51. package/lib/types/index.d.ts +6 -6
  52. package/lib/types/index.js +6 -6
  53. package/lib/types/logger/logger.js +1 -0
  54. package/lib/types/{plugin.d.ts → plugin/plugin.d.ts} +3 -3
  55. package/lib/types/plugin/plugin.js +1 -0
  56. package/lib/types/render/render.js +1 -0
  57. package/lib/utils/{common.d.ts → common/common.d.ts} +1 -1
  58. package/lib/utils/common/common.js +591 -0
  59. package/lib/utils/{config.d.ts → config/config.d.ts} +37 -19
  60. package/lib/utils/config/config.js +328 -0
  61. package/lib/utils/config/updateVersion.js +145 -0
  62. package/lib/utils/config/yamlEditor.js +292 -0
  63. package/lib/utils/{handler.d.ts → core/handler.d.ts} +1 -1
  64. package/lib/utils/core/handler.js +115 -0
  65. package/lib/utils/core/init.js +213 -0
  66. package/lib/utils/core/logger.js +105 -0
  67. package/lib/utils/{segment.d.ts → core/segment.d.ts} +1 -1
  68. package/lib/utils/core/segment.js +441 -0
  69. package/lib/utils/index.d.ts +11 -11
  70. package/lib/utils/index.js +11 -11
  71. package/lib/utils/{button.d.ts → tools/button.d.ts} +1 -1
  72. package/lib/utils/tools/button.js +38 -0
  73. package/lib/utils/tools/exec.js +37 -0
  74. package/lib/utils/tools/ffmpeg.js +25 -0
  75. package/lib/utils/tools/update.js +139 -0
  76. package/package.json +1 -1
  77. package/lib/core/dir.js +0 -7
  78. package/lib/core/init.js +0 -42
  79. package/lib/core/karin.js +0 -194
  80. package/lib/core/listener.js +0 -217
  81. package/lib/core/plugin.app.js +0 -19
  82. package/lib/core/plugin.js +0 -145
  83. package/lib/core/plugin.loader.js +0 -561
  84. package/lib/core/process.js +0 -98
  85. package/lib/core/server.js +0 -269
  86. package/lib/db/level.js +0 -37
  87. package/lib/db/redis.js +0 -134
  88. package/lib/db/redis_level.js +0 -293
  89. package/lib/event/event.handler.js +0 -167
  90. package/lib/event/message.handler.js +0 -254
  91. package/lib/event/notice.handler.js +0 -204
  92. package/lib/event/request.handler.js +0 -110
  93. package/lib/event/review.handler.js +0 -387
  94. package/lib/types/config.js +0 -1
  95. package/lib/types/element.js +0 -1
  96. package/lib/types/logger.js +0 -1
  97. package/lib/types/plugin.js +0 -1
  98. package/lib/types/render.js +0 -1
  99. package/lib/utils/button.js +0 -34
  100. package/lib/utils/common.js +0 -572
  101. package/lib/utils/config.js +0 -318
  102. package/lib/utils/exec.js +0 -36
  103. package/lib/utils/ffmpeg.js +0 -25
  104. package/lib/utils/handler.js +0 -109
  105. package/lib/utils/init.js +0 -208
  106. package/lib/utils/logger.js +0 -104
  107. package/lib/utils/segment.js +0 -470
  108. package/lib/utils/update.js +0 -135
  109. package/lib/utils/updateVersion.js +0 -145
  110. package/lib/utils/yamlEditor.js +0 -279
  111. /package/lib/core/{dir.d.ts → init/dir.d.ts} +0 -0
  112. /package/lib/core/{init.d.ts → init/init.d.ts} +0 -0
  113. /package/lib/core/{process.d.ts → process/process.d.ts} +0 -0
  114. /package/lib/core/{server.d.ts → server/server.d.ts} +0 -0
  115. /package/lib/db/{level.d.ts → level/level.d.ts} +0 -0
  116. /package/lib/db/{redis.d.ts → redis/redis.d.ts} +0 -0
  117. /package/lib/db/{redis_level.d.ts → redis/redis_level.d.ts} +0 -0
  118. /package/lib/types/adapter/{adapter.js → base.js} +0 -0
  119. /package/lib/types/{config.d.ts → config/config.d.ts} +0 -0
  120. /package/lib/types/{element.d.ts → element/element.d.ts} +0 -0
  121. /package/lib/types/{logger.d.ts → logger/logger.d.ts} +0 -0
  122. /package/lib/types/{render.d.ts → render/render.d.ts} +0 -0
  123. /package/lib/utils/{updateVersion.d.ts → config/updateVersion.d.ts} +0 -0
  124. /package/lib/utils/{yamlEditor.d.ts → config/yamlEditor.d.ts} +0 -0
  125. /package/lib/utils/{init.d.ts → core/init.d.ts} +0 -0
  126. /package/lib/utils/{logger.d.ts → core/logger.d.ts} +0 -0
  127. /package/lib/utils/{exec.d.ts → tools/exec.d.ts} +0 -0
  128. /package/lib/utils/{ffmpeg.d.ts → tools/ffmpeg.d.ts} +0 -0
  129. /package/lib/utils/{update.d.ts → tools/update.d.ts} +0 -0
@@ -0,0 +1,140 @@
1
+ /**
2
+ * 插件基类
3
+ */
4
+ export class Plugin {
5
+ /**
6
+ * @param name - 插件名称
7
+ */
8
+ name;
9
+ /**
10
+ * @param dsc - 插件描述
11
+ * @deprecated 请使用desc
12
+ */
13
+ dsc;
14
+ /**
15
+ * @param desc - 插件描述
16
+ */
17
+ desc;
18
+ /**
19
+ * @param event - 监听事件
20
+ */
21
+ event;
22
+ /**
23
+ * @param priority - 优先级 默认10000
24
+ */
25
+ priority;
26
+ /**
27
+ * @param task - 定时任务
28
+ */
29
+ task;
30
+ /**
31
+ * @param rule - 命令规则
32
+ */
33
+ rule;
34
+ /**
35
+ * @param button - 按钮
36
+ */
37
+ button;
38
+ /**
39
+ * @param handler - handler
40
+ */
41
+ handler;
42
+ /**
43
+ * @param userId - 用户ID 一般上下文使用
44
+ */
45
+ userId;
46
+ /**
47
+ * @param timeout - 上下文超时
48
+ */
49
+ timeout;
50
+ constructor({ name, dsc = name, desc = name, event = "message" /* EventType.Message */, priority = 10000, task = [], rule = [], handler = [], button = [], }) {
51
+ this.name = name;
52
+ this.dsc = dsc;
53
+ this.desc = desc;
54
+ this.event = event;
55
+ this.priority = priority;
56
+ this.task = task;
57
+ this.rule = rule;
58
+ this.button = button;
59
+ this.handler = handler;
60
+ }
61
+ /**
62
+ * - 快速回复
63
+ */
64
+ reply(msg = '', options = { reply: false, recallMsg: 0, at: false, button: false, retry_count: 1 }) {
65
+ return this.e.reply(msg, options);
66
+ }
67
+ /**
68
+ * - 快速回复合并转发
69
+ */
70
+ async replyForward(msg) {
71
+ const result = await this.e.bot.sendForwardMessage(this.e.contact, msg);
72
+ return result;
73
+ }
74
+ /**
75
+ * - 构建上下文键
76
+ */
77
+ conKey() {
78
+ return `${this.e.isGroup ? `${this.e.group_id}.` : ''}` + (this.userId || this.e.user_id);
79
+ }
80
+ /**
81
+ * 设置上下文状态
82
+ */
83
+ setContext(
84
+ /**
85
+ * @param fnc - 执行方法
86
+ */
87
+ fnc,
88
+ /**
89
+ * @param reply - 超时后是否回复
90
+ */
91
+ reply = true,
92
+ /**
93
+ * @param time - 超时时间,默认120秒
94
+ */
95
+ time = 120) {
96
+ const key = this.conKey();
97
+ if (typeof fnc === 'string') {
98
+ stateArr[key] = { type: 'class', fnc: this, name: fnc };
99
+ }
100
+ else {
101
+ stateArr[key] = { type: 'fnc', fnc };
102
+ }
103
+ /** 操作时间 */
104
+ this.timeout = setTimeout(() => {
105
+ if (stateArr[key]) {
106
+ delete stateArr[key];
107
+ if (reply)
108
+ this.e.reply('操作超时已取消', { at: true });
109
+ }
110
+ }, time * 1000);
111
+ }
112
+ /**
113
+ * 获取上下文状态
114
+ */
115
+ getContext() {
116
+ const key = this.conKey();
117
+ return stateArr[key];
118
+ }
119
+ /**
120
+ * 清除上下文状态
121
+ */
122
+ finish() {
123
+ const key = this.conKey();
124
+ if (stateArr[key] && stateArr[key]) {
125
+ /** 清除定时器 */
126
+ clearTimeout(this.timeout);
127
+ delete stateArr[key];
128
+ }
129
+ }
130
+ e;
131
+ replyCallback;
132
+ }
133
+ /**
134
+ * 上下文状态
135
+ */
136
+ export const stateArr = {};
137
+ /**
138
+ * @description 即将废弃,请使用 `Plugin`
139
+ */
140
+ export const plugin = Plugin;
@@ -1,7 +1,7 @@
1
1
  import chokidar from 'chokidar';
2
2
  import schedule from 'node-schedule';
3
- import { Plugin } from './plugin.js';
4
- import { PluginApps, PluginTask, dirName, fileName, AppInfo, NewMessagePlugin } from '../types/index.js';
3
+ import { Plugin } from './base.js';
4
+ import { PluginApps, PluginTask, dirName, fileName, AppInfo, NewMessagePlugin } from '../../types/index.js';
5
5
  declare class PluginLoader {
6
6
  dir: './plugins';
7
7
  dirPath: string;
@@ -103,7 +103,7 @@ declare class PluginLoader {
103
103
  */
104
104
  getApps(dir: dirName, isTs: boolean, isWatch?: boolean): void;
105
105
  /**
106
- * 排序并打印插件加兹安信息
106
+ * 排序并打印插件信息
107
107
  * @param isPrint - 是否打印
108
108
  */
109
109
  orderBy(isPrint?: boolean): void;