alemonjs 2.1.53 → 2.1.55
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/lib/app/define-router.d.ts +1 -0
- package/lib/app/define-router.js +6 -1
- package/lib/app/event-format.js +1 -1
- package/lib/app/event-processor-cycleFiles.js +2 -6
- package/lib/app/expose.d.ts +16 -0
- package/lib/app/expose.js +190 -0
- package/lib/app/index.d.ts +1 -0
- package/lib/app/index.js +2 -1
- package/lib/app/load_modules/loadChild.js +4 -0
- package/lib/app/store.d.ts +9 -9
- package/lib/app/store.js +2 -0
- package/lib/index.js +2 -1
- package/lib/types/event/index.d.ts +2 -0
- package/lib/types/expose/index.d.ts +41 -0
- package/lib/types/expose/index.js +1 -0
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/lib/app/define/define-children.d.ts +0 -8
- package/lib/app/define/define-children.js +0 -25
- package/lib/app/define/define-middleware.d.ts +0 -2
- package/lib/app/define/define-middleware.js +0 -8
- package/lib/app/define/define-platform.d.ts +0 -13
- package/lib/app/define/define-platform.js +0 -40
- package/lib/app/define/define-response.d.ts +0 -2
- package/lib/app/define/define-response.js +0 -8
- package/lib/app/define/define-router.d.ts +0 -17
- package/lib/app/define/define-router.js +0 -34
- package/lib/app/event/event-group.d.ts +0 -9
- package/lib/app/event/event-group.js +0 -29
- package/lib/app/event/event-middleware.d.ts +0 -23
- package/lib/app/event/event-middleware.js +0 -44
- package/lib/app/event/event-response.d.ts +0 -16
- package/lib/app/event/event-response.js +0 -23
- package/lib/app/event/event-selects.d.ts +0 -13
- package/lib/app/event/event-selects.js +0 -15
- package/lib/app/event-processor/event-processor-callHandler.d.ts +0 -1
- package/lib/app/event-processor/event-processor-callHandler.js +0 -43
- package/lib/app/event-processor/event-processor-cycle.d.ts +0 -14
- package/lib/app/event-processor/event-processor-cycle.js +0 -97
- package/lib/app/event-processor/event-processor-cycleFiles.d.ts +0 -11
- package/lib/app/event-processor/event-processor-cycleFiles.js +0 -147
- package/lib/app/event-processor/event-processor-cycleRoute.d.ts +0 -10
- package/lib/app/event-processor/event-processor-cycleRoute.js +0 -133
- package/lib/app/event-processor/event-processor-event.d.ts +0 -24
- package/lib/app/event-processor/event-processor-event.js +0 -41
- package/lib/app/event-processor/event-processor-middleware.d.ts +0 -14
- package/lib/app/event-processor/event-processor-middleware.js +0 -31
- package/lib/app/event-processor/event-processor-subscribe.d.ts +0 -35
- package/lib/app/event-processor/event-processor-subscribe.js +0 -115
- package/lib/app/event-processor/event-processor.d.ts +0 -17
- package/lib/app/event-processor/event-processor.js +0 -207
- package/lib/app/hook-use/hook-use-api.d.ts +0 -6
- package/lib/app/hook-use/hook-use-api.js +0 -22
- package/lib/app/hook-use/hook-use-channel.d.ts +0 -8
- package/lib/app/hook-use/hook-use-channel.js +0 -33
- package/lib/app/hook-use/hook-use-client.d.ts +0 -7
- package/lib/app/hook-use/hook-use-client.js +0 -27
- package/lib/app/hook-use/hook-use-me.d.ts +0 -8
- package/lib/app/hook-use/hook-use-me.js +0 -45
- package/lib/app/hook-use/hook-use-menber.d.ts +0 -8
- package/lib/app/hook-use/hook-use-menber.js +0 -59
- package/lib/app/hook-use/hook-use-mention.d.ts +0 -23
- package/lib/app/hook-use/hook-use-mention.js +0 -105
- package/lib/app/hook-use/hook-use-message.d.ts +0 -29
- package/lib/app/hook-use/hook-use-message.js +0 -88
- package/lib/app/hook-use/hook-use-state.d.ts +0 -30
- package/lib/app/hook-use/hook-use-state.js +0 -101
- package/lib/app/hook-use/hook-use-subscribe.d.ts +0 -46
- package/lib/app/hook-use/hook-use-subscribe.js +0 -143
- package/lib/app/hook-use-api.d.ts +0 -268
- package/lib/app/hook-use-api.js +0 -1213
- package/lib/app/hook-use-state.d.ts +0 -3
- package/lib/app/hook-use-state.js +0 -68
- package/lib/app/hook-use-subscribe.d.ts +0 -73
- package/lib/app/hook-use-subscribe.js +0 -112
- package/lib/app/message/message-api.d.ts +0 -69
- package/lib/app/message/message-api.js +0 -105
- package/lib/app/message/message-format-old.d.ts +0 -143
- package/lib/app/message/message-format-old.js +0 -359
- package/lib/app/message/message-format.d.ts +0 -215
- package/lib/app/message/message-format.js +0 -382
- package/lib/app/message-controller.d.ts +0 -25
- package/lib/app/message-controller.js +0 -66
- package/lib/app/message-format.old.d.ts +0 -50
- package/lib/app/message-format.old.js +0 -217
- package/lib/cbp/processor/handle.d.ts +0 -3
- package/lib/cbp/processor/handle.js +0 -32
- package/lib/jsx/index.d.ts +0 -105
- package/lib/jsx/index.js +0 -211
- package/lib/jsx/jsx-dev-runtime.d.ts +0 -2
- package/lib/jsx/jsx-dev-runtime.js +0 -1
- package/lib/jsx/jsx-runtime.d.ts +0 -18
- package/lib/jsx/jsx-runtime.js +0 -24
- package/lib/process/client.js +0 -109
- package/lib/store/SinglyLinkedList.d.ts +0 -22
- package/lib/store/SinglyLinkedList.js +0 -97
- package/lib/store/store.d.ts +0 -127
- package/lib/store/store.js +0 -443
package/lib/app/hook-use-api.js
DELETED
|
@@ -1,1213 +0,0 @@
|
|
|
1
|
-
import { ResultCode } from '../core/variable.js';
|
|
2
|
-
import { ChildrenApp } from './store.js';
|
|
3
|
-
import { createResult } from '../core/utils.js';
|
|
4
|
-
import { sendAction } from '../cbp/processor/actions.js';
|
|
5
|
-
import { sendAPI } from '../cbp/processor/api.js';
|
|
6
|
-
import { Format } from './message-format.js';
|
|
7
|
-
import { getCurrentEvent } from './hook-event-context.js';
|
|
8
|
-
|
|
9
|
-
const useMention = (event) => {
|
|
10
|
-
if (!event || typeof event !== 'object') {
|
|
11
|
-
logger.error({
|
|
12
|
-
code: ResultCode.FailParams,
|
|
13
|
-
message: 'Invalid event: event must be an object',
|
|
14
|
-
data: null
|
|
15
|
-
});
|
|
16
|
-
throw new Error('Invalid event: event must be an object');
|
|
17
|
-
}
|
|
18
|
-
let res = null;
|
|
19
|
-
const load = async () => {
|
|
20
|
-
if (res) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const results = await sendAction({
|
|
24
|
-
action: 'mention.get',
|
|
25
|
-
payload: { event }
|
|
26
|
-
});
|
|
27
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
28
|
-
if (result) {
|
|
29
|
-
res = result.data;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const match = (item, options) => {
|
|
33
|
-
if (options.UserId !== undefined && item.UserId !== options.UserId) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
if (options.UserKey !== undefined && item.UserKey !== options.UserKey) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
if (options.IsBot === undefined && item.IsBot) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
};
|
|
53
|
-
const mention = {
|
|
54
|
-
find: async (options = {}) => {
|
|
55
|
-
try {
|
|
56
|
-
await load();
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
const result = createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
|
|
60
|
-
return {
|
|
61
|
-
...result,
|
|
62
|
-
count: 0
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
if (!Array.isArray(res)) {
|
|
66
|
-
return {
|
|
67
|
-
...createResult(ResultCode.Warn, 'No mention data found', null),
|
|
68
|
-
count: 0
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const data = res.filter(item => match(item, options));
|
|
72
|
-
const result = createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
|
|
73
|
-
return {
|
|
74
|
-
...result,
|
|
75
|
-
count: data.length || 0
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
findOne: async (options = {}) => {
|
|
79
|
-
const results = await mention.find(options);
|
|
80
|
-
if (results.code !== ResultCode.Ok || !results.data?.length) {
|
|
81
|
-
const result = createResult(results.code, results.message, null);
|
|
82
|
-
return {
|
|
83
|
-
...result,
|
|
84
|
-
count: 0
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
const data = results?.data[0];
|
|
88
|
-
const result = createResult(ResultCode.Ok, results.message, data);
|
|
89
|
-
return {
|
|
90
|
-
...result,
|
|
91
|
-
count: results.data?.length || 0
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
return [mention];
|
|
96
|
-
};
|
|
97
|
-
const useMessage = (event) => {
|
|
98
|
-
const currentEvent = (event ?? getCurrentEvent());
|
|
99
|
-
if (!currentEvent || typeof currentEvent !== 'object') {
|
|
100
|
-
logger.error({
|
|
101
|
-
code: ResultCode.FailParams,
|
|
102
|
-
message: 'Invalid event: event must be an object',
|
|
103
|
-
data: null
|
|
104
|
-
});
|
|
105
|
-
throw new Error('Invalid event: event must be an object');
|
|
106
|
-
}
|
|
107
|
-
const valueEvent = currentEvent;
|
|
108
|
-
const resolveFormat = (params) => {
|
|
109
|
-
if (params.format instanceof Format) {
|
|
110
|
-
return params.format.value;
|
|
111
|
-
}
|
|
112
|
-
return params.format;
|
|
113
|
-
};
|
|
114
|
-
const sendRaw = async (val, replyId) => {
|
|
115
|
-
if (!val || val.length === 0) {
|
|
116
|
-
return [createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)];
|
|
117
|
-
}
|
|
118
|
-
const result = await sendAction({
|
|
119
|
-
action: 'message.send',
|
|
120
|
-
payload: {
|
|
121
|
-
event: valueEvent,
|
|
122
|
-
params: {
|
|
123
|
-
format: val,
|
|
124
|
-
replyId
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return Array.isArray(result) ? result : [result];
|
|
129
|
-
};
|
|
130
|
-
const lightweight = {
|
|
131
|
-
send(params) {
|
|
132
|
-
if (Array.isArray(params)) {
|
|
133
|
-
return sendRaw(params.length > 0 ? params : []);
|
|
134
|
-
}
|
|
135
|
-
return sendRaw(resolveFormat(params), params?.replyId ?? valueEvent.MessageId);
|
|
136
|
-
},
|
|
137
|
-
async delete(params) {
|
|
138
|
-
const targetId = params?.messageId || valueEvent.MessageId;
|
|
139
|
-
if (!targetId) {
|
|
140
|
-
return createResult(ResultCode.FailParams, 'Missing MessageId', null);
|
|
141
|
-
}
|
|
142
|
-
try {
|
|
143
|
-
const results = await sendAction({
|
|
144
|
-
action: 'message.delete',
|
|
145
|
-
payload: { MessageId: targetId, ChannelId: valueEvent.ChannelId, event: valueEvent }
|
|
146
|
-
});
|
|
147
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
148
|
-
return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
return createResult(ResultCode.Fail, 'Failed to delete message', null);
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
async edit(params) {
|
|
155
|
-
const targetId = params.messageId || valueEvent.MessageId;
|
|
156
|
-
const channelId = valueEvent.ChannelId;
|
|
157
|
-
if (!targetId || !channelId) {
|
|
158
|
-
return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const val = params.format instanceof Format ? params.format.value : params.format;
|
|
162
|
-
const results = await sendAction({
|
|
163
|
-
action: 'message.edit',
|
|
164
|
-
payload: { ChannelId: channelId, MessageId: targetId, params: { format: val }, event: valueEvent }
|
|
165
|
-
});
|
|
166
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
167
|
-
return result || createResult(ResultCode.Warn, 'Edit not supported or failed', null);
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
return createResult(ResultCode.Fail, 'Failed to edit message', null);
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
async pin(params) {
|
|
174
|
-
const targetId = params?.messageId || valueEvent.MessageId;
|
|
175
|
-
const channelId = valueEvent.ChannelId;
|
|
176
|
-
if (!targetId || !channelId) {
|
|
177
|
-
return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
const results = await sendAction({
|
|
181
|
-
action: 'message.pin',
|
|
182
|
-
payload: { ChannelId: channelId, MessageId: targetId }
|
|
183
|
-
});
|
|
184
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
185
|
-
return result || createResult(ResultCode.Warn, 'Pin not supported or failed', null);
|
|
186
|
-
}
|
|
187
|
-
catch {
|
|
188
|
-
return createResult(ResultCode.Fail, 'Failed to pin message', null);
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
async unpin(params) {
|
|
192
|
-
const targetId = params?.messageId || valueEvent.MessageId;
|
|
193
|
-
const channelId = valueEvent.ChannelId;
|
|
194
|
-
if (!targetId || !channelId) {
|
|
195
|
-
return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
|
|
196
|
-
}
|
|
197
|
-
try {
|
|
198
|
-
const results = await sendAction({
|
|
199
|
-
action: 'message.unpin',
|
|
200
|
-
payload: { ChannelId: channelId, MessageId: targetId }
|
|
201
|
-
});
|
|
202
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
203
|
-
return result || createResult(ResultCode.Warn, 'Unpin not supported or failed', null);
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
return createResult(ResultCode.Fail, 'Failed to unpin message', null);
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
async get(params) {
|
|
210
|
-
const targetId = params?.messageId || valueEvent.MessageId;
|
|
211
|
-
if (!targetId) {
|
|
212
|
-
return createResult(ResultCode.FailParams, 'Missing MessageId', null);
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
const results = await sendAction({
|
|
216
|
-
action: 'message.get',
|
|
217
|
-
payload: { MessageId: targetId }
|
|
218
|
-
});
|
|
219
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
220
|
-
return result || createResult(ResultCode.Warn, 'Get message not supported or failed', null);
|
|
221
|
-
}
|
|
222
|
-
catch {
|
|
223
|
-
return createResult(ResultCode.Fail, 'Failed to get message', null);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
return [lightweight];
|
|
228
|
-
};
|
|
229
|
-
const useMember = (event) => {
|
|
230
|
-
if (!event || typeof event !== 'object') {
|
|
231
|
-
logger.error({
|
|
232
|
-
code: ResultCode.FailParams,
|
|
233
|
-
message: 'Invalid event: event must be an object',
|
|
234
|
-
data: null
|
|
235
|
-
});
|
|
236
|
-
throw new Error('Invalid event: event must be an object');
|
|
237
|
-
}
|
|
238
|
-
const getGuildId = (guildId) => guildId || event.GuildId;
|
|
239
|
-
const info = async (params) => {
|
|
240
|
-
try {
|
|
241
|
-
const results = await sendAction({
|
|
242
|
-
action: 'member.info',
|
|
243
|
-
payload: {
|
|
244
|
-
event,
|
|
245
|
-
params: {
|
|
246
|
-
userId: params.userId,
|
|
247
|
-
guildId: getGuildId(params.guildId)
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
252
|
-
if (result) {
|
|
253
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved member information', result.data ?? null);
|
|
254
|
-
}
|
|
255
|
-
return createResult(ResultCode.Warn, 'No member information found', null);
|
|
256
|
-
}
|
|
257
|
-
catch {
|
|
258
|
-
return createResult(ResultCode.Fail, 'Failed to get member information', null);
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
const list = async (params) => {
|
|
262
|
-
const guildId = getGuildId(params?.guildId);
|
|
263
|
-
if (!guildId) {
|
|
264
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', { Items: [] });
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
const results = await sendAction({
|
|
268
|
-
action: 'member.list',
|
|
269
|
-
payload: { GuildId: guildId, params: params?.pagination }
|
|
270
|
-
});
|
|
271
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
272
|
-
if (result) {
|
|
273
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved member list', result.data ?? { Items: [] });
|
|
274
|
-
}
|
|
275
|
-
return createResult(ResultCode.Warn, 'No member list found', { Items: [] });
|
|
276
|
-
}
|
|
277
|
-
catch {
|
|
278
|
-
return createResult(ResultCode.Fail, 'Failed to get member list', { Items: [] });
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
const kick = async (params) => {
|
|
282
|
-
const gid = getGuildId(params.guildId);
|
|
283
|
-
if (!gid || !params.userId) {
|
|
284
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
285
|
-
}
|
|
286
|
-
try {
|
|
287
|
-
const results = await sendAction({
|
|
288
|
-
action: 'member.kick',
|
|
289
|
-
payload: { GuildId: gid, UserId: params.userId }
|
|
290
|
-
});
|
|
291
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
292
|
-
return result || createResult(ResultCode.Warn, 'Kick not supported or failed', null);
|
|
293
|
-
}
|
|
294
|
-
catch {
|
|
295
|
-
return createResult(ResultCode.Fail, 'Failed to kick member', null);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
const ban = async (params) => {
|
|
299
|
-
const gid = getGuildId(params.guildId);
|
|
300
|
-
if (!gid || !params.userId) {
|
|
301
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
302
|
-
}
|
|
303
|
-
try {
|
|
304
|
-
const results = await sendAction({
|
|
305
|
-
action: 'member.ban',
|
|
306
|
-
payload: { GuildId: gid, UserId: params.userId, params: { reason: params.reason, duration: params.duration } }
|
|
307
|
-
});
|
|
308
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
309
|
-
return result || createResult(ResultCode.Warn, 'Ban not supported or failed', null);
|
|
310
|
-
}
|
|
311
|
-
catch {
|
|
312
|
-
return createResult(ResultCode.Fail, 'Failed to ban member', null);
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
const unban = async (params) => {
|
|
316
|
-
const gid = getGuildId(params.guildId);
|
|
317
|
-
if (!gid || !params.userId) {
|
|
318
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
319
|
-
}
|
|
320
|
-
try {
|
|
321
|
-
const results = await sendAction({
|
|
322
|
-
action: 'member.unban',
|
|
323
|
-
payload: { GuildId: gid, UserId: params.userId }
|
|
324
|
-
});
|
|
325
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
326
|
-
return result || createResult(ResultCode.Warn, 'Unban not supported or failed', null);
|
|
327
|
-
}
|
|
328
|
-
catch {
|
|
329
|
-
return createResult(ResultCode.Fail, 'Failed to unban member', null);
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
const information = (params) => info(params);
|
|
333
|
-
const search = async (params) => {
|
|
334
|
-
const gid = getGuildId(params.guildId);
|
|
335
|
-
if (!gid || !params.keyword) {
|
|
336
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or keyword', null);
|
|
337
|
-
}
|
|
338
|
-
try {
|
|
339
|
-
const results = await sendAction({
|
|
340
|
-
action: 'member.search',
|
|
341
|
-
payload: { GuildId: gid, params: { keyword: params.keyword, limit: params.limit } }
|
|
342
|
-
});
|
|
343
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
344
|
-
return result || createResult(ResultCode.Warn, 'Member search not supported or failed', null);
|
|
345
|
-
}
|
|
346
|
-
catch {
|
|
347
|
-
return createResult(ResultCode.Fail, 'Failed to search members', null);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
const member = {
|
|
351
|
-
info,
|
|
352
|
-
information,
|
|
353
|
-
list,
|
|
354
|
-
kick,
|
|
355
|
-
ban,
|
|
356
|
-
unban,
|
|
357
|
-
search,
|
|
358
|
-
async mute(params) {
|
|
359
|
-
const gid = getGuildId(params.guildId);
|
|
360
|
-
if (!gid || !params.userId) {
|
|
361
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
362
|
-
}
|
|
363
|
-
try {
|
|
364
|
-
const results = await sendAction({
|
|
365
|
-
action: 'member.mute',
|
|
366
|
-
payload: { GuildId: gid, UserId: params.userId, params: { duration: params.duration } }
|
|
367
|
-
});
|
|
368
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
369
|
-
return result || createResult(ResultCode.Warn, 'Mute not supported or failed', null);
|
|
370
|
-
}
|
|
371
|
-
catch {
|
|
372
|
-
return createResult(ResultCode.Fail, 'Failed to mute member', null);
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
async admin(params) {
|
|
376
|
-
const gid = getGuildId(params.guildId);
|
|
377
|
-
if (!gid || !params.userId) {
|
|
378
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
379
|
-
}
|
|
380
|
-
try {
|
|
381
|
-
const results = await sendAction({
|
|
382
|
-
action: 'member.admin',
|
|
383
|
-
payload: { GuildId: gid, UserId: params.userId, params: { enable: params.enable } }
|
|
384
|
-
});
|
|
385
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
386
|
-
return result || createResult(ResultCode.Warn, 'Admin set not supported or failed', null);
|
|
387
|
-
}
|
|
388
|
-
catch {
|
|
389
|
-
return createResult(ResultCode.Fail, 'Failed to set admin', null);
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
async card(params) {
|
|
393
|
-
const gid = getGuildId(params.guildId);
|
|
394
|
-
if (!gid || !params.userId) {
|
|
395
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
396
|
-
}
|
|
397
|
-
try {
|
|
398
|
-
const results = await sendAction({
|
|
399
|
-
action: 'member.card',
|
|
400
|
-
payload: { GuildId: gid, UserId: params.userId, params: { card: params.card } }
|
|
401
|
-
});
|
|
402
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
403
|
-
return result || createResult(ResultCode.Warn, 'Card set not supported or failed', null);
|
|
404
|
-
}
|
|
405
|
-
catch {
|
|
406
|
-
return createResult(ResultCode.Fail, 'Failed to set member card', null);
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
async title(params) {
|
|
410
|
-
const gid = getGuildId(params.guildId);
|
|
411
|
-
if (!gid || !params.userId) {
|
|
412
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
413
|
-
}
|
|
414
|
-
try {
|
|
415
|
-
const results = await sendAction({
|
|
416
|
-
action: 'member.title',
|
|
417
|
-
payload: { GuildId: gid, UserId: params.userId, params: { title: params.title, duration: params.duration ?? -1 } }
|
|
418
|
-
});
|
|
419
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
420
|
-
return result || createResult(ResultCode.Warn, 'Title set not supported or failed', null);
|
|
421
|
-
}
|
|
422
|
-
catch {
|
|
423
|
-
return createResult(ResultCode.Fail, 'Failed to set member title', null);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
return [member];
|
|
428
|
-
};
|
|
429
|
-
const useChannel = (event) => {
|
|
430
|
-
if (!event || typeof event !== 'object') {
|
|
431
|
-
logger.error({
|
|
432
|
-
code: ResultCode.FailParams,
|
|
433
|
-
message: 'Invalid event: event must be an object',
|
|
434
|
-
data: null
|
|
435
|
-
});
|
|
436
|
-
throw new Error('Invalid event: event must be an object');
|
|
437
|
-
}
|
|
438
|
-
const info = async (params) => {
|
|
439
|
-
const cid = params?.channelId || event.ChannelId;
|
|
440
|
-
if (!cid) {
|
|
441
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
|
|
442
|
-
}
|
|
443
|
-
try {
|
|
444
|
-
const results = await sendAction({
|
|
445
|
-
action: 'channel.info',
|
|
446
|
-
payload: { ChannelId: cid }
|
|
447
|
-
});
|
|
448
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
449
|
-
if (result) {
|
|
450
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved channel info', result.data ?? null);
|
|
451
|
-
}
|
|
452
|
-
return createResult(ResultCode.Warn, 'No channel info found', null);
|
|
453
|
-
}
|
|
454
|
-
catch {
|
|
455
|
-
return createResult(ResultCode.Fail, 'Failed to get channel info', null);
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
const list = async (params) => {
|
|
459
|
-
const gid = params?.guildId || event.GuildId;
|
|
460
|
-
if (!gid) {
|
|
461
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', []);
|
|
462
|
-
}
|
|
463
|
-
try {
|
|
464
|
-
const results = await sendAction({
|
|
465
|
-
action: 'channel.list',
|
|
466
|
-
payload: { GuildId: gid }
|
|
467
|
-
});
|
|
468
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
469
|
-
if (result) {
|
|
470
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved channel list', result.data ?? []);
|
|
471
|
-
}
|
|
472
|
-
return createResult(ResultCode.Warn, 'No channel list found', []);
|
|
473
|
-
}
|
|
474
|
-
catch {
|
|
475
|
-
return createResult(ResultCode.Fail, 'Failed to get channel list', []);
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
const create = async (params) => {
|
|
479
|
-
const gid = params.guildId || event.GuildId;
|
|
480
|
-
if (!gid) {
|
|
481
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
482
|
-
}
|
|
483
|
-
try {
|
|
484
|
-
const results = await sendAction({
|
|
485
|
-
action: 'channel.create',
|
|
486
|
-
payload: { GuildId: gid, params: { name: params.name, type: params.type, parentId: params.parentId } }
|
|
487
|
-
});
|
|
488
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
489
|
-
return result
|
|
490
|
-
? createResult(ResultCode.Ok, 'Channel created', result.data ?? null)
|
|
491
|
-
: createResult(ResultCode.Warn, 'Create not supported or failed', null);
|
|
492
|
-
}
|
|
493
|
-
catch {
|
|
494
|
-
return createResult(ResultCode.Fail, 'Failed to create channel', null);
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
const update = async (params) => {
|
|
498
|
-
if (!params.channelId) {
|
|
499
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
|
|
500
|
-
}
|
|
501
|
-
try {
|
|
502
|
-
const results = await sendAction({
|
|
503
|
-
action: 'channel.update',
|
|
504
|
-
payload: { ChannelId: params.channelId, params: { name: params.name, topic: params.topic, position: params.position } }
|
|
505
|
-
});
|
|
506
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
507
|
-
return result || createResult(ResultCode.Warn, 'Update not supported or failed', null);
|
|
508
|
-
}
|
|
509
|
-
catch {
|
|
510
|
-
return createResult(ResultCode.Fail, 'Failed to update channel', null);
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
const remove = async (params) => {
|
|
514
|
-
if (!params.channelId) {
|
|
515
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
|
|
516
|
-
}
|
|
517
|
-
try {
|
|
518
|
-
const results = await sendAction({
|
|
519
|
-
action: 'channel.delete',
|
|
520
|
-
payload: { ChannelId: params.channelId }
|
|
521
|
-
});
|
|
522
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
523
|
-
return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
|
|
524
|
-
}
|
|
525
|
-
catch {
|
|
526
|
-
return createResult(ResultCode.Fail, 'Failed to delete channel', null);
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
const channel = {
|
|
530
|
-
info,
|
|
531
|
-
list,
|
|
532
|
-
create,
|
|
533
|
-
update,
|
|
534
|
-
delete: remove
|
|
535
|
-
};
|
|
536
|
-
return [channel];
|
|
537
|
-
};
|
|
538
|
-
const useSend = (event) => {
|
|
539
|
-
const [message] = useMessage(event);
|
|
540
|
-
const send = (...val) => {
|
|
541
|
-
return message.send(val);
|
|
542
|
-
};
|
|
543
|
-
return send;
|
|
544
|
-
};
|
|
545
|
-
const useSends = (event) => {
|
|
546
|
-
const [message] = useMessage(event);
|
|
547
|
-
return [message.send];
|
|
548
|
-
};
|
|
549
|
-
const unChildren = (name = 'main') => {
|
|
550
|
-
if (!name || typeof name !== 'string') {
|
|
551
|
-
logger.error({
|
|
552
|
-
code: ResultCode.FailParams,
|
|
553
|
-
message: 'Invalid name: name must be a string',
|
|
554
|
-
data: null
|
|
555
|
-
});
|
|
556
|
-
throw new Error('Invalid name: name must be a string');
|
|
557
|
-
}
|
|
558
|
-
const app = new ChildrenApp(name);
|
|
559
|
-
app.un();
|
|
560
|
-
};
|
|
561
|
-
const onSelects = (values) => values;
|
|
562
|
-
global.onSelects = onSelects;
|
|
563
|
-
const createSelects = onSelects;
|
|
564
|
-
const useClient = (event, _ApiClass) => {
|
|
565
|
-
const client = new Proxy({}, {
|
|
566
|
-
get(_target, prop) {
|
|
567
|
-
if (typeof prop === 'symbol') {
|
|
568
|
-
return undefined;
|
|
569
|
-
}
|
|
570
|
-
return (...args) => {
|
|
571
|
-
return sendAPI({
|
|
572
|
-
action: 'client.api',
|
|
573
|
-
payload: {
|
|
574
|
-
event,
|
|
575
|
-
key: String(prop),
|
|
576
|
-
params: args
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
return [client];
|
|
583
|
-
};
|
|
584
|
-
const useGuild = (event) => {
|
|
585
|
-
if (!event || typeof event !== 'object') {
|
|
586
|
-
logger.error({
|
|
587
|
-
code: ResultCode.FailParams,
|
|
588
|
-
message: 'Invalid event: event must be an object',
|
|
589
|
-
data: null
|
|
590
|
-
});
|
|
591
|
-
throw new Error('Invalid event: event must be an object');
|
|
592
|
-
}
|
|
593
|
-
const info = async (params) => {
|
|
594
|
-
const gid = params?.guildId || event.GuildId;
|
|
595
|
-
if (!gid) {
|
|
596
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
597
|
-
}
|
|
598
|
-
try {
|
|
599
|
-
const results = await sendAction({
|
|
600
|
-
action: 'guild.info',
|
|
601
|
-
payload: { GuildId: gid }
|
|
602
|
-
});
|
|
603
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
604
|
-
if (result) {
|
|
605
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved guild info', result.data ?? null);
|
|
606
|
-
}
|
|
607
|
-
return createResult(ResultCode.Warn, 'No guild info found', null);
|
|
608
|
-
}
|
|
609
|
-
catch {
|
|
610
|
-
return createResult(ResultCode.Fail, 'Failed to get guild info', null);
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
const list = async () => {
|
|
614
|
-
try {
|
|
615
|
-
const results = await sendAction({
|
|
616
|
-
action: 'guild.list',
|
|
617
|
-
payload: {}
|
|
618
|
-
});
|
|
619
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
620
|
-
if (result) {
|
|
621
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved guild list', result.data ?? []);
|
|
622
|
-
}
|
|
623
|
-
return createResult(ResultCode.Warn, 'No guild list found', []);
|
|
624
|
-
}
|
|
625
|
-
catch {
|
|
626
|
-
return createResult(ResultCode.Fail, 'Failed to get guild list', []);
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
const guild = {
|
|
630
|
-
info,
|
|
631
|
-
list,
|
|
632
|
-
async update(params) {
|
|
633
|
-
const gid = params.guildId || event.GuildId;
|
|
634
|
-
if (!gid) {
|
|
635
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
636
|
-
}
|
|
637
|
-
try {
|
|
638
|
-
const results = await sendAction({
|
|
639
|
-
action: 'guild.update',
|
|
640
|
-
payload: { GuildId: gid, params: { name: params.name } }
|
|
641
|
-
});
|
|
642
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
643
|
-
return result || createResult(ResultCode.Warn, 'Update not supported or failed', null);
|
|
644
|
-
}
|
|
645
|
-
catch {
|
|
646
|
-
return createResult(ResultCode.Fail, 'Failed to update guild', null);
|
|
647
|
-
}
|
|
648
|
-
},
|
|
649
|
-
async leave(params) {
|
|
650
|
-
const gid = params?.guildId || event.GuildId;
|
|
651
|
-
if (!gid) {
|
|
652
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
653
|
-
}
|
|
654
|
-
try {
|
|
655
|
-
const results = await sendAction({
|
|
656
|
-
action: 'guild.leave',
|
|
657
|
-
payload: { GuildId: gid, params: { isDismiss: params?.isDismiss } }
|
|
658
|
-
});
|
|
659
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
660
|
-
return result || createResult(ResultCode.Warn, 'Leave not supported or failed', null);
|
|
661
|
-
}
|
|
662
|
-
catch {
|
|
663
|
-
return createResult(ResultCode.Fail, 'Failed to leave guild', null);
|
|
664
|
-
}
|
|
665
|
-
},
|
|
666
|
-
async mute(params) {
|
|
667
|
-
const gid = params.guildId || event.GuildId;
|
|
668
|
-
if (!gid) {
|
|
669
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
670
|
-
}
|
|
671
|
-
try {
|
|
672
|
-
const results = await sendAction({
|
|
673
|
-
action: 'guild.mute',
|
|
674
|
-
payload: { GuildId: gid, params: { enable: params.enable } }
|
|
675
|
-
});
|
|
676
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
677
|
-
return result || createResult(ResultCode.Warn, 'Mute not supported or failed', null);
|
|
678
|
-
}
|
|
679
|
-
catch {
|
|
680
|
-
return createResult(ResultCode.Fail, 'Failed to mute guild', null);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
};
|
|
684
|
-
return [guild];
|
|
685
|
-
};
|
|
686
|
-
const useRole = (event) => {
|
|
687
|
-
if (!event || typeof event !== 'object') {
|
|
688
|
-
logger.error({
|
|
689
|
-
code: ResultCode.FailParams,
|
|
690
|
-
message: 'Invalid event: event must be an object',
|
|
691
|
-
data: null
|
|
692
|
-
});
|
|
693
|
-
throw new Error('Invalid event: event must be an object');
|
|
694
|
-
}
|
|
695
|
-
const getGuildId = (guildId) => guildId || event.GuildId;
|
|
696
|
-
const list = async (params) => {
|
|
697
|
-
const gid = getGuildId(params?.guildId);
|
|
698
|
-
if (!gid) {
|
|
699
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', []);
|
|
700
|
-
}
|
|
701
|
-
try {
|
|
702
|
-
const results = await sendAction({
|
|
703
|
-
action: 'role.list',
|
|
704
|
-
payload: { GuildId: gid }
|
|
705
|
-
});
|
|
706
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
707
|
-
if (result) {
|
|
708
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved role list', result.data ?? []);
|
|
709
|
-
}
|
|
710
|
-
return createResult(ResultCode.Warn, 'No role list found', []);
|
|
711
|
-
}
|
|
712
|
-
catch {
|
|
713
|
-
return createResult(ResultCode.Fail, 'Failed to get role list', []);
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
const create = async (params) => {
|
|
717
|
-
const gid = getGuildId(params.guildId);
|
|
718
|
-
if (!gid) {
|
|
719
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
720
|
-
}
|
|
721
|
-
try {
|
|
722
|
-
const results = await sendAction({
|
|
723
|
-
action: 'role.create',
|
|
724
|
-
payload: { GuildId: gid, params: { name: params.name, color: params.color, permissions: params.permissions } }
|
|
725
|
-
});
|
|
726
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
727
|
-
return result ? createResult(ResultCode.Ok, 'Role created', result.data ?? null) : createResult(ResultCode.Warn, 'Create not supported or failed', null);
|
|
728
|
-
}
|
|
729
|
-
catch {
|
|
730
|
-
return createResult(ResultCode.Fail, 'Failed to create role', null);
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
const update = async (params) => {
|
|
734
|
-
const gid = getGuildId(params.guildId);
|
|
735
|
-
if (!gid || !params.roleId) {
|
|
736
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or RoleId', null);
|
|
737
|
-
}
|
|
738
|
-
try {
|
|
739
|
-
const results = await sendAction({
|
|
740
|
-
action: 'role.update',
|
|
741
|
-
payload: { GuildId: gid, RoleId: params.roleId, params: { name: params.name, color: params.color, permissions: params.permissions } }
|
|
742
|
-
});
|
|
743
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
744
|
-
return result || createResult(ResultCode.Warn, 'Update not supported or failed', null);
|
|
745
|
-
}
|
|
746
|
-
catch {
|
|
747
|
-
return createResult(ResultCode.Fail, 'Failed to update role', null);
|
|
748
|
-
}
|
|
749
|
-
};
|
|
750
|
-
const remove = async (params) => {
|
|
751
|
-
const gid = getGuildId(params.guildId);
|
|
752
|
-
if (!gid || !params.roleId) {
|
|
753
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or RoleId', null);
|
|
754
|
-
}
|
|
755
|
-
try {
|
|
756
|
-
const results = await sendAction({
|
|
757
|
-
action: 'role.delete',
|
|
758
|
-
payload: { GuildId: gid, RoleId: params.roleId }
|
|
759
|
-
});
|
|
760
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
761
|
-
return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
|
|
762
|
-
}
|
|
763
|
-
catch {
|
|
764
|
-
return createResult(ResultCode.Fail, 'Failed to delete role', null);
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
const assign = async (params) => {
|
|
768
|
-
const gid = getGuildId(params.guildId);
|
|
769
|
-
if (!gid || !params.userId || !params.roleId) {
|
|
770
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId, UserId or RoleId', null);
|
|
771
|
-
}
|
|
772
|
-
try {
|
|
773
|
-
const results = await sendAction({
|
|
774
|
-
action: 'role.assign',
|
|
775
|
-
payload: { GuildId: gid, UserId: params.userId, RoleId: params.roleId }
|
|
776
|
-
});
|
|
777
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
778
|
-
return result || createResult(ResultCode.Warn, 'Assign not supported or failed', null);
|
|
779
|
-
}
|
|
780
|
-
catch {
|
|
781
|
-
return createResult(ResultCode.Fail, 'Failed to assign role', null);
|
|
782
|
-
}
|
|
783
|
-
};
|
|
784
|
-
const revoke = async (params) => {
|
|
785
|
-
const gid = getGuildId(params.guildId);
|
|
786
|
-
if (!gid || !params.userId || !params.roleId) {
|
|
787
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId, UserId or RoleId', null);
|
|
788
|
-
}
|
|
789
|
-
try {
|
|
790
|
-
const results = await sendAction({
|
|
791
|
-
action: 'role.remove',
|
|
792
|
-
payload: { GuildId: gid, UserId: params.userId, RoleId: params.roleId }
|
|
793
|
-
});
|
|
794
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
795
|
-
return result || createResult(ResultCode.Warn, 'Remove not supported or failed', null);
|
|
796
|
-
}
|
|
797
|
-
catch {
|
|
798
|
-
return createResult(ResultCode.Fail, 'Failed to remove role', null);
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
const role = {
|
|
802
|
-
list,
|
|
803
|
-
create,
|
|
804
|
-
update,
|
|
805
|
-
delete: remove,
|
|
806
|
-
assign,
|
|
807
|
-
remove: revoke
|
|
808
|
-
};
|
|
809
|
-
return [role];
|
|
810
|
-
};
|
|
811
|
-
const useReaction = (event) => {
|
|
812
|
-
if (!event || typeof event !== 'object') {
|
|
813
|
-
logger.error({
|
|
814
|
-
code: ResultCode.FailParams,
|
|
815
|
-
message: 'Invalid event: event must be an object',
|
|
816
|
-
data: null
|
|
817
|
-
});
|
|
818
|
-
throw new Error('Invalid event: event must be an object');
|
|
819
|
-
}
|
|
820
|
-
const add = async (params) => {
|
|
821
|
-
const mid = params.messageId || event.MessageId;
|
|
822
|
-
const cid = event.ChannelId;
|
|
823
|
-
if (!mid || !cid || !params.emojiId) {
|
|
824
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
|
|
825
|
-
}
|
|
826
|
-
try {
|
|
827
|
-
const results = await sendAction({
|
|
828
|
-
action: 'reaction.add',
|
|
829
|
-
payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId }
|
|
830
|
-
});
|
|
831
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
832
|
-
return result || createResult(ResultCode.Warn, 'Reaction add not supported or failed', null);
|
|
833
|
-
}
|
|
834
|
-
catch {
|
|
835
|
-
return createResult(ResultCode.Fail, 'Failed to add reaction', null);
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
const remove = async (params) => {
|
|
839
|
-
const mid = params.messageId || event.MessageId;
|
|
840
|
-
const cid = event.ChannelId;
|
|
841
|
-
if (!mid || !cid || !params.emojiId) {
|
|
842
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
|
|
843
|
-
}
|
|
844
|
-
try {
|
|
845
|
-
const results = await sendAction({
|
|
846
|
-
action: 'reaction.remove',
|
|
847
|
-
payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId }
|
|
848
|
-
});
|
|
849
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
850
|
-
return result || createResult(ResultCode.Warn, 'Reaction remove not supported or failed', null);
|
|
851
|
-
}
|
|
852
|
-
catch {
|
|
853
|
-
return createResult(ResultCode.Fail, 'Failed to remove reaction', null);
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
const list = async (params) => {
|
|
857
|
-
const mid = params.messageId || event.MessageId;
|
|
858
|
-
const cid = event.ChannelId;
|
|
859
|
-
if (!mid || !cid || !params.emojiId) {
|
|
860
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
|
|
861
|
-
}
|
|
862
|
-
try {
|
|
863
|
-
const results = await sendAction({
|
|
864
|
-
action: 'reaction.list',
|
|
865
|
-
payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId, params: { limit: params.limit } }
|
|
866
|
-
});
|
|
867
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
868
|
-
return result || createResult(ResultCode.Warn, 'Reaction list not supported or failed', null);
|
|
869
|
-
}
|
|
870
|
-
catch {
|
|
871
|
-
return createResult(ResultCode.Fail, 'Failed to list reactions', null);
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
const reaction = {
|
|
875
|
-
add,
|
|
876
|
-
remove,
|
|
877
|
-
list
|
|
878
|
-
};
|
|
879
|
-
return [reaction];
|
|
880
|
-
};
|
|
881
|
-
const useMe = () => {
|
|
882
|
-
const info = async () => {
|
|
883
|
-
try {
|
|
884
|
-
const results = await sendAction({
|
|
885
|
-
action: 'me.info',
|
|
886
|
-
payload: {}
|
|
887
|
-
});
|
|
888
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
889
|
-
if (result) {
|
|
890
|
-
const data = result?.data ?? null;
|
|
891
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
892
|
-
}
|
|
893
|
-
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
894
|
-
}
|
|
895
|
-
catch {
|
|
896
|
-
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
const guilds = async () => {
|
|
900
|
-
try {
|
|
901
|
-
const results = await sendAction({
|
|
902
|
-
action: 'me.guilds',
|
|
903
|
-
payload: {}
|
|
904
|
-
});
|
|
905
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
906
|
-
if (result) {
|
|
907
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved guild list', result.data ?? []);
|
|
908
|
-
}
|
|
909
|
-
return createResult(ResultCode.Warn, 'No guild list found', []);
|
|
910
|
-
}
|
|
911
|
-
catch {
|
|
912
|
-
return createResult(ResultCode.Fail, 'Failed to get guild list', []);
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
const threads = async () => {
|
|
916
|
-
try {
|
|
917
|
-
const results = await sendAction({
|
|
918
|
-
action: 'me.threads',
|
|
919
|
-
payload: {}
|
|
920
|
-
});
|
|
921
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
922
|
-
if (result) {
|
|
923
|
-
const data = result?.data ?? null;
|
|
924
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
925
|
-
}
|
|
926
|
-
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
927
|
-
}
|
|
928
|
-
catch {
|
|
929
|
-
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
930
|
-
}
|
|
931
|
-
};
|
|
932
|
-
const friends = async () => {
|
|
933
|
-
try {
|
|
934
|
-
const results = await sendAction({
|
|
935
|
-
action: 'me.friends',
|
|
936
|
-
payload: {}
|
|
937
|
-
});
|
|
938
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
939
|
-
if (result) {
|
|
940
|
-
const data = result?.data ?? null;
|
|
941
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
942
|
-
}
|
|
943
|
-
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
944
|
-
}
|
|
945
|
-
catch {
|
|
946
|
-
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
const control = {
|
|
950
|
-
info,
|
|
951
|
-
guilds,
|
|
952
|
-
threads,
|
|
953
|
-
friends
|
|
954
|
-
};
|
|
955
|
-
return [control];
|
|
956
|
-
};
|
|
957
|
-
const useRequest = () => {
|
|
958
|
-
const friend = async (params) => {
|
|
959
|
-
if (!params.flag) {
|
|
960
|
-
return createResult(ResultCode.FailParams, 'Missing flag', null);
|
|
961
|
-
}
|
|
962
|
-
try {
|
|
963
|
-
const results = await sendAction({
|
|
964
|
-
action: 'request.friend',
|
|
965
|
-
payload: { params: { flag: params.flag, approve: params.approve, remark: params.remark } }
|
|
966
|
-
});
|
|
967
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
968
|
-
return result || createResult(ResultCode.Warn, 'Friend request handling not supported or failed', null);
|
|
969
|
-
}
|
|
970
|
-
catch {
|
|
971
|
-
return createResult(ResultCode.Fail, 'Failed to handle friend request', null);
|
|
972
|
-
}
|
|
973
|
-
};
|
|
974
|
-
const guild = async (params) => {
|
|
975
|
-
if (!params.flag || !params.subType) {
|
|
976
|
-
return createResult(ResultCode.FailParams, 'Missing flag or subType', null);
|
|
977
|
-
}
|
|
978
|
-
try {
|
|
979
|
-
const results = await sendAction({
|
|
980
|
-
action: 'request.guild',
|
|
981
|
-
payload: { params: { flag: params.flag, subType: params.subType, approve: params.approve, reason: params.reason } }
|
|
982
|
-
});
|
|
983
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
984
|
-
return result || createResult(ResultCode.Warn, 'Guild request handling not supported or failed', null);
|
|
985
|
-
}
|
|
986
|
-
catch {
|
|
987
|
-
return createResult(ResultCode.Fail, 'Failed to handle guild request', null);
|
|
988
|
-
}
|
|
989
|
-
};
|
|
990
|
-
const request = {
|
|
991
|
-
friend,
|
|
992
|
-
guild
|
|
993
|
-
};
|
|
994
|
-
return [request];
|
|
995
|
-
};
|
|
996
|
-
const useUser = () => {
|
|
997
|
-
const info = async (params) => {
|
|
998
|
-
if (!params.userId) {
|
|
999
|
-
return createResult(ResultCode.FailParams, 'Missing UserId', null);
|
|
1000
|
-
}
|
|
1001
|
-
try {
|
|
1002
|
-
const results = await sendAction({
|
|
1003
|
-
action: 'user.info',
|
|
1004
|
-
payload: { UserId: params.userId }
|
|
1005
|
-
});
|
|
1006
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1007
|
-
if (result) {
|
|
1008
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved user info', result.data ?? null);
|
|
1009
|
-
}
|
|
1010
|
-
return createResult(ResultCode.Warn, 'No user info found', null);
|
|
1011
|
-
}
|
|
1012
|
-
catch {
|
|
1013
|
-
return createResult(ResultCode.Fail, 'Failed to get user info', null);
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
const user = {
|
|
1017
|
-
info
|
|
1018
|
-
};
|
|
1019
|
-
return [user];
|
|
1020
|
-
};
|
|
1021
|
-
const useMedia = (event) => {
|
|
1022
|
-
if (!event || typeof event !== 'object') {
|
|
1023
|
-
logger.error({
|
|
1024
|
-
code: ResultCode.FailParams,
|
|
1025
|
-
message: 'Invalid event: event must be an object',
|
|
1026
|
-
data: null
|
|
1027
|
-
});
|
|
1028
|
-
throw new Error('Invalid event: event must be an object');
|
|
1029
|
-
}
|
|
1030
|
-
const upload = async (params) => {
|
|
1031
|
-
try {
|
|
1032
|
-
const results = await sendAction({
|
|
1033
|
-
action: 'media.upload',
|
|
1034
|
-
payload: { params }
|
|
1035
|
-
});
|
|
1036
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1037
|
-
return result || createResult(ResultCode.Warn, 'Media upload not supported or failed', null);
|
|
1038
|
-
}
|
|
1039
|
-
catch {
|
|
1040
|
-
return createResult(ResultCode.Fail, 'Failed to upload media', null);
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
const sendChannel = async (params) => {
|
|
1044
|
-
const cid = params.channelId || event.ChannelId;
|
|
1045
|
-
if (!cid) {
|
|
1046
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
|
|
1047
|
-
}
|
|
1048
|
-
try {
|
|
1049
|
-
const results = await sendAction({
|
|
1050
|
-
action: 'media.send.channel',
|
|
1051
|
-
payload: { ChannelId: cid, params: { type: params.type, url: params.url, data: params.data, name: params.name } }
|
|
1052
|
-
});
|
|
1053
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1054
|
-
return result || createResult(ResultCode.Warn, 'Media send not supported or failed', null);
|
|
1055
|
-
}
|
|
1056
|
-
catch {
|
|
1057
|
-
return createResult(ResultCode.Fail, 'Failed to send media to channel', null);
|
|
1058
|
-
}
|
|
1059
|
-
};
|
|
1060
|
-
const sendUser = async (params) => {
|
|
1061
|
-
if (!params.userId) {
|
|
1062
|
-
return createResult(ResultCode.FailParams, 'Missing UserId', null);
|
|
1063
|
-
}
|
|
1064
|
-
try {
|
|
1065
|
-
const results = await sendAction({
|
|
1066
|
-
action: 'media.send.user',
|
|
1067
|
-
payload: { UserId: params.userId, params: { type: params.type, url: params.url, data: params.data, name: params.name } }
|
|
1068
|
-
});
|
|
1069
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1070
|
-
return result || createResult(ResultCode.Warn, 'Media send not supported or failed', null);
|
|
1071
|
-
}
|
|
1072
|
-
catch {
|
|
1073
|
-
return createResult(ResultCode.Fail, 'Failed to send media to user', null);
|
|
1074
|
-
}
|
|
1075
|
-
};
|
|
1076
|
-
const media = {
|
|
1077
|
-
upload,
|
|
1078
|
-
sendChannel,
|
|
1079
|
-
sendUser
|
|
1080
|
-
};
|
|
1081
|
-
return [media];
|
|
1082
|
-
};
|
|
1083
|
-
const useHistory = (event) => {
|
|
1084
|
-
if (!event || typeof event !== 'object') {
|
|
1085
|
-
logger.error({
|
|
1086
|
-
code: ResultCode.FailParams,
|
|
1087
|
-
message: 'Invalid event: event must be an object',
|
|
1088
|
-
data: null
|
|
1089
|
-
});
|
|
1090
|
-
throw new Error('Invalid event: event must be an object');
|
|
1091
|
-
}
|
|
1092
|
-
const list = async (params) => {
|
|
1093
|
-
const cid = params?.channelId || event.ChannelId;
|
|
1094
|
-
if (!cid) {
|
|
1095
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
|
|
1096
|
-
}
|
|
1097
|
-
try {
|
|
1098
|
-
const results = await sendAction({
|
|
1099
|
-
action: 'history.list',
|
|
1100
|
-
payload: { ChannelId: cid, params: { limit: params?.limit, before: params?.before, after: params?.after } }
|
|
1101
|
-
});
|
|
1102
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1103
|
-
return result || createResult(ResultCode.Warn, 'History list not supported or failed', null);
|
|
1104
|
-
}
|
|
1105
|
-
catch {
|
|
1106
|
-
return createResult(ResultCode.Fail, 'Failed to get message history', null);
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
const history = {
|
|
1110
|
-
list
|
|
1111
|
-
};
|
|
1112
|
-
return [history];
|
|
1113
|
-
};
|
|
1114
|
-
const usePermission = (event) => {
|
|
1115
|
-
if (!event || typeof event !== 'object') {
|
|
1116
|
-
logger.error({
|
|
1117
|
-
code: ResultCode.FailParams,
|
|
1118
|
-
message: 'Invalid event: event must be an object',
|
|
1119
|
-
data: null
|
|
1120
|
-
});
|
|
1121
|
-
throw new Error('Invalid event: event must be an object');
|
|
1122
|
-
}
|
|
1123
|
-
const get = async (params) => {
|
|
1124
|
-
const cid = params.channelId || event.ChannelId;
|
|
1125
|
-
if (!cid || !params.userId) {
|
|
1126
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId or UserId', null);
|
|
1127
|
-
}
|
|
1128
|
-
try {
|
|
1129
|
-
const results = await sendAction({
|
|
1130
|
-
action: 'permission.get',
|
|
1131
|
-
payload: { ChannelId: cid, UserId: params.userId }
|
|
1132
|
-
});
|
|
1133
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1134
|
-
return result || createResult(ResultCode.Warn, 'Permission get not supported or failed', null);
|
|
1135
|
-
}
|
|
1136
|
-
catch {
|
|
1137
|
-
return createResult(ResultCode.Fail, 'Failed to get permission', null);
|
|
1138
|
-
}
|
|
1139
|
-
};
|
|
1140
|
-
const set = async (params) => {
|
|
1141
|
-
const cid = params.channelId || event.ChannelId;
|
|
1142
|
-
if (!cid || !params.userId) {
|
|
1143
|
-
return createResult(ResultCode.FailParams, 'Missing ChannelId or UserId', null);
|
|
1144
|
-
}
|
|
1145
|
-
try {
|
|
1146
|
-
const results = await sendAction({
|
|
1147
|
-
action: 'permission.set',
|
|
1148
|
-
payload: { ChannelId: cid, UserId: params.userId, params: { allow: params.allow, deny: params.deny } }
|
|
1149
|
-
});
|
|
1150
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1151
|
-
return result || createResult(ResultCode.Warn, 'Permission set not supported or failed', null);
|
|
1152
|
-
}
|
|
1153
|
-
catch {
|
|
1154
|
-
return createResult(ResultCode.Fail, 'Failed to set permission', null);
|
|
1155
|
-
}
|
|
1156
|
-
};
|
|
1157
|
-
const permission = {
|
|
1158
|
-
get,
|
|
1159
|
-
set
|
|
1160
|
-
};
|
|
1161
|
-
return [permission];
|
|
1162
|
-
};
|
|
1163
|
-
const useAnnounce = (event) => {
|
|
1164
|
-
if (!event || typeof event !== 'object') {
|
|
1165
|
-
logger.error({
|
|
1166
|
-
code: ResultCode.FailParams,
|
|
1167
|
-
message: 'Invalid event: event must be an object',
|
|
1168
|
-
data: null
|
|
1169
|
-
});
|
|
1170
|
-
throw new Error('Invalid event: event must be an object');
|
|
1171
|
-
}
|
|
1172
|
-
const set = async (params) => {
|
|
1173
|
-
const gid = params.guildId || event.GuildId;
|
|
1174
|
-
if (!gid || !params.messageId) {
|
|
1175
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId or MessageId', null);
|
|
1176
|
-
}
|
|
1177
|
-
try {
|
|
1178
|
-
const results = await sendAction({
|
|
1179
|
-
action: 'channel.announce',
|
|
1180
|
-
payload: { GuildId: gid, params: { messageId: params.messageId, channelId: params.channelId } }
|
|
1181
|
-
});
|
|
1182
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1183
|
-
return result || createResult(ResultCode.Warn, 'Announce set not supported or failed', null);
|
|
1184
|
-
}
|
|
1185
|
-
catch {
|
|
1186
|
-
return createResult(ResultCode.Fail, 'Failed to set announcement', null);
|
|
1187
|
-
}
|
|
1188
|
-
};
|
|
1189
|
-
const remove = async (params) => {
|
|
1190
|
-
const gid = params?.guildId || event.GuildId;
|
|
1191
|
-
if (!gid) {
|
|
1192
|
-
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
1193
|
-
}
|
|
1194
|
-
try {
|
|
1195
|
-
const results = await sendAction({
|
|
1196
|
-
action: 'channel.announce',
|
|
1197
|
-
payload: { GuildId: gid, params: { messageId: params?.messageId || 'all', remove: true } }
|
|
1198
|
-
});
|
|
1199
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
1200
|
-
return result || createResult(ResultCode.Warn, 'Announce remove not supported or failed', null);
|
|
1201
|
-
}
|
|
1202
|
-
catch {
|
|
1203
|
-
return createResult(ResultCode.Fail, 'Failed to remove announcement', null);
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
const announce = {
|
|
1207
|
-
set,
|
|
1208
|
-
remove
|
|
1209
|
-
};
|
|
1210
|
-
return [announce];
|
|
1211
|
-
};
|
|
1212
|
-
|
|
1213
|
-
export { createSelects, onSelects, unChildren, useAnnounce, useChannel, useClient, useGuild, useHistory, useMe, useMedia, useMember, useMention, useMessage, usePermission, useReaction, useRequest, useRole, useSend, useSends, useUser };
|