alemonjs 2.1.77 → 2.1.79
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/LICENSE +21 -0
- package/lib/app/event-processor.js +6 -4
- package/lib/app/hook-event-context.d.ts +5 -0
- package/lib/app/hook-event-context.js +39 -1
- package/lib/app/hook-use/common.d.ts +2 -2
- package/lib/app/hook-use/common.js +1 -1
- package/lib/app/hook-use/message.js +20 -10
- package/lib/app/index.js +1 -1
- package/lib/app/message-api.js +36 -17
- package/lib/app/router/validator.js +2 -1
- package/lib/index.js +1 -1
- package/lib/types/event/base/expansion.d.ts +5 -0
- package/lib/types/event/base/platform.d.ts +2 -0
- package/package.json +4 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-present, Yuxi (Evan) You
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIdED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -112,18 +112,18 @@ const onProcessor = (name, event, data) => {
|
|
|
112
112
|
const masterId = value?.master_id;
|
|
113
113
|
const masterKey = value?.master_key;
|
|
114
114
|
if (event['UserId'] && matchIn(masterId, event['UserId'])) {
|
|
115
|
-
event['
|
|
115
|
+
event['IsMaster'] = true;
|
|
116
116
|
}
|
|
117
117
|
else if (event['UserKey'] && matchIn(masterKey, event['UserKey'])) {
|
|
118
|
-
event['
|
|
118
|
+
event['IsMaster'] = true;
|
|
119
119
|
}
|
|
120
120
|
const botId = value?.bot_id;
|
|
121
121
|
const botKey = value?.bot_key;
|
|
122
122
|
if (event['UserId'] && matchIn(botId, event['UserId'])) {
|
|
123
|
-
event['
|
|
123
|
+
event['IsBot'] = true;
|
|
124
124
|
}
|
|
125
125
|
else if (event['UserKey'] && matchIn(botKey, event['UserKey'])) {
|
|
126
|
-
event['
|
|
126
|
+
event['IsBot'] = true;
|
|
127
127
|
}
|
|
128
128
|
const Now = Date.now();
|
|
129
129
|
const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? processorRepeatedEventTime;
|
|
@@ -146,6 +146,8 @@ const onProcessor = (name, event, data) => {
|
|
|
146
146
|
event['value'] = data;
|
|
147
147
|
}
|
|
148
148
|
event['name'] = name;
|
|
149
|
+
event['IsPrivate'] = event['IsPrivate'] ?? name.startsWith('private.');
|
|
150
|
+
event['IsAtMe'] = event['IsAtMe'] ?? false;
|
|
149
151
|
expendCycle(event, name, value);
|
|
150
152
|
}
|
|
151
153
|
catch (error) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Result } from '../core';
|
|
1
2
|
import { EventKeys, Events } from '../types';
|
|
2
3
|
export type EventTraceReason = 'filtered' | 'completed' | 'consumed' | 'error';
|
|
3
4
|
export declare const withEventContext: <T extends EventKeys, R>(event: Events[T], next: (...args: boolean[]) => void, runner: () => R) => R;
|
|
@@ -5,3 +6,7 @@ export declare const withProcessorTrace: <T extends EventKeys, R>(select: T, eve
|
|
|
5
6
|
export declare const getCurrentEvent: <T extends EventKeys>() => Events[T] | undefined;
|
|
6
7
|
export declare const getCurrentNext: () => ((...args: boolean[]) => void) | undefined;
|
|
7
8
|
export declare const finishCurrentTrace: (reason: EventTraceReason) => void;
|
|
9
|
+
export declare const markEventSendAttempt: <T extends EventKeys>(event?: Events[T]) => void;
|
|
10
|
+
export declare const markEventSendSuccess: <T extends EventKeys>(event?: Events[T]) => void;
|
|
11
|
+
export declare const markEventSendFailure: <T extends EventKeys>(error: unknown, event?: Events[T]) => void;
|
|
12
|
+
export declare const recordEventSendResults: <T extends EventKeys>(results: Result[], event?: Events[T]) => void;
|
|
@@ -93,5 +93,43 @@ const getCurrentNext = () => {
|
|
|
93
93
|
const finishCurrentTrace = (reason) => {
|
|
94
94
|
eventStore.getStore()?.trace?.finish(reason);
|
|
95
95
|
};
|
|
96
|
+
const getTargetEvent = (event) => {
|
|
97
|
+
return event ?? eventStore.getStore()?.event;
|
|
98
|
+
};
|
|
99
|
+
const markEventSendAttempt = (event) => {
|
|
100
|
+
const target = getTargetEvent(event);
|
|
101
|
+
if (!target) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
target._has_send_attempt = true;
|
|
105
|
+
};
|
|
106
|
+
const markEventSendSuccess = (event) => {
|
|
107
|
+
const target = getTargetEvent(event);
|
|
108
|
+
if (!target) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
target._has_send_attempt = true;
|
|
112
|
+
target._has_send_success = true;
|
|
113
|
+
target._last_send_error = null;
|
|
114
|
+
};
|
|
115
|
+
const markEventSendFailure = (error, event) => {
|
|
116
|
+
const target = getTargetEvent(event);
|
|
117
|
+
if (!target) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
target._has_send_attempt = true;
|
|
121
|
+
target._last_send_error = error instanceof Error ? error.message : typeof error === 'string' ? error : 'Unknown send error';
|
|
122
|
+
};
|
|
123
|
+
const recordEventSendResults = (results, event) => {
|
|
124
|
+
markEventSendAttempt(event);
|
|
125
|
+
if (Array.isArray(results) && results.some(item => item?.code === ResultCode.Ok)) {
|
|
126
|
+
markEventSendSuccess(event);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const firstError = Array.isArray(results) ? results.find(item => item?.code !== ResultCode.Ok)?.message : null;
|
|
130
|
+
if (firstError) {
|
|
131
|
+
markEventSendFailure(firstError, event);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
96
134
|
|
|
97
|
-
export { finishCurrentTrace, getCurrentEvent, getCurrentNext, withEventContext, withProcessorTrace };
|
|
135
|
+
export { finishCurrentTrace, getCurrentEvent, getCurrentNext, markEventSendAttempt, markEventSendFailure, markEventSendSuccess, recordEventSendResults, withEventContext, withProcessorTrace };
|
|
@@ -5,9 +5,9 @@ import { createResult, Result } from '../../core/utils';
|
|
|
5
5
|
import { sendAction } from '../../cbp/processor/actions';
|
|
6
6
|
import { sendAPI } from '../../cbp/processor/api';
|
|
7
7
|
import { Format } from '../message-format';
|
|
8
|
-
import { getCurrentEvent, getCurrentNext } from '../hook-event-context';
|
|
8
|
+
import { getCurrentEvent, getCurrentNext, recordEventSendResults, markEventSendAttempt, markEventSendFailure } from '../hook-event-context';
|
|
9
9
|
export type { DataEnums, EventKeys, Events, User, GuildInfo, ChannelInfo, MemberInfo, RoleInfo, PaginationParams, PaginatedResult, Result };
|
|
10
|
-
export { ResultCode, ChildrenApp, createResult, sendAction, sendAPI, Format, getCurrentEvent, getCurrentNext };
|
|
10
|
+
export { ResultCode, ChildrenApp, createResult, sendAction, sendAPI, Format, getCurrentEvent, getCurrentNext, recordEventSendResults, markEventSendAttempt, markEventSendFailure };
|
|
11
11
|
export type Options = {
|
|
12
12
|
UserId?: string;
|
|
13
13
|
UserKey?: string;
|
|
@@ -5,7 +5,7 @@ export { sendAction } from '../../cbp/processor/actions.js';
|
|
|
5
5
|
export { sendAPI } from '../../cbp/processor/api.js';
|
|
6
6
|
export { Format } from '../message-format.js';
|
|
7
7
|
import { getCurrentEvent } from '../hook-event-context.js';
|
|
8
|
-
export { getCurrentNext } from '../hook-event-context.js';
|
|
8
|
+
export { getCurrentNext, markEventSendAttempt, markEventSendFailure, recordEventSendResults } from '../hook-event-context.js';
|
|
9
9
|
|
|
10
10
|
const getEventOrThrow = (event) => {
|
|
11
11
|
const currentEvent = event ?? getCurrentEvent();
|
|
@@ -3,6 +3,7 @@ import { createResult } from '../../core/utils.js';
|
|
|
3
3
|
import { ResultCode } from '../../core/variable.js';
|
|
4
4
|
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
5
|
import { Format } from '../message-format.js';
|
|
6
|
+
import { markEventSendAttempt, recordEventSendResults, markEventSendFailure } from '../hook-event-context.js';
|
|
6
7
|
|
|
7
8
|
const useMessage = (event) => {
|
|
8
9
|
const valueEvent = getEventOrThrow(event);
|
|
@@ -16,17 +17,26 @@ const useMessage = (event) => {
|
|
|
16
17
|
if (!val || val.length === 0) {
|
|
17
18
|
return [createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)];
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
markEventSendAttempt(valueEvent);
|
|
21
|
+
try {
|
|
22
|
+
const result = await sendAction({
|
|
23
|
+
action: 'message.send',
|
|
24
|
+
payload: {
|
|
25
|
+
event: valueEvent,
|
|
26
|
+
params: {
|
|
27
|
+
format: val,
|
|
28
|
+
replyId
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
});
|
|
32
|
+
const results = Array.isArray(result) ? result : [result];
|
|
33
|
+
recordEventSendResults(results, valueEvent);
|
|
34
|
+
return results;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
markEventSendFailure(error, valueEvent);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
30
40
|
};
|
|
31
41
|
const lightweight = {
|
|
32
42
|
send(params) {
|
package/lib/app/index.js
CHANGED
|
@@ -34,7 +34,7 @@ export { useUser } from './hook-use/user.js';
|
|
|
34
34
|
export { useObserver, useSubscribe } from './hook-use/subscribe.js';
|
|
35
35
|
export { createEvent, useEvent } from './hook-use/event.js';
|
|
36
36
|
export { clearInterval, clearTimeout, listSchedule, pauseSchedule, resumeSchedule, setCron, setInterval, setTimeout } from './api/schedule.js';
|
|
37
|
-
export { finishCurrentTrace, getCurrentEvent, getCurrentNext, withEventContext, withProcessorTrace } from './hook-event-context.js';
|
|
37
|
+
export { finishCurrentTrace, getCurrentEvent, getCurrentNext, markEventSendAttempt, markEventSendFailure, markEventSendSuccess, recordEventSendResults, withEventContext, withProcessorTrace } from './hook-event-context.js';
|
|
38
38
|
export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './schedule-store.js';
|
|
39
39
|
export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './event-utils.js';
|
|
40
40
|
export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
|
package/lib/app/message-api.js
CHANGED
|
@@ -4,6 +4,7 @@ import 'fs';
|
|
|
4
4
|
import 'path';
|
|
5
5
|
import 'yaml';
|
|
6
6
|
import { createResult } from '../core/utils.js';
|
|
7
|
+
import { markEventSendAttempt, recordEventSendResults, markEventSendFailure } from './hook-event-context.js';
|
|
7
8
|
|
|
8
9
|
const format = (...data) => {
|
|
9
10
|
if (!data || data.length === 0) {
|
|
@@ -31,16 +32,25 @@ class MessageDirect {
|
|
|
31
32
|
});
|
|
32
33
|
throw new Error('Invalid SpaceId: SpaceId must be a string');
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
markEventSendAttempt();
|
|
36
|
+
try {
|
|
37
|
+
const results = await sendAction({
|
|
38
|
+
action: 'message.send.channel',
|
|
39
|
+
payload: {
|
|
40
|
+
ChannelId: params.SpaceId,
|
|
41
|
+
params: {
|
|
42
|
+
format: Array.isArray(params.format) ? params.format : params.format.value,
|
|
43
|
+
replyId: params?.replyId
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
46
|
+
});
|
|
47
|
+
recordEventSendResults(results, undefined);
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
markEventSendFailure(error);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
55
|
async sendToUser(params) {
|
|
46
56
|
if (!params.OpenID || typeof params.OpenID !== 'string') {
|
|
@@ -51,15 +61,24 @@ class MessageDirect {
|
|
|
51
61
|
});
|
|
52
62
|
throw new Error('Invalid OpenID: OpenID must be a string');
|
|
53
63
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
markEventSendAttempt();
|
|
65
|
+
try {
|
|
66
|
+
const results = await sendAction({
|
|
67
|
+
action: 'message.send.user',
|
|
68
|
+
payload: {
|
|
69
|
+
UserId: params.OpenID,
|
|
70
|
+
params: {
|
|
71
|
+
format: Array.isArray(params.format) ? params.format : params.format.value
|
|
72
|
+
}
|
|
60
73
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
74
|
+
});
|
|
75
|
+
recordEventSendResults(results, undefined);
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
markEventSendFailure(error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
84
|
const sendToChannel = (SpaceId, data) => {
|
|
@@ -254,7 +254,8 @@ function validateRouteArgsForCommand(commandPath, rawArgs, schema) {
|
|
|
254
254
|
const missingRequiredArg = getMissingRequiredArg(rawArgs, schema);
|
|
255
255
|
return {
|
|
256
256
|
valid: false,
|
|
257
|
-
error: schema?.messages?.tooFewArgs ??
|
|
257
|
+
error: schema?.messages?.tooFewArgs ??
|
|
258
|
+
(missingRequiredArg ? `${formatArgReference(missingRequiredArg.arg.name, missingRequiredArg.displayIndex)}是必填的` : `至少需要 ${minArgs} 个参数`),
|
|
258
259
|
usage
|
|
259
260
|
};
|
|
260
261
|
}
|
package/lib/index.js
CHANGED
|
@@ -41,7 +41,7 @@ export { useUser } from './app/hook-use/user.js';
|
|
|
41
41
|
export { useObserver, useSubscribe } from './app/hook-use/subscribe.js';
|
|
42
42
|
export { createEvent, useEvent } from './app/hook-use/event.js';
|
|
43
43
|
export { clearInterval, clearTimeout, listSchedule, pauseSchedule, resumeSchedule, setCron, setInterval, setTimeout } from './app/api/schedule.js';
|
|
44
|
-
export { finishCurrentTrace, getCurrentEvent, getCurrentNext, withEventContext, withProcessorTrace } from './app/hook-event-context.js';
|
|
44
|
+
export { finishCurrentTrace, getCurrentEvent, getCurrentNext, markEventSendAttempt, markEventSendFailure, markEventSendSuccess, recordEventSendResults, withEventContext, withProcessorTrace } from './app/hook-event-context.js';
|
|
45
45
|
export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './app/schedule-store.js';
|
|
46
46
|
export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './app/event-utils.js';
|
|
47
47
|
export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.79",
|
|
4
4
|
"description": "bot script",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"cron": "^4.4.0",
|
|
35
35
|
"file-type": "21.0.0",
|
|
36
36
|
"flatted": "^3.3.3",
|
|
37
|
+
"https-proxy-agent": "^9.0.0",
|
|
37
38
|
"koa": "^3.0.1",
|
|
38
39
|
"koa-router": "^14.0.0",
|
|
39
40
|
"koa-static": "^5.0.0",
|
|
@@ -43,7 +44,6 @@
|
|
|
43
44
|
"qrcode": "^1.5.4",
|
|
44
45
|
"uuid": "11.1.0",
|
|
45
46
|
"ws": "^8.18.0",
|
|
46
|
-
"https-proxy-agent": "^9.0.0",
|
|
47
47
|
"yaml": "^2.5.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"type": "git",
|
|
72
72
|
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
-
}
|
|
74
|
+
"gitHead": "7dab16a2167bbdf5706931b67e7eab2fc67835d6"
|
|
75
|
+
}
|