alemonjs 2.1.79 → 2.1.80

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.
@@ -96,29 +96,41 @@ const finishCurrentTrace = (reason) => {
96
96
  const getTargetEvent = (event) => {
97
97
  return event ?? eventStore.getStore()?.event;
98
98
  };
99
+ const setSendAttempted = (target) => {
100
+ target._sendAttempted = true;
101
+ target._has_send_attempt = true;
102
+ };
103
+ const setSendSucceeded = (target) => {
104
+ target._sendSucceeded = true;
105
+ target._has_send_success = true;
106
+ };
107
+ const setLastSendError = (target, error) => {
108
+ target._lastSendError = error;
109
+ target._last_send_error = error;
110
+ };
99
111
  const markEventSendAttempt = (event) => {
100
112
  const target = getTargetEvent(event);
101
113
  if (!target) {
102
114
  return;
103
115
  }
104
- target._has_send_attempt = true;
116
+ setSendAttempted(target);
105
117
  };
106
118
  const markEventSendSuccess = (event) => {
107
119
  const target = getTargetEvent(event);
108
120
  if (!target) {
109
121
  return;
110
122
  }
111
- target._has_send_attempt = true;
112
- target._has_send_success = true;
113
- target._last_send_error = null;
123
+ setSendAttempted(target);
124
+ setSendSucceeded(target);
125
+ setLastSendError(target, null);
114
126
  };
115
127
  const markEventSendFailure = (error, event) => {
116
128
  const target = getTargetEvent(event);
117
129
  if (!target) {
118
130
  return;
119
131
  }
120
- target._has_send_attempt = true;
121
- target._last_send_error = error instanceof Error ? error.message : typeof error === 'string' ? error : 'Unknown send error';
132
+ setSendAttempted(target);
133
+ setLastSendError(target, error instanceof Error ? error.message : typeof error === 'string' ? error : 'Unknown send error');
122
134
  };
123
135
  const recordEventSendResults = (results, event) => {
124
136
  markEventSendAttempt(event);
@@ -12,6 +12,7 @@ export * from './permission';
12
12
  export * from './reaction';
13
13
  export * from './request';
14
14
  export * from './role';
15
+ export * from './route';
15
16
  export * from './user';
16
17
  export * from './subscribe';
17
18
  export * from './event';
@@ -12,6 +12,7 @@ export { usePermission } from './permission.js';
12
12
  export { useReaction } from './reaction.js';
13
13
  export { useRequest } from './request.js';
14
14
  export { useRole } from './role.js';
15
+ export { useRoute } from './route.js';
15
16
  export { useUser } from './user.js';
16
17
  export { useObserver, useSubscribe } from './subscribe.js';
17
18
  export { createEvent, useEvent } from './event.js';
@@ -0,0 +1,32 @@
1
+ import type { EventKeys, Events } from '../../types';
2
+ import type { RouteParams } from '../router/types';
3
+ import type { RouteSchemaValue } from '../router/validator';
4
+ type RouteReader = {
5
+ param: (name: string) => RouteSchemaValue | undefined;
6
+ hasParam: (name: string) => boolean;
7
+ };
8
+ export type UseRouteUnmatched = RouteReader & {
9
+ matched: false;
10
+ key: undefined;
11
+ text: undefined;
12
+ sourceText: undefined;
13
+ rewrittenText: undefined;
14
+ rawArgs: [];
15
+ parsedArgs: [];
16
+ params: {
17
+ [key: string]: any;
18
+ };
19
+ };
20
+ export type UseRouteMatched = RouteReader & {
21
+ matched: true;
22
+ key: string;
23
+ text: string;
24
+ sourceText?: string;
25
+ rewrittenText: string;
26
+ rawArgs: string[];
27
+ parsedArgs: RouteSchemaValue[];
28
+ params: RouteParams;
29
+ };
30
+ export type UseRouteResult = UseRouteUnmatched | UseRouteMatched;
31
+ export declare const useRoute: <T extends EventKeys>(event?: Events[T]) => readonly [UseRouteResult];
32
+ export {};
@@ -0,0 +1,39 @@
1
+ import { getEventOrThrow } from './common.js';
2
+
3
+ const createRouteReader = (params) => ({
4
+ param: (name) => params[name],
5
+ hasParam: (name) => Object.prototype.hasOwnProperty.call(params, name) && params[name] !== undefined
6
+ });
7
+ const createEmptyRoute = () => ({
8
+ matched: false,
9
+ key: undefined,
10
+ text: undefined,
11
+ sourceText: undefined,
12
+ rewrittenText: undefined,
13
+ rawArgs: [],
14
+ parsedArgs: [],
15
+ params: {},
16
+ ...createRouteReader({})
17
+ });
18
+ const useRoute = (event) => {
19
+ const currentEvent = getEventOrThrow(event);
20
+ const route = currentEvent.__route;
21
+ if (!route) {
22
+ return [createEmptyRoute()];
23
+ }
24
+ return [
25
+ {
26
+ matched: true,
27
+ key: route.key,
28
+ text: route.text,
29
+ sourceText: route.sourceText,
30
+ rewrittenText: route.rewrittenText ?? route.text,
31
+ rawArgs: [...route.rawArgs],
32
+ parsedArgs: [...route.parsedArgs],
33
+ params: { ...route.params },
34
+ ...createRouteReader(route.params)
35
+ }
36
+ ];
37
+ };
38
+
39
+ export { useRoute };
package/lib/app/index.js CHANGED
@@ -30,6 +30,7 @@ export { usePermission } from './hook-use/permission.js';
30
30
  export { useReaction } from './hook-use/reaction.js';
31
31
  export { useRequest } from './hook-use/request.js';
32
32
  export { useRole } from './hook-use/role.js';
33
+ export { useRoute } from './hook-use/route.js';
33
34
  export { useUser } from './hook-use/user.js';
34
35
  export { useObserver, useSubscribe } from './hook-use/subscribe.js';
35
36
  export { createEvent, useEvent } from './hook-use/event.js';
@@ -545,6 +545,8 @@ class Router {
545
545
  attachRouteContext(event, {
546
546
  key: match.route.config.path,
547
547
  text: match.normalizedCommand,
548
+ sourceText: typeof event.MessageText === 'string' ? event.MessageText : undefined,
549
+ rewrittenText: match.normalizedCommand,
548
550
  rawArgs: match.rawArgs,
549
551
  parsedArgs: [],
550
552
  params: {}
@@ -570,6 +572,8 @@ class Router {
570
572
  attachRouteContext(event, {
571
573
  key: match.route.config.path,
572
574
  text: match.normalizedCommand,
575
+ sourceText: initialMessageText,
576
+ rewrittenText: match.normalizedCommand,
573
577
  rawArgs: match.rawArgs,
574
578
  parsedArgs: match.parsedArgs,
575
579
  params
@@ -606,6 +610,8 @@ class Router {
606
610
  attachRouteContext(event, {
607
611
  key: '',
608
612
  text: scopedText,
613
+ sourceText: typeof event.MessageText === 'string' ? event.MessageText : undefined,
614
+ rewrittenText: scopedText,
609
615
  rawArgs: [],
610
616
  parsedArgs: [],
611
617
  params: {}
@@ -3,6 +3,8 @@ export type RouteParams = Record<string, RouteSchemaValue | undefined>;
3
3
  export type RouteContext = {
4
4
  key: string;
5
5
  text: string;
6
+ sourceText?: string;
7
+ rewrittenText?: string;
6
8
  rawArgs: string[];
7
9
  parsedArgs: RouteSchemaValue[];
8
10
  params: RouteParams;
package/lib/index.js CHANGED
@@ -37,6 +37,7 @@ export { usePermission } from './app/hook-use/permission.js';
37
37
  export { useReaction } from './app/hook-use/reaction.js';
38
38
  export { useRequest } from './app/hook-use/request.js';
39
39
  export { useRole } from './app/hook-use/role.js';
40
+ export { useRoute } from './app/hook-use/route.js';
40
41
  export { useUser } from './app/hook-use/user.js';
41
42
  export { useObserver, useSubscribe } from './app/hook-use/subscribe.js';
42
43
  export { createEvent, useEvent } from './app/hook-use/event.js';
@@ -1,8 +1,11 @@
1
1
  export type Expansion = {
2
2
  IsAtMe?: boolean;
3
3
  IsPrivate?: boolean;
4
+ _sendAttempted?: boolean;
4
5
  _has_send_attempt?: boolean;
6
+ _sendSucceeded?: boolean;
5
7
  _has_send_success?: boolean;
8
+ _lastSendError?: string | null;
6
9
  _last_send_error?: string | null;
7
10
  [key: string]: any;
8
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.79",
3
+ "version": "2.1.80",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -34,7 +34,6 @@
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",
38
37
  "koa": "^3.0.1",
39
38
  "koa-router": "^14.0.0",
40
39
  "koa-static": "^5.0.0",
@@ -44,6 +43,7 @@
44
43
  "qrcode": "^1.5.4",
45
44
  "uuid": "11.1.0",
46
45
  "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": "7dab16a2167bbdf5706931b67e7eab2fc67835d6"
75
- }
74
+ "gitHead": "c6aa5616afe091a37610dad22fbb2d2618d943b8"
75
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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.