alemonjs 1.1.19 → 1.1.20

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/README.md CHANGED
@@ -1,21 +1,90 @@
1
- ☞[English document](./README_English.md)
1
+ ## 阿柠檬跨平台开发框架
2
2
 
3
- ## 阿柠檬跨平台开发框架机器人
3
+ alemonjs 是消息正则匹配的跨平台开发框架,支持 QQ 群、QQ 频道、KOOK、Discord、米游社大别野等平台,只需要一套代码即可快速构建机器人。
4
4
 
5
- 开发文档 OPEN[https://alemonjs.com](https://alemonjs.com)
5
+ 我们提供了热开发和打包编译工具,除此,也能自行混淆压缩来提高机器人响应速度
6
6
 
7
- 类型/接口 OPEN[docs](https://ningmengchongshui.github.io/alemon/)
7
+ [开发文档 https://alemonjs.com](https://alemonjs.com)
8
8
 
9
- 开发模板 GITEE[create-alemonjs](https://gitee.com/ningmengchongshui/alemon/tree/cli/bin)
9
+ ### 快速开始
10
10
 
11
- 开发模板 GITHUB[create-alemonjs](https://github.com/ningmengchongshui/alemon/tree/cli/bin)
11
+ 可直接执行脚手架 并快速启动程序
12
12
 
13
- 共享平台 OPEN[sharing platform](https://gitee.com/ningmengchongshui/alemon/tree/web/docs/.vitepress/components/data)
13
+ ```sh
14
+ npm init alemonjs@latest -y
15
+ cd alemonb
16
+ npm install
17
+ npm run dev
18
+ ```
14
19
 
15
- ## 开源协议
20
+ 连接平台需要正确配置登录
16
21
 
17
- GNU GPL 是使用最广泛的自由软件许可证,并有强烈的版权要求
22
+ `a.login.config.ts`
18
23
 
19
- 分发衍生作品时,作品的源代码必须在同一许可证下可用
24
+ ```ts
25
+ import { LoginMap } from 'alemonjs'
26
+ export const login: LoginMap = {
27
+ // 配置名
28
+ test: {
29
+ // 平台名 qq discord ntqq qq villa
30
+ qq: {
31
+ // ... 配置信息
32
+ // ...详细请看
33
+ // alemonjs.com
34
+ }
35
+ }
36
+ }
37
+ ```
20
38
 
21
- GNUGPL 有多种变体,每个变体都有不同的要求
39
+ > npm run [脚本名] [配置名] [平台名]
40
+
41
+ 启动时带上匹配规则机器人正确启动
42
+
43
+ ```sh
44
+ npm run dev test qq
45
+ ```
46
+
47
+ ### 开发示例
48
+
49
+ 启动开发模式后会以`apps`作为应用目录
50
+
51
+ ```ts
52
+ // apps/word.ts
53
+ import { APlugin, AMessage } from 'alemonjs'
54
+ // 导出应用 PluginName
55
+ export class PluginName extends APlugin {
56
+ constructor() {
57
+ super({
58
+ dsc: '插件描述', // 描述,可有可无
59
+ rule: [
60
+ {
61
+ reg: /你好/, // 响应消息 你好
62
+ fnc: 'post' // 执行函数 post
63
+ }
64
+ ]
65
+ })
66
+ }
67
+ // 定义函数 post
68
+ async post(e: AMessage) {
69
+ // 事件.回复("你好呀")
70
+ e.reply('你好呀')
71
+ // 直接返回 null | undefined | false
72
+ // 不再进行后续的正则匹配
73
+ return
74
+ }
75
+ }
76
+ ```
77
+
78
+ 每当文件有修改或进行保存时就会自动刷新应用
79
+
80
+ 当确认该应用可用于生成环境时,可进行打包操作
81
+
82
+ ```sh
83
+ npm run build
84
+ ```
85
+
86
+ > 注意,请确保内容修改都是在 npm run dev 下进行
87
+
88
+ 打包完成后,会生成`dist/main.js`和`package.json`文件
89
+
90
+ 该程序可放置于`plugins/your plugin name`文件夹下
package/lib/core/apps.js CHANGED
@@ -2,6 +2,7 @@ import { dirname, basename } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
  import { setAppMessage, setAppArg, setAppCharacter, setAppEvent, setAppPriority } from './cache.js';
4
4
  import { setApp } from './app.js';
5
+ import { setAllCall } from './call.js';
5
6
  /**
6
7
  * 应用路径
7
8
  * @param url
@@ -242,6 +243,22 @@ export function createApp(url) {
242
243
  }
243
244
  return app;
244
245
  },
246
+ /**
247
+ * 比正则系统更优先的回调系统
248
+ * 且无视所有event设置
249
+ * @param event 事件
250
+ * @param call 回调
251
+ * @param priority 优先级
252
+ */
253
+ on: (event, call, priority = 9000) => {
254
+ try {
255
+ setAllCall(event, call, priority);
256
+ }
257
+ catch (err) {
258
+ console.error('APP on', err);
259
+ }
260
+ return app;
261
+ },
245
262
  /**
246
263
  * 挂起应用
247
264
  * @returns
@@ -0,0 +1,44 @@
1
+ import lodash from 'lodash';
2
+ const CALL = {
3
+ AUDIO_FREQUENCY: [],
4
+ AUDIO_MICROPHONE: [],
5
+ CHANNEL: [],
6
+ FORUMS_POST: [],
7
+ FORUMS_REPLY: [],
8
+ FORUMS_THREAD: [],
9
+ GUILD: [],
10
+ GUILD_BOT: [],
11
+ GUILD_MEMBERS: [],
12
+ GUILD_MESSAGE_REACTIONS: [],
13
+ INTERACTION: [],
14
+ MESSAGES: [],
15
+ message: []
16
+ };
17
+ /**
18
+ * 排序回调
19
+ */
20
+ export function orderByAppCall() {
21
+ // 排序
22
+ for (const val in CALL) {
23
+ CALL[val] = lodash.orderBy(CALL[val], ['priority'], ['asc']);
24
+ }
25
+ }
26
+ /**
27
+ * 得到回调
28
+ * @returns
29
+ */
30
+ export function getAppCall(event) {
31
+ return CALL[event];
32
+ }
33
+ /**
34
+ * 设置回调
35
+ * @param event
36
+ * @param call
37
+ * @param priority
38
+ */
39
+ export function setAllCall(event, call, priority = 9000) {
40
+ CALL[event].push({
41
+ call,
42
+ priority
43
+ });
44
+ }
@@ -7,6 +7,7 @@ import { getApp, delApp, getAppKey } from './app.js';
7
7
  import { EventEnum } from './typings.js';
8
8
  import { conversationHandlers, getConversationState } from './dialogue.js';
9
9
  import { getAppProCoinfg } from './configs.js';
10
+ import { getAppCall, orderByAppCall } from './call.js';
10
11
  const Command = {};
11
12
  const CommandNotMessage = {};
12
13
  const CommandApp = {};
@@ -244,6 +245,18 @@ function dataInit() {
244
245
  * 插件初始化
245
246
  */
246
247
  export async function appsInit() {
248
+ /**
249
+ * *********
250
+ * 回调系统
251
+ * ********
252
+ */
253
+ // 排序
254
+ orderByAppCall();
255
+ /**
256
+ * ************
257
+ * 正则系统
258
+ * ************
259
+ */
247
260
  // 清空当前的apps
248
261
  dataInit();
249
262
  // 得到所有插件名
@@ -309,6 +322,43 @@ export async function InstructionMatching(e) {
309
322
  await handler(e, state);
310
323
  return true;
311
324
  }
325
+ let t = false;
326
+ /**
327
+ * 回调系统
328
+ */
329
+ for (const app of getAppCall('MESSAGES')) {
330
+ if (t === true)
331
+ break;
332
+ try {
333
+ // app.call
334
+ const back = await app.call(e);
335
+ if (back === true) {
336
+ t = back;
337
+ }
338
+ }
339
+ catch (err) {
340
+ console.error(`[${e.event}]`, `[${app.call}]`, `[${false}]\n`, `[${err}]`);
341
+ continue;
342
+ }
343
+ }
344
+ /**
345
+ * 回调系统
346
+ */
347
+ for (const app of getAppCall('message')) {
348
+ if (t === true)
349
+ break;
350
+ try {
351
+ // app.call
352
+ const back = await app.call(e);
353
+ if (back === true) {
354
+ t = back;
355
+ }
356
+ }
357
+ catch (err) {
358
+ console.error(`[${e.event}]`, `[${app.call}]`, `[${false}]\n`, `[${err}]`);
359
+ continue;
360
+ }
361
+ }
312
362
  const APPCACHE = {};
313
363
  const ARGCACHE = {};
314
364
  /**
@@ -414,6 +464,22 @@ export async function typeMessage(e) {
414
464
  console.info('e', e);
415
465
  if (!CommandNotMessage[e.event])
416
466
  return true;
467
+ /**
468
+ * 回调系统
469
+ */
470
+ const event = getAppCall(e.event);
471
+ for (const app of event) {
472
+ try {
473
+ // app.call
474
+ const back = await app.call(e);
475
+ if (back === true)
476
+ break;
477
+ }
478
+ catch (err) {
479
+ console.error(`[${e.event}]`, `[${app.call}]`, `[${false}]\n`, `[${err}]`);
480
+ continue;
481
+ }
482
+ }
417
483
  const APPCACHE = {};
418
484
  const ARGCACHE = {};
419
485
  for (const item in CommandApp) {
@@ -67,6 +67,7 @@ export const EventEnum = [
67
67
  'MESSAGES',
68
68
  /**
69
69
  * 消息
70
+ * @deprecated MESSAGES
70
71
  */
71
72
  'message',
72
73
  /**
@@ -44,8 +44,8 @@ export const DIRECT_MESSAGE = async (event) => {
44
44
  at: false,
45
45
  at_users: [],
46
46
  at_user: undefined,
47
- msg: event.content,
48
- msg_txt: event.content,
47
+ msg: event?.extra?.kmarkdown?.raw_content ?? event.content,
48
+ msg_txt: event?.extra?.kmarkdown?.raw_content ?? event.content,
49
49
  msg_id: event.msg_id,
50
50
  open_id: open_id,
51
51
  //
@@ -19,7 +19,7 @@ export const PUBLIC_GUILD_MESSAGES_KOOK = async (event) => {
19
19
  console.info('event', event);
20
20
  let at = false;
21
21
  const at_users = [];
22
- let msg = event.content;
22
+ let msg = event?.extra?.kmarkdown?.raw_content ?? event.content;
23
23
  /**
24
24
  * 艾特类型所得到的
25
25
  * 包括机器人在内
@@ -90,7 +90,7 @@ export const PUBLIC_GUILD_MESSAGES_KOOK = async (event) => {
90
90
  at_users,
91
91
  at_user,
92
92
  msg,
93
- msg_txt: event.content,
93
+ msg_txt: event?.extra?.kmarkdown?.raw_content ?? event.content,
94
94
  msg_id: event.msg_id,
95
95
  open_id: data?.code ?? '', // 私聊标记 空的 需要创建私聊 每次请求都自动创建
96
96
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "description": "DOCS https://alemonjs.com/",
5
5
  "scripts": {
6
6
  "dev": "ts-node alemon.config.ts",
@@ -1,3 +1,4 @@
1
+ import { AMessage, EventEnum } from './typings.js';
1
2
  /**
2
3
  * 应用路径
3
4
  * @param url
@@ -73,6 +74,14 @@ export declare function createApps(url: string): {
73
74
  * @param app 应用对象
74
75
  */
75
76
  use: (urlObject?: object) => any;
77
+ /**
78
+ * 比正则系统更优先的回调系统
79
+ * 且无视所有event设置
80
+ * @param event 事件
81
+ * @param call 回调
82
+ * @param priority 优先级
83
+ */
84
+ on: (event: "message" | "GUILD_MEMBERS" | "GUILD_MESSAGE_REACTIONS" | "MESSAGE_AUDIT" | "INTERACTION" | "GUILD" | "GUILD_BOT" | "CHANNEL" | "FORUMS_THREAD" | "FORUMS_POST" | "FORUMS_REPLY" | "MESSAGES" | "MESSAGE_BUTTON" | "AUDIO_FREQUENCY" | "AUDIO_MICROPHONE", call: (e: AMessage) => any, priority?: number) => any;
76
85
  /**
77
86
  * 挂起应用
78
87
  * @returns
@@ -132,6 +141,14 @@ export declare function createApp(url: string): {
132
141
  * @param app 应用对象
133
142
  */
134
143
  use: (urlObject?: object) => any;
144
+ /**
145
+ * 比正则系统更优先的回调系统
146
+ * 且无视所有event设置
147
+ * @param event 事件
148
+ * @param call 回调
149
+ * @param priority 优先级
150
+ */
151
+ on: (event: (typeof EventEnum)[number], call: (e: AMessage) => any, priority?: number) => any;
135
152
  /**
136
153
  * 挂起应用
137
154
  * @returns
@@ -0,0 +1,20 @@
1
+ import { AMessage, EventEnum } from './typings.js';
2
+ /**
3
+ * 排序回调
4
+ */
5
+ export declare function orderByAppCall(): void;
6
+ /**
7
+ * 得到回调
8
+ * @returns
9
+ */
10
+ export declare function getAppCall(event: (typeof EventEnum)[number]): {
11
+ priority: number;
12
+ call: (e: AMessage) => any;
13
+ }[];
14
+ /**
15
+ * 设置回调
16
+ * @param event
17
+ * @param call
18
+ * @param priority
19
+ */
20
+ export declare function setAllCall(event: (typeof EventEnum)[number], call: (e: AMessage) => any, priority?: number): void;