@abyss-project/reflex 6.3.0 → 6.6.0
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/.prettierrc +5 -5
- package/dist/api/function-run.api.d.ts +3 -1
- package/dist/api/function-run.api.js +5 -1
- package/dist/api/function-run.api.js.map +1 -1
- package/dist/api/function-settings.api.d.ts +3 -1
- package/dist/api/function-settings.api.js +7 -1
- package/dist/api/function-settings.api.js.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/storage-surplus.admin.api.d.ts +5 -0
- package/dist/api/storage-surplus.admin.api.js +17 -0
- package/dist/api/storage-surplus.admin.api.js.map +1 -0
- package/dist/discord/discord-command-tree.d.ts +5 -0
- package/dist/discord/discord-command-tree.js +38 -0
- package/dist/discord/discord-command-tree.js.map +1 -0
- package/dist/discord/discord-event-filter-cases.js +27 -11
- package/dist/discord/discord-event-filter-cases.js.map +1 -1
- package/dist/discord/discord-event-filters.js +7 -3
- package/dist/discord/discord-event-filters.js.map +1 -1
- package/dist/discord/discord-event-intents.d.ts +8 -2
- package/dist/discord/discord-event-intents.js +13 -2
- package/dist/discord/discord-event-intents.js.map +1 -1
- package/dist/discord/index.d.ts +1 -0
- package/dist/discord/index.js +1 -0
- package/dist/discord/index.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/types/enum/discord-command-node-type.enum.d.ts +5 -0
- package/dist/types/enum/discord-command-node-type.enum.js +10 -0
- package/dist/types/enum/discord-command-node-type.enum.js.map +1 -0
- package/dist/types/enum/discord-command-type.enum.d.ts +5 -0
- package/dist/types/enum/discord-command-type.enum.js +10 -0
- package/dist/types/enum/discord-command-type.enum.js.map +1 -0
- package/dist/types/enum/discord-event-type.enum.d.ts +3 -1
- package/dist/types/enum/discord-event-type.enum.js +2 -0
- package/dist/types/enum/discord-event-type.enum.js.map +1 -1
- package/dist/types/enum/index.d.ts +2 -0
- package/dist/types/enum/index.js +2 -0
- package/dist/types/enum/index.js.map +1 -1
- package/dist/types/enum/reflex-error-code.enum.d.ts +14 -1
- package/dist/types/enum/reflex-error-code.enum.js +13 -0
- package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
- package/dist/types/interface/api/requests/application-run-settings.request.d.ts +1 -0
- package/dist/types/interface/api/requests/function-run.request.d.ts +16 -0
- package/dist/types/interface/api/requests/function-settings.request.d.ts +12 -0
- package/dist/types/interface/api/requests/index.d.ts +1 -0
- package/dist/types/interface/api/requests/index.js +1 -0
- package/dist/types/interface/api/requests/index.js.map +1 -1
- package/dist/types/interface/api/requests/service-discord.request.d.ts +7 -3
- package/dist/types/interface/api/requests/service.request.d.ts +1 -0
- package/dist/types/interface/api/requests/storage-surplus.admin.request.d.ts +8 -0
- package/dist/types/interface/api/requests/storage-surplus.admin.request.js +3 -0
- package/dist/types/interface/api/requests/storage-surplus.admin.request.js.map +1 -0
- package/dist/types/interface/api/responses/function-run.response.d.ts +12 -0
- package/dist/types/interface/api/responses/function-settings.response.d.ts +5 -1
- package/dist/types/interface/api/responses/index.d.ts +1 -0
- package/dist/types/interface/api/responses/index.js +1 -0
- package/dist/types/interface/api/responses/index.js.map +1 -1
- package/dist/types/interface/api/responses/storage-surplus.admin.response.d.ts +8 -0
- package/dist/types/interface/api/responses/storage-surplus.admin.response.js +3 -0
- package/dist/types/interface/api/responses/storage-surplus.admin.response.js.map +1 -0
- package/dist/types/interface/models/index.d.ts +2 -0
- package/dist/types/interface/models/index.js +2 -0
- package/dist/types/interface/models/index.js.map +1 -1
- package/dist/types/interface/models/reflex-discord.model.d.ts +18 -2
- package/dist/types/interface/models/reflex-discord.model.js +4 -0
- package/dist/types/interface/models/reflex-discord.model.js.map +1 -1
- package/dist/types/interface/models/reflex-run-retention.model.d.ts +13 -0
- package/dist/types/interface/models/reflex-run-retention.model.js +8 -0
- package/dist/types/interface/models/reflex-run-retention.model.js.map +1 -0
- package/dist/types/interface/models/reflex-run-settings.model.d.ts +4 -0
- package/dist/types/interface/models/reflex-run.model.d.ts +9 -0
- package/dist/types/interface/models/reflex-run.model.js +4 -1
- package/dist/types/interface/models/reflex-run.model.js.map +1 -1
- package/dist/types/interface/models/reflex-service-deployment.model.d.ts +2 -2
- package/dist/types/interface/models/reflex-service.model.d.ts +1 -0
- package/dist/types/interface/models/reflex-storage-surplus.model.d.ts +11 -0
- package/dist/types/interface/models/reflex-storage-surplus.model.js +3 -0
- package/dist/types/interface/models/reflex-storage-surplus.model.js.map +1 -0
- package/package.json +1 -1
- package/src/api/application-run-settings.api.test.ts +62 -51
- package/src/api/function-run.api.ts +34 -0
- package/src/api/function-settings.api.ts +96 -74
- package/src/api/function.api.test.ts +346 -291
- package/src/api/index.ts +27 -26
- package/src/api/service.api.test.ts +220 -215
- package/src/api/storage-surplus.admin.api.test.ts +66 -0
- package/src/api/storage-surplus.admin.api.ts +45 -0
- package/src/discord/discord-command-tree.test.ts +47 -0
- package/src/discord/discord-command-tree.ts +60 -0
- package/src/discord/discord-event-filter-cases.ts +54 -16
- package/src/discord/discord-event-filters.test.ts +33 -4
- package/src/discord/discord-event-filters.ts +13 -5
- package/src/discord/discord-event-intents.test.ts +27 -0
- package/src/discord/discord-event-intents.ts +31 -6
- package/src/discord/index.ts +1 -0
- package/src/index.ts +44 -0
- package/src/types/enum/discord-command-node-type.enum.ts +10 -0
- package/src/types/enum/discord-command-type.enum.ts +9 -0
- package/src/types/enum/discord-event-type.enum.ts +4 -0
- package/src/types/enum/index.ts +2 -0
- package/src/types/enum/reflex-error-code.enum.ts +112 -73
- package/src/types/interface/api/requests/application-run-settings.request.ts +13 -11
- package/src/types/interface/api/requests/function-run.request.ts +53 -32
- package/src/types/interface/api/requests/function-settings.request.ts +50 -34
- package/src/types/interface/api/requests/index.ts +25 -24
- package/src/types/interface/api/requests/service-discord.request.ts +19 -6
- package/src/types/interface/api/requests/service.request.ts +48 -46
- package/src/types/interface/api/requests/storage-surplus.admin.request.ts +12 -0
- package/src/types/interface/api/responses/function-run.response.ts +35 -18
- package/src/types/interface/api/responses/function-settings.response.ts +57 -50
- package/src/types/interface/api/responses/index.ts +25 -24
- package/src/types/interface/api/responses/storage-surplus.admin.response.ts +10 -0
- package/src/types/interface/models/index.ts +29 -27
- package/src/types/interface/models/reflex-discord.model.ts +45 -4
- package/src/types/interface/models/reflex-run-retention.model.ts +24 -0
- package/src/types/interface/models/reflex-run-settings.model.ts +39 -28
- package/src/types/interface/models/reflex-run.model.ts +317 -299
- package/src/types/interface/models/reflex-service-deployment.model.ts +48 -46
- package/src/types/interface/models/reflex-service.model.ts +47 -45
- package/src/types/interface/models/reflex-storage-surplus.model.ts +23 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IReflexDiscordCommand,
|
|
3
|
+
IReflexDiscordCommandTreeNode,
|
|
4
|
+
} from '../types/interface/models';
|
|
5
|
+
|
|
6
|
+
type TreeSource = Pick<IReflexDiscordCommand, 'id' | 'parentId' | 'name'>;
|
|
7
|
+
|
|
8
|
+
const byName = <T extends TreeSource>(
|
|
9
|
+
a: IReflexDiscordCommandTreeNode<T>,
|
|
10
|
+
b: IReflexDiscordCommandTreeNode<T>,
|
|
11
|
+
): number => (a.command.name < b.command.name ? -1 : a.command.name > b.command.name ? 1 : 0);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The commands of a Service as trees: each root (a node without parent) with its children, sorted by name at
|
|
15
|
+
* every level, as the registration sends them and the screens show them. A node whose parent is not in the
|
|
16
|
+
* list is left out: it cannot be placed.
|
|
17
|
+
*/
|
|
18
|
+
export const buildDiscordCommandTree = <T extends TreeSource>(
|
|
19
|
+
commands: readonly T[],
|
|
20
|
+
): IReflexDiscordCommandTreeNode<T>[] => {
|
|
21
|
+
const nodes = new Map<string, IReflexDiscordCommandTreeNode<T>>(
|
|
22
|
+
commands.map((command) => [command.id, { command, children: [] }]),
|
|
23
|
+
);
|
|
24
|
+
const roots: IReflexDiscordCommandTreeNode<T>[] = [];
|
|
25
|
+
for (const node of nodes.values()) {
|
|
26
|
+
if (node.command.parentId === null) {
|
|
27
|
+
roots.push(node);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
nodes.get(node.command.parentId)?.children.push(node);
|
|
31
|
+
}
|
|
32
|
+
const sort = (level: IReflexDiscordCommandTreeNode<T>[]): IReflexDiscordCommandTreeNode<T>[] => {
|
|
33
|
+
level.sort(byName);
|
|
34
|
+
level.forEach((node) => sort(node.children));
|
|
35
|
+
return level;
|
|
36
|
+
};
|
|
37
|
+
return sort(roots);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The names from the root down to the command, `['config', 'role', 'add']`: what a user types after the slash,
|
|
42
|
+
* and, joined by a space, the routing key of a leaf. Empty when an ancestor is missing from the list.
|
|
43
|
+
*/
|
|
44
|
+
export const discordCommandPathOf = <T extends TreeSource>(
|
|
45
|
+
command: T,
|
|
46
|
+
commands: readonly T[],
|
|
47
|
+
): string[] => {
|
|
48
|
+
const byId = new Map(commands.map((entry) => [entry.id, entry]));
|
|
49
|
+
const path = [command.name];
|
|
50
|
+
let parentId = command.parentId;
|
|
51
|
+
while (parentId !== null) {
|
|
52
|
+
const parent = byId.get(parentId);
|
|
53
|
+
if (parent === undefined || path.length > 3) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
path.unshift(parent.name);
|
|
57
|
+
parentId = parent.parentId;
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
60
|
+
};
|
|
@@ -19,19 +19,35 @@ export const FILTER_CASE_BOT_ID = 'bot-1';
|
|
|
19
19
|
const MEMBER_ID = 'user-1';
|
|
20
20
|
const OTHER_BOT_ID = 'bot-2';
|
|
21
21
|
|
|
22
|
+
const ALL_TYPES = Object.values(DiscordEventType);
|
|
23
|
+
const POLL_TYPES = [
|
|
24
|
+
DiscordEventType.MESSAGE_POLL_VOTE_ADD,
|
|
25
|
+
DiscordEventType.MESSAGE_POLL_VOTE_REMOVE,
|
|
26
|
+
];
|
|
27
|
+
const CHANNEL_TYPES = [
|
|
28
|
+
DiscordEventType.MESSAGE_CREATE,
|
|
29
|
+
DiscordEventType.MESSAGE_REACTION_ADD,
|
|
30
|
+
...POLL_TYPES,
|
|
31
|
+
];
|
|
32
|
+
const ROLE_TYPES = [
|
|
33
|
+
DiscordEventType.GUILD_MEMBER_ADD,
|
|
34
|
+
DiscordEventType.MESSAGE_CREATE,
|
|
35
|
+
DiscordEventType.MESSAGE_REACTION_ADD,
|
|
36
|
+
];
|
|
37
|
+
/** The types whose event says whether the actor is a bot: all but the poll votes. */
|
|
38
|
+
const BOT_FLAG_TYPES = ALL_TYPES.filter((type) => !POLL_TYPES.includes(type));
|
|
39
|
+
|
|
22
40
|
const subject = (
|
|
23
41
|
type: DiscordEventType,
|
|
24
42
|
overrides: Partial<IDiscordEventFilterSubject> = {},
|
|
25
43
|
): IDiscordEventFilterSubject => ({
|
|
26
44
|
type,
|
|
27
45
|
guildId: 'guild-1',
|
|
28
|
-
channelId:
|
|
29
|
-
type === DiscordEventType.MESSAGE_CREATE || type === DiscordEventType.MESSAGE_REACTION_ADD
|
|
30
|
-
? 'channel-1'
|
|
31
|
-
: null,
|
|
46
|
+
channelId: CHANNEL_TYPES.includes(type) ? 'channel-1' : null,
|
|
32
47
|
actorId: MEMBER_ID,
|
|
33
48
|
actorIsBot: false,
|
|
34
|
-
|
|
49
|
+
// A poll vote carries no member, so no role.
|
|
50
|
+
actorRoleIds: POLL_TYPES.includes(type) ? [] : ['role-1'],
|
|
35
51
|
content: type === DiscordEventType.MESSAGE_CREATE ? '!hello world' : null,
|
|
36
52
|
...overrides,
|
|
37
53
|
});
|
|
@@ -42,14 +58,6 @@ const rejected = (filter: DiscordEventFilterName): DiscordEventFilterVerdict =>
|
|
|
42
58
|
filter,
|
|
43
59
|
});
|
|
44
60
|
|
|
45
|
-
const ALL_TYPES = Object.values(DiscordEventType);
|
|
46
|
-
const CHANNEL_TYPES = [DiscordEventType.MESSAGE_CREATE, DiscordEventType.MESSAGE_REACTION_ADD];
|
|
47
|
-
const ROLE_TYPES = [
|
|
48
|
-
DiscordEventType.GUILD_MEMBER_ADD,
|
|
49
|
-
DiscordEventType.MESSAGE_CREATE,
|
|
50
|
-
DiscordEventType.MESSAGE_REACTION_ADD,
|
|
51
|
-
];
|
|
52
|
-
|
|
53
61
|
const build = (
|
|
54
62
|
name: string,
|
|
55
63
|
eventType: DiscordEventType,
|
|
@@ -94,6 +102,8 @@ export const DISCORD_EVENT_FILTER_CASES: IDiscordEventFilterCase[] = [
|
|
|
94
102
|
rejected(DiscordEventFilterName.GUILD_IDS),
|
|
95
103
|
),
|
|
96
104
|
build('empty guildIds is no filter', type, { guildIds: [] }, subject(type), kept),
|
|
105
|
+
]),
|
|
106
|
+
...typeCases(BOT_FLAG_TYPES, (type) => [
|
|
97
107
|
build(
|
|
98
108
|
'bot actor is ignored by default',
|
|
99
109
|
type,
|
|
@@ -145,12 +155,40 @@ export const DISCORD_EVENT_FILTER_CASES: IDiscordEventFilterCase[] = [
|
|
|
145
155
|
subject(type, { actorId: FILTER_CASE_BOT_ID, actorIsBot: true }),
|
|
146
156
|
kept,
|
|
147
157
|
),
|
|
158
|
+
]),
|
|
159
|
+
...typeCases(
|
|
160
|
+
CHANNEL_TYPES.filter((type) => BOT_FLAG_TYPES.includes(type)),
|
|
161
|
+
(type) => [
|
|
162
|
+
build(
|
|
163
|
+
'ignoreSelf false still meets ignoreBots',
|
|
164
|
+
type,
|
|
165
|
+
{ ignoreSelf: false },
|
|
166
|
+
subject(type, { actorId: FILTER_CASE_BOT_ID, actorIsBot: true }),
|
|
167
|
+
rejected(DiscordEventFilterName.IGNORE_BOTS),
|
|
168
|
+
),
|
|
169
|
+
],
|
|
170
|
+
),
|
|
171
|
+
...typeCases(POLL_TYPES, (type) => [
|
|
172
|
+
build(
|
|
173
|
+
'ignoreBots does not apply to a poll vote (Discord sends no bot flag)',
|
|
174
|
+
type,
|
|
175
|
+
{ ignoreBots: true },
|
|
176
|
+
subject(type, { actorId: OTHER_BOT_ID, actorIsBot: true }),
|
|
177
|
+
kept,
|
|
178
|
+
),
|
|
148
179
|
build(
|
|
149
|
-
'
|
|
180
|
+
'roleIds does not apply to a poll vote (Discord sends no member)',
|
|
181
|
+
type,
|
|
182
|
+
{ roleIds: ['role-9'] },
|
|
183
|
+
subject(type),
|
|
184
|
+
kept,
|
|
185
|
+
),
|
|
186
|
+
build(
|
|
187
|
+
'ignoreSelf false keeps a vote of the bot itself',
|
|
150
188
|
type,
|
|
151
189
|
{ ignoreSelf: false },
|
|
152
|
-
subject(type, { actorId: FILTER_CASE_BOT_ID
|
|
153
|
-
|
|
190
|
+
subject(type, { actorId: FILTER_CASE_BOT_ID }),
|
|
191
|
+
kept,
|
|
154
192
|
),
|
|
155
193
|
]),
|
|
156
194
|
...typeCases(
|
|
@@ -24,7 +24,7 @@ describe('matchesEventFilters', () => {
|
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
it('the shared set covers every filter on the
|
|
27
|
+
it('the shared set covers every filter on the six types', () => {
|
|
28
28
|
const rejectedBy = new Map<DiscordEventFilterName, Set<DiscordEventType>>();
|
|
29
29
|
for (const c of DISCORD_EVENT_FILTER_CASES) {
|
|
30
30
|
if (!c.expected.kept) {
|
|
@@ -34,6 +34,15 @@ describe('matchesEventFilters', () => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
const all = Object.values(DiscordEventType);
|
|
37
|
+
const polls = [
|
|
38
|
+
DiscordEventType.MESSAGE_POLL_VOTE_ADD,
|
|
39
|
+
DiscordEventType.MESSAGE_POLL_VOTE_REMOVE,
|
|
40
|
+
];
|
|
41
|
+
const channels = [
|
|
42
|
+
DiscordEventType.MESSAGE_CREATE,
|
|
43
|
+
DiscordEventType.MESSAGE_REACTION_ADD,
|
|
44
|
+
...polls,
|
|
45
|
+
].sort();
|
|
37
46
|
expect([...(rejectedBy.get(DiscordEventFilterName.GUILD_ONLY) ?? [])].sort()).toEqual(
|
|
38
47
|
[...all].sort(),
|
|
39
48
|
);
|
|
@@ -41,10 +50,10 @@ describe('matchesEventFilters', () => {
|
|
|
41
50
|
[...all].sort(),
|
|
42
51
|
);
|
|
43
52
|
expect([...(rejectedBy.get(DiscordEventFilterName.IGNORE_BOTS) ?? [])].sort()).toEqual(
|
|
44
|
-
|
|
53
|
+
all.filter((type) => !polls.includes(type)).sort(),
|
|
45
54
|
);
|
|
46
55
|
expect([...(rejectedBy.get(DiscordEventFilterName.CHANNEL_IDS) ?? [])].sort()).toEqual(
|
|
47
|
-
|
|
56
|
+
channels,
|
|
48
57
|
);
|
|
49
58
|
expect([...(rejectedBy.get(DiscordEventFilterName.ROLE_IDS) ?? [])].sort()).toEqual(
|
|
50
59
|
[
|
|
@@ -54,7 +63,7 @@ describe('matchesEventFilters', () => {
|
|
|
54
63
|
].sort(),
|
|
55
64
|
);
|
|
56
65
|
expect([...(rejectedBy.get(DiscordEventFilterName.IGNORE_SELF) ?? [])].sort()).toEqual(
|
|
57
|
-
|
|
66
|
+
channels,
|
|
58
67
|
);
|
|
59
68
|
expect([...(rejectedBy.get(DiscordEventFilterName.CONTENT_PREFIX) ?? [])]).toEqual([
|
|
60
69
|
DiscordEventType.MESSAGE_CREATE,
|
|
@@ -73,6 +82,26 @@ describe('matchesEventFilters', () => {
|
|
|
73
82
|
expect(verdict).toEqual({ kept: false, filter: DiscordEventFilterName.GUILD_ONLY });
|
|
74
83
|
});
|
|
75
84
|
|
|
85
|
+
it.each([DiscordEventType.MESSAGE_POLL_VOTE_ADD, DiscordEventType.MESSAGE_POLL_VOTE_REMOVE])(
|
|
86
|
+
'%s: a vote of the bot itself is ignoreSelf, roleIds and ignoreBots never reject it',
|
|
87
|
+
(type) => {
|
|
88
|
+
expect(
|
|
89
|
+
matchesEventFilters(
|
|
90
|
+
{ eventType: type, filters: {} },
|
|
91
|
+
subject(type, { actorId: FILTER_CASE_BOT_ID }),
|
|
92
|
+
FILTER_CASE_BOT_ID,
|
|
93
|
+
),
|
|
94
|
+
).toEqual({ kept: false, filter: DiscordEventFilterName.IGNORE_SELF });
|
|
95
|
+
expect(
|
|
96
|
+
matchesEventFilters(
|
|
97
|
+
{ eventType: type, filters: { roleIds: ['role-1'], ignoreBots: true } },
|
|
98
|
+
subject(type, { actorIsBot: true }),
|
|
99
|
+
FILTER_CASE_BOT_ID,
|
|
100
|
+
),
|
|
101
|
+
).toEqual({ kept: true });
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
76
105
|
it('does not mutate the trigger or the event', () => {
|
|
77
106
|
const trigger = {
|
|
78
107
|
eventType: DiscordEventType.MESSAGE_CREATE,
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { DiscordEventFilterName, DiscordEventType } from '../types/enum';
|
|
2
2
|
import type { IReflexDiscordEvent } from '../types/interface/models';
|
|
3
|
+
import { isPollVoteEventType } from './discord-event-intents';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* What the filters read of an event, whoever built it (the Gateway from the raw dispatch, the editor from a sample).
|
|
6
|
-
* "Actor" is the author of a message, the member who arrived or left, the user who reacted.
|
|
7
|
+
* "Actor" is the author of a message, the member who arrived or left, the user who reacted or voted.
|
|
7
8
|
*/
|
|
8
9
|
export interface IDiscordEventFilterSubject {
|
|
9
10
|
type: DiscordEventType;
|
|
10
11
|
/** Null outside a server (a direct message). */
|
|
11
12
|
guildId: string | null;
|
|
12
|
-
/** Null for a member event. */
|
|
13
|
+
/** Null for a member event (arrival or departure). */
|
|
13
14
|
channelId: string | null;
|
|
14
15
|
actorId: string | null;
|
|
15
16
|
actorIsBot: boolean;
|
|
@@ -33,9 +34,16 @@ const rejectedBy = (filter: DiscordEventFilterName): DiscordEventFilterVerdict =
|
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
const hasChannel = (type: DiscordEventType): boolean =>
|
|
36
|
-
type === DiscordEventType.MESSAGE_CREATE ||
|
|
37
|
+
type === DiscordEventType.MESSAGE_CREATE ||
|
|
38
|
+
type === DiscordEventType.MESSAGE_REACTION_ADD ||
|
|
39
|
+
isPollVoteEventType(type);
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
/** A departure has no member left, a poll vote carries no member: `roleIds` does not apply to them. */
|
|
42
|
+
const hasRoles = (type: DiscordEventType): boolean =>
|
|
43
|
+
type !== DiscordEventType.GUILD_MEMBER_REMOVE && !isPollVoteEventType(type);
|
|
44
|
+
|
|
45
|
+
/** A poll vote says nothing of the voter but its id: `ignoreBots` does not apply to it (only `ignoreSelf` does). */
|
|
46
|
+
const hasBotFlag = (type: DiscordEventType): boolean => !isPollVoteEventType(type);
|
|
39
47
|
|
|
40
48
|
/**
|
|
41
49
|
* Decides whether a trigger keeps an event. Filters are combined with AND and run in this order, the first that
|
|
@@ -88,7 +96,7 @@ export const matchesEventFilters = (
|
|
|
88
96
|
if (hasChannel(type) && filters.ignoreSelf !== false && event.actorId === botUserId) {
|
|
89
97
|
return rejectedBy(DiscordEventFilterName.IGNORE_SELF);
|
|
90
98
|
}
|
|
91
|
-
if (filters.ignoreBots !== false && event.actorIsBot) {
|
|
99
|
+
if (hasBotFlag(type) && filters.ignoreBots !== false && event.actorIsBot) {
|
|
92
100
|
return rejectedBy(DiscordEventFilterName.IGNORE_BOTS);
|
|
93
101
|
}
|
|
94
102
|
return KEPT;
|
|
@@ -17,6 +17,33 @@ describe('intentsOf', () => {
|
|
|
17
17
|
expect(DiscordGatewayIntent.GUILD_MESSAGES).toBe(512);
|
|
18
18
|
expect(DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS).toBe(1024);
|
|
19
19
|
expect(DiscordGatewayIntent.MESSAGE_CONTENT).toBe(32768);
|
|
20
|
+
expect(DiscordGatewayIntent.GUILD_MESSAGE_POLLS).toBe(16777216);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it.each([DiscordEventType.MESSAGE_POLL_VOTE_ADD, DiscordEventType.MESSAGE_POLL_VOTE_REMOVE])(
|
|
24
|
+
'%s asks for GUILD_MESSAGE_POLLS only when the bot turned poll votes on',
|
|
25
|
+
(eventType) => {
|
|
26
|
+
expect(intentsOf([trigger(eventType)])).toBe(0);
|
|
27
|
+
expect(intentsOf([trigger(eventType)], { pollVotesEnabled: false })).toBe(0);
|
|
28
|
+
expect(intentsOf([trigger(eventType)], { pollVotesEnabled: true })).toBe(
|
|
29
|
+
DiscordGatewayIntent.GUILD_MESSAGE_POLLS,
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
it('asks for no poll intent when poll votes are on but no trigger is a poll vote', () => {
|
|
35
|
+
expect(intentsOf([trigger(DiscordEventType.MESSAGE_CREATE)], { pollVotesEnabled: true })).toBe(
|
|
36
|
+
DiscordGatewayIntent.GUILD_MESSAGES,
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('keeps the other triggers when poll votes are off', () => {
|
|
41
|
+
expect(
|
|
42
|
+
intentsOf([
|
|
43
|
+
trigger(DiscordEventType.MESSAGE_REACTION_ADD),
|
|
44
|
+
trigger(DiscordEventType.MESSAGE_POLL_VOTE_ADD),
|
|
45
|
+
]),
|
|
46
|
+
).toBe(DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS);
|
|
20
47
|
});
|
|
21
48
|
|
|
22
49
|
it('is 0 without a trigger, so the bot keeps identifying with no intent', () => {
|
|
@@ -9,6 +9,8 @@ export enum DiscordGatewayIntent {
|
|
|
9
9
|
GUILD_MESSAGE_REACTIONS = 1 << 10,
|
|
10
10
|
/** The content of a message. Privileged. */
|
|
11
11
|
MESSAGE_CONTENT = 1 << 15,
|
|
12
|
+
/** Poll votes in a server. Not privileged, but asked only when the bot turns poll votes on (card 943). */
|
|
13
|
+
GUILD_MESSAGE_POLLS = 1 << 24,
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
/** The intents Discord asks the bot owner to enable in the portal (and to have verified past 100 servers). */
|
|
@@ -23,8 +25,26 @@ export const DISCORD_EVENT_BASE_INTENT: Record<DiscordEventType, DiscordGatewayI
|
|
|
23
25
|
[DiscordEventType.GUILD_MEMBER_REMOVE]: DiscordGatewayIntent.GUILD_MEMBERS,
|
|
24
26
|
[DiscordEventType.MESSAGE_CREATE]: DiscordGatewayIntent.GUILD_MESSAGES,
|
|
25
27
|
[DiscordEventType.MESSAGE_REACTION_ADD]: DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS,
|
|
28
|
+
[DiscordEventType.MESSAGE_POLL_VOTE_ADD]: DiscordGatewayIntent.GUILD_MESSAGE_POLLS,
|
|
29
|
+
[DiscordEventType.MESSAGE_POLL_VOTE_REMOVE]: DiscordGatewayIntent.GUILD_MESSAGE_POLLS,
|
|
26
30
|
};
|
|
27
31
|
|
|
32
|
+
/** The event types of poll votes: their intent is asked only when the bot turns poll votes on. */
|
|
33
|
+
export const DISCORD_POLL_VOTE_EVENT_TYPES: readonly DiscordEventType[] = [
|
|
34
|
+
DiscordEventType.MESSAGE_POLL_VOTE_ADD,
|
|
35
|
+
DiscordEventType.MESSAGE_POLL_VOTE_REMOVE,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/** True for a poll vote event type. */
|
|
39
|
+
export const isPollVoteEventType = (eventType: DiscordEventType): boolean =>
|
|
40
|
+
DISCORD_POLL_VOTE_EVENT_TYPES.includes(eventType);
|
|
41
|
+
|
|
42
|
+
/** What the bot of an environment allows beyond its triggers. */
|
|
43
|
+
export interface DiscordIntentOptions {
|
|
44
|
+
/** The bot turned poll votes on; false by default: a poll trigger then asks for nothing. */
|
|
45
|
+
pollVotesEnabled?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
type IntentSource = Pick<IReflexDiscordEvent, 'eventType' | 'filters' | 'includeContent'>;
|
|
29
49
|
|
|
30
50
|
/** True when the trigger reads the content of a message: it asks for it, or filters on a prefix. */
|
|
@@ -41,12 +61,17 @@ const intentListOf = (event: IntentSource): DiscordGatewayIntent[] => {
|
|
|
41
61
|
return intents;
|
|
42
62
|
};
|
|
43
63
|
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The `intents` of IDENTIFY for the triggers of a version: the union of their bits, 0 without a trigger. A poll
|
|
66
|
+
* vote trigger counts only when the bot turned poll votes on.
|
|
67
|
+
*/
|
|
68
|
+
export const intentsOf = (
|
|
69
|
+
events: readonly IntentSource[],
|
|
70
|
+
options: DiscordIntentOptions = {},
|
|
71
|
+
): number =>
|
|
72
|
+
events
|
|
73
|
+
.filter((event) => options.pollVotesEnabled === true || !isPollVoteEventType(event.eventType))
|
|
74
|
+
.reduce((bits, event) => intentListOf(event).reduce((acc, intent) => acc | intent, bits), 0);
|
|
50
75
|
|
|
51
76
|
/** The privileged intents the triggers need, in bit order, without duplicates. */
|
|
52
77
|
export const privilegedIntentsOf = (events: readonly IntentSource[]): DiscordGatewayIntent[] => {
|
package/src/discord/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ import * as serviceConsumerApi from './api/service-consumer.api';
|
|
|
25
25
|
import * as serviceOpenApiApi from './api/service-openapi.api';
|
|
26
26
|
import * as serviceLimitsApi from './api/service-limits.api';
|
|
27
27
|
import * as serviceCompletionWebhookApi from './api/service-completion-webhook.api';
|
|
28
|
+
import * as storageSurplusAdminApi from './api/storage-surplus.admin.api';
|
|
28
29
|
|
|
29
30
|
export * from './api';
|
|
30
31
|
export * from './types';
|
|
@@ -33,10 +34,15 @@ export * from './insights';
|
|
|
33
34
|
|
|
34
35
|
const DEFAULT_BASE_URL = 'https://reflex-api.abyss-project.fr/';
|
|
35
36
|
|
|
37
|
+
/** The header of the service-to-service routes (`/storage-surplus/admin/*`): the admin token of the mesh. */
|
|
38
|
+
export const ADMIN_TOKEN_HEADER = 'abyss-admin-token';
|
|
39
|
+
|
|
36
40
|
type CoreConfig = {
|
|
37
41
|
baseURL?: string;
|
|
38
42
|
/** The session token of the member (`Authorization: Bearer`). Every route but `health` needs it. */
|
|
39
43
|
token?: string;
|
|
44
|
+
/** The admin token of the mesh (`abyss-admin-token`), for the routes abyss-main calls (`storageSurplus.admin`). */
|
|
45
|
+
adminToken?: string;
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
type AbyssReflexCoreSDK = {
|
|
@@ -71,6 +77,9 @@ type AbyssReflexCoreSDK = {
|
|
|
71
77
|
list: typeof functionRunApi.listFunctionRun;
|
|
72
78
|
get: typeof functionRunApi.getFunctionRun;
|
|
73
79
|
state: typeof functionRunApi.getFunctionRunState;
|
|
80
|
+
replay: typeof functionRunApi.replayFunctionRun;
|
|
81
|
+
/** Marks a run as a favorite (never purged) or not. */
|
|
82
|
+
favorite: typeof functionRunApi.setFunctionRunFavorite;
|
|
74
83
|
};
|
|
75
84
|
/** The dashboard of the function: tiles, series, ranking. */
|
|
76
85
|
insights: {
|
|
@@ -86,6 +95,11 @@ type AbyssReflexCoreSDK = {
|
|
|
86
95
|
logCap: {
|
|
87
96
|
set: typeof functionSettingsApi.setFunctionLogCap;
|
|
88
97
|
};
|
|
98
|
+
/** The retention tier of the runs of the function and the number of versions kept. */
|
|
99
|
+
runRetention: {
|
|
100
|
+
get: typeof functionSettingsApi.getFunctionRunRetention;
|
|
101
|
+
set: typeof functionSettingsApi.setFunctionRunRetention;
|
|
102
|
+
};
|
|
89
103
|
};
|
|
90
104
|
/** Function templates of an application (`/api/function-template/:applicationId`). */
|
|
91
105
|
functionTemplate: {
|
|
@@ -229,6 +243,18 @@ type AbyssReflexCoreSDK = {
|
|
|
229
243
|
rotateSecret: typeof serviceCompletionWebhookApi.rotateServiceCompletionWebhookSecret;
|
|
230
244
|
};
|
|
231
245
|
};
|
|
246
|
+
/**
|
|
247
|
+
* The day-90 contract of abyss-main's storage surplus, service-to-service (admin token). AbyssReflex has nothing to
|
|
248
|
+
* archive for the ONLINE surplus: `listArchivable` is always empty; the archives of the runs are listed and deleted.
|
|
249
|
+
*/
|
|
250
|
+
storageSurplus: {
|
|
251
|
+
admin: {
|
|
252
|
+
listArchivable: typeof storageSurplusAdminApi.listArchivableStorageSurplusAdmin;
|
|
253
|
+
archive: typeof storageSurplusAdminApi.archiveStorageSurplusAdmin;
|
|
254
|
+
listArchives: typeof storageSurplusAdminApi.listArchivesStorageSurplusAdmin;
|
|
255
|
+
deleteArchives: typeof storageSurplusAdminApi.deleteArchivesStorageSurplusAdmin;
|
|
256
|
+
};
|
|
257
|
+
};
|
|
232
258
|
};
|
|
233
259
|
|
|
234
260
|
export class AbyssReflexCore {
|
|
@@ -274,6 +300,8 @@ export class AbyssReflexCore {
|
|
|
274
300
|
list: functionRunApi.listFunctionRun,
|
|
275
301
|
get: functionRunApi.getFunctionRun,
|
|
276
302
|
state: functionRunApi.getFunctionRunState,
|
|
303
|
+
replay: functionRunApi.replayFunctionRun,
|
|
304
|
+
favorite: functionRunApi.setFunctionRunFavorite,
|
|
277
305
|
},
|
|
278
306
|
insights: {
|
|
279
307
|
get: functionInsightsApi.getFunctionInsights,
|
|
@@ -287,6 +315,10 @@ export class AbyssReflexCore {
|
|
|
287
315
|
logCap: {
|
|
288
316
|
set: functionSettingsApi.setFunctionLogCap,
|
|
289
317
|
},
|
|
318
|
+
runRetention: {
|
|
319
|
+
get: functionSettingsApi.getFunctionRunRetention,
|
|
320
|
+
set: functionSettingsApi.setFunctionRunRetention,
|
|
321
|
+
},
|
|
290
322
|
},
|
|
291
323
|
functionTemplate: {
|
|
292
324
|
list: functionTemplateApi.listFunctionTemplate,
|
|
@@ -413,6 +445,14 @@ export class AbyssReflexCore {
|
|
|
413
445
|
rotateSecret: serviceCompletionWebhookApi.rotateServiceCompletionWebhookSecret,
|
|
414
446
|
},
|
|
415
447
|
},
|
|
448
|
+
storageSurplus: {
|
|
449
|
+
admin: {
|
|
450
|
+
listArchivable: storageSurplusAdminApi.listArchivableStorageSurplusAdmin,
|
|
451
|
+
archive: storageSurplusAdminApi.archiveStorageSurplusAdmin,
|
|
452
|
+
listArchives: storageSurplusAdminApi.listArchivesStorageSurplusAdmin,
|
|
453
|
+
deleteArchives: storageSurplusAdminApi.deleteArchivesStorageSurplusAdmin,
|
|
454
|
+
},
|
|
455
|
+
},
|
|
416
456
|
};
|
|
417
457
|
}
|
|
418
458
|
return AbyssReflexCore._sdk;
|
|
@@ -430,6 +470,10 @@ export class AbyssReflexCore {
|
|
|
430
470
|
if (config.token) {
|
|
431
471
|
AbyssReflexCore.axios.defaults.headers.common.Authorization = `Bearer ${config.token}`;
|
|
432
472
|
}
|
|
473
|
+
|
|
474
|
+
if (config.adminToken) {
|
|
475
|
+
AbyssReflexCore.axios.defaults.headers.common[ADMIN_TOKEN_HEADER] = config.adminToken;
|
|
476
|
+
}
|
|
433
477
|
}
|
|
434
478
|
|
|
435
479
|
public static getConfig(): CoreConfig {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The place of a row in the tree of a slash command: a command (the root), a subcommand group, or a
|
|
3
|
+
* subcommand. A command without children, a subcommand and a context menu run a function (a leaf); a command
|
|
4
|
+
* with children and a group do not.
|
|
5
|
+
*/
|
|
6
|
+
export enum DiscordCommandNodeType {
|
|
7
|
+
COMMAND = 'COMMAND',
|
|
8
|
+
SUBCOMMAND_GROUP = 'SUBCOMMAND_GROUP',
|
|
9
|
+
SUBCOMMAND = 'SUBCOMMAND',
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The type of a Discord application command: a slash command, or a context menu (right click, then "Apps"). */
|
|
2
|
+
export enum DiscordCommandType {
|
|
3
|
+
/** A slash command, `/name`. */
|
|
4
|
+
CHAT_INPUT = 'CHAT_INPUT',
|
|
5
|
+
/** A context menu on a member. */
|
|
6
|
+
USER = 'USER',
|
|
7
|
+
/** A context menu on a message. */
|
|
8
|
+
MESSAGE = 'MESSAGE',
|
|
9
|
+
}
|
|
@@ -4,4 +4,8 @@ export enum DiscordEventType {
|
|
|
4
4
|
GUILD_MEMBER_REMOVE = 'GUILD_MEMBER_REMOVE',
|
|
5
5
|
MESSAGE_CREATE = 'MESSAGE_CREATE',
|
|
6
6
|
MESSAGE_REACTION_ADD = 'MESSAGE_REACTION_ADD',
|
|
7
|
+
/** A member votes for an answer of a poll (one event per answer). Received only when the bot turns poll votes on. */
|
|
8
|
+
MESSAGE_POLL_VOTE_ADD = 'MESSAGE_POLL_VOTE_ADD',
|
|
9
|
+
/** A member withdraws a vote. Received only when the bot turns poll votes on. */
|
|
10
|
+
MESSAGE_POLL_VOTE_REMOVE = 'MESSAGE_POLL_VOTE_REMOVE',
|
|
7
11
|
}
|
package/src/types/enum/index.ts
CHANGED
|
@@ -20,6 +20,8 @@ export * from './vault-visibility.enum';
|
|
|
20
20
|
export * from './configuration-read-as.enum';
|
|
21
21
|
export * from './service-version-change-kind.enum';
|
|
22
22
|
export * from './discord-option-type.enum';
|
|
23
|
+
export * from './discord-command-type.enum';
|
|
24
|
+
export * from './discord-command-node-type.enum';
|
|
23
25
|
export * from './discord-component-kind.enum';
|
|
24
26
|
export * from './discord-sync-status.enum';
|
|
25
27
|
export * from './discord-token-state.enum';
|