alemonjs 2.1.48 → 2.1.49
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/event-processor-callHandler.js +3 -2
- package/lib/app/event-processor-cycleFiles.js +1 -1
- package/lib/app/event-utils.d.ts +14 -0
- package/lib/app/event-utils.js +86 -0
- package/lib/app/hook-event-context.d.ts +3 -0
- package/lib/app/hook-event-context.js +11 -0
- package/lib/app/hook-use/announce.d.ts +12 -0
- package/lib/app/hook-use/announce.js +49 -0
- package/lib/app/hook-use/channel.d.ts +24 -0
- package/lib/app/hook-use/channel.js +109 -0
- package/lib/app/hook-use/client.d.ts +2 -0
- package/lib/app/hook-use/client.js +49 -0
- package/lib/app/hook-use/common.d.ts +18 -0
- package/lib/app/hook-use/common.js +22 -0
- package/lib/app/hook-use/guild.d.ts +19 -0
- package/lib/app/hook-use/guild.js +102 -0
- package/lib/app/hook-use/history.d.ts +9 -0
- package/lib/app/hook-use/history.js +31 -0
- package/lib/app/hook-use/index.d.ts +15 -0
- package/lib/app/hook-use/index.js +15 -0
- package/lib/app/hook-use/me.d.ts +7 -0
- package/lib/app/hook-use/me.js +90 -0
- package/lib/app/hook-use/media.d.ts +23 -0
- package/lib/app/hook-use/media.js +62 -0
- package/lib/app/hook-use/member.d.ts +54 -0
- package/lib/app/hook-use/member.js +200 -0
- package/lib/app/hook-use/mention.d.ts +9 -0
- package/lib/app/hook-use/mention.js +88 -0
- package/lib/app/hook-use/message.d.ts +28 -0
- package/lib/app/hook-use/message.js +142 -0
- package/lib/app/hook-use/permission.d.ts +13 -0
- package/lib/app/hook-use/permission.js +49 -0
- package/lib/app/hook-use/reaction.d.ts +16 -0
- package/lib/app/hook-use/reaction.js +70 -0
- package/lib/app/hook-use/request.d.ts +14 -0
- package/lib/app/hook-use/request.js +53 -0
- package/lib/app/hook-use/role.d.ts +33 -0
- package/lib/app/hook-use/role.js +125 -0
- package/lib/app/hook-use/user.d.ts +6 -0
- package/lib/app/hook-use/user.js +39 -0
- package/lib/app/hook-use-api.d.ts +3 -3
- package/lib/app/hook-use-api.js +16 -13
- package/lib/app/hook-use-subscribe.d.ts +61 -20
- package/lib/app/hook-use-subscribe.js +21 -7
- package/lib/app/index.d.ts +3 -2
- package/lib/app/index.js +18 -3
- package/lib/app/message-api.d.ts +0 -6
- package/lib/app/message-api.js +1 -4
- package/lib/app/message-format.js +1 -1
- package/lib/cbp/connects/client.js +5 -4
- package/lib/client.js +3 -2
- package/lib/index.js +18 -3
- package/package.json +3 -3
- package/LICENSE +0 -21
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { getEventOrThrow } from './common.js';
|
|
2
|
+
import { createResult } from '../../core/utils.js';
|
|
3
|
+
import { ResultCode } from '../../core/variable.js';
|
|
4
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
|
+
import { Format } from '../message-format.js';
|
|
6
|
+
|
|
7
|
+
const useMessage = (event) => {
|
|
8
|
+
const valueEvent = getEventOrThrow(event);
|
|
9
|
+
const resolveFormat = (params) => {
|
|
10
|
+
if (params.format instanceof Format) {
|
|
11
|
+
return params.format.value;
|
|
12
|
+
}
|
|
13
|
+
return params.format;
|
|
14
|
+
};
|
|
15
|
+
const sendRaw = async (val, replyId) => {
|
|
16
|
+
if (!val || val.length === 0) {
|
|
17
|
+
return [createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)];
|
|
18
|
+
}
|
|
19
|
+
const result = await sendAction({
|
|
20
|
+
action: 'message.send',
|
|
21
|
+
payload: {
|
|
22
|
+
event: valueEvent,
|
|
23
|
+
params: {
|
|
24
|
+
format: val,
|
|
25
|
+
replyId
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return Array.isArray(result) ? result : [result];
|
|
30
|
+
};
|
|
31
|
+
const lightweight = {
|
|
32
|
+
send(params) {
|
|
33
|
+
if (Array.isArray(params)) {
|
|
34
|
+
return sendRaw(params.length > 0 ? params : []);
|
|
35
|
+
}
|
|
36
|
+
return sendRaw(resolveFormat(params), params?.replyId ?? valueEvent.MessageId);
|
|
37
|
+
},
|
|
38
|
+
async delete(params) {
|
|
39
|
+
const targetId = params?.messageId || valueEvent.MessageId;
|
|
40
|
+
if (!targetId) {
|
|
41
|
+
return createResult(ResultCode.FailParams, 'Missing MessageId', null);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const results = await sendAction({
|
|
45
|
+
action: 'message.delete',
|
|
46
|
+
payload: { MessageId: targetId, ChannelId: valueEvent.ChannelId, event: valueEvent }
|
|
47
|
+
});
|
|
48
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
49
|
+
return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return createResult(ResultCode.Fail, 'Failed to delete message', null);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
async edit(params) {
|
|
56
|
+
const targetId = params.messageId || valueEvent.MessageId;
|
|
57
|
+
const channelId = valueEvent.ChannelId;
|
|
58
|
+
if (!targetId || !channelId) {
|
|
59
|
+
return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const val = params.format instanceof Format ? params.format.value : params.format;
|
|
63
|
+
const results = await sendAction({
|
|
64
|
+
action: 'message.edit',
|
|
65
|
+
payload: { ChannelId: channelId, MessageId: targetId, params: { format: val }, event: valueEvent }
|
|
66
|
+
});
|
|
67
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
68
|
+
return result || createResult(ResultCode.Warn, 'Edit not supported or failed', null);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return createResult(ResultCode.Fail, 'Failed to edit message', null);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
async pin(params) {
|
|
75
|
+
const targetId = params?.messageId || valueEvent.MessageId;
|
|
76
|
+
const channelId = valueEvent.ChannelId;
|
|
77
|
+
if (!targetId || !channelId) {
|
|
78
|
+
return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const results = await sendAction({
|
|
82
|
+
action: 'message.pin',
|
|
83
|
+
payload: { ChannelId: channelId, MessageId: targetId }
|
|
84
|
+
});
|
|
85
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
86
|
+
return result || createResult(ResultCode.Warn, 'Pin not supported or failed', null);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return createResult(ResultCode.Fail, 'Failed to pin message', null);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
async unpin(params) {
|
|
93
|
+
const targetId = params?.messageId || valueEvent.MessageId;
|
|
94
|
+
const channelId = valueEvent.ChannelId;
|
|
95
|
+
if (!targetId || !channelId) {
|
|
96
|
+
return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const results = await sendAction({
|
|
100
|
+
action: 'message.unpin',
|
|
101
|
+
payload: { ChannelId: channelId, MessageId: targetId }
|
|
102
|
+
});
|
|
103
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
104
|
+
return result || createResult(ResultCode.Warn, 'Unpin not supported or failed', null);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return createResult(ResultCode.Fail, 'Failed to unpin message', null);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
async get(params) {
|
|
111
|
+
const targetId = params?.messageId || valueEvent.MessageId;
|
|
112
|
+
if (!targetId) {
|
|
113
|
+
return createResult(ResultCode.FailParams, 'Missing MessageId', null);
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const results = await sendAction({
|
|
117
|
+
action: 'message.get',
|
|
118
|
+
payload: { MessageId: targetId }
|
|
119
|
+
});
|
|
120
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
121
|
+
return result || createResult(ResultCode.Warn, 'Get message not supported or failed', null);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return createResult(ResultCode.Fail, 'Failed to get message', null);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return [lightweight];
|
|
129
|
+
};
|
|
130
|
+
const useSend = (event) => {
|
|
131
|
+
const [message] = useMessage(event);
|
|
132
|
+
const send = (...val) => {
|
|
133
|
+
return message.send(val);
|
|
134
|
+
};
|
|
135
|
+
return send;
|
|
136
|
+
};
|
|
137
|
+
const useSends = (event) => {
|
|
138
|
+
const [message] = useMessage(event);
|
|
139
|
+
return [message.send];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export { useMessage, useSend, useSends };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventKeys, Events, Result } from './common';
|
|
2
|
+
export declare const usePermission: <T extends EventKeys>(event?: Events[T]) => readonly [{
|
|
3
|
+
get: (params: {
|
|
4
|
+
userId: string;
|
|
5
|
+
channelId?: string;
|
|
6
|
+
}) => Promise<Result>;
|
|
7
|
+
set: (params: {
|
|
8
|
+
userId: string;
|
|
9
|
+
allow?: string;
|
|
10
|
+
deny?: string;
|
|
11
|
+
channelId?: string;
|
|
12
|
+
}) => Promise<Result>;
|
|
13
|
+
}];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getEventOrThrow } from './common.js';
|
|
2
|
+
import { createResult } from '../../core/utils.js';
|
|
3
|
+
import { ResultCode } from '../../core/variable.js';
|
|
4
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
|
+
|
|
6
|
+
const usePermission = (event) => {
|
|
7
|
+
const valueEvent = getEventOrThrow(event);
|
|
8
|
+
const get = async (params) => {
|
|
9
|
+
const cid = params.channelId || valueEvent.ChannelId;
|
|
10
|
+
if (!cid || !params.userId) {
|
|
11
|
+
return createResult(ResultCode.FailParams, 'Missing ChannelId or UserId', null);
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const results = await sendAction({
|
|
15
|
+
action: 'permission.get',
|
|
16
|
+
payload: { ChannelId: cid, UserId: params.userId }
|
|
17
|
+
});
|
|
18
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
19
|
+
return result || createResult(ResultCode.Warn, 'Permission get not supported or failed', null);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return createResult(ResultCode.Fail, 'Failed to get permission', null);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const set = async (params) => {
|
|
26
|
+
const cid = params.channelId || valueEvent.ChannelId;
|
|
27
|
+
if (!cid || !params.userId) {
|
|
28
|
+
return createResult(ResultCode.FailParams, 'Missing ChannelId or UserId', null);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const results = await sendAction({
|
|
32
|
+
action: 'permission.set',
|
|
33
|
+
payload: { ChannelId: cid, UserId: params.userId, params: { allow: params.allow, deny: params.deny } }
|
|
34
|
+
});
|
|
35
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
36
|
+
return result || createResult(ResultCode.Warn, 'Permission set not supported or failed', null);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return createResult(ResultCode.Fail, 'Failed to set permission', null);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const permission = {
|
|
43
|
+
get,
|
|
44
|
+
set
|
|
45
|
+
};
|
|
46
|
+
return [permission];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { usePermission };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EventKeys, Events, Result } from './common';
|
|
2
|
+
export declare const useReaction: <T extends EventKeys>(event?: Events[T]) => readonly [{
|
|
3
|
+
add: (params: {
|
|
4
|
+
emojiId: string;
|
|
5
|
+
messageId?: string;
|
|
6
|
+
}) => Promise<Result>;
|
|
7
|
+
remove: (params: {
|
|
8
|
+
emojiId: string;
|
|
9
|
+
messageId?: string;
|
|
10
|
+
}) => Promise<Result>;
|
|
11
|
+
list: (params: {
|
|
12
|
+
emojiId: string;
|
|
13
|
+
messageId?: string;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}) => Promise<Result>;
|
|
16
|
+
}];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getEventOrThrow } from './common.js';
|
|
2
|
+
import { createResult } from '../../core/utils.js';
|
|
3
|
+
import { ResultCode } from '../../core/variable.js';
|
|
4
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
|
+
|
|
6
|
+
const useReaction = (event) => {
|
|
7
|
+
const valueEvent = getEventOrThrow(event);
|
|
8
|
+
const add = async (params) => {
|
|
9
|
+
const mid = params.messageId || valueEvent.MessageId;
|
|
10
|
+
const cid = valueEvent.ChannelId;
|
|
11
|
+
if (!mid || !cid || !params.emojiId) {
|
|
12
|
+
return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const results = await sendAction({
|
|
16
|
+
action: 'reaction.add',
|
|
17
|
+
payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId }
|
|
18
|
+
});
|
|
19
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
20
|
+
return result || createResult(ResultCode.Warn, 'Reaction add not supported or failed', null);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return createResult(ResultCode.Fail, 'Failed to add reaction', null);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const remove = async (params) => {
|
|
27
|
+
const mid = params.messageId || valueEvent.MessageId;
|
|
28
|
+
const cid = valueEvent.ChannelId;
|
|
29
|
+
if (!mid || !cid || !params.emojiId) {
|
|
30
|
+
return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const results = await sendAction({
|
|
34
|
+
action: 'reaction.remove',
|
|
35
|
+
payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId }
|
|
36
|
+
});
|
|
37
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
38
|
+
return result || createResult(ResultCode.Warn, 'Reaction remove not supported or failed', null);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return createResult(ResultCode.Fail, 'Failed to remove reaction', null);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const list = async (params) => {
|
|
45
|
+
const mid = params.messageId || valueEvent.MessageId;
|
|
46
|
+
const cid = valueEvent.ChannelId;
|
|
47
|
+
if (!mid || !cid || !params.emojiId) {
|
|
48
|
+
return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const results = await sendAction({
|
|
52
|
+
action: 'reaction.list',
|
|
53
|
+
payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId, params: { limit: params.limit } }
|
|
54
|
+
});
|
|
55
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
56
|
+
return result || createResult(ResultCode.Warn, 'Reaction list not supported or failed', null);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return createResult(ResultCode.Fail, 'Failed to list reactions', null);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const reaction = {
|
|
63
|
+
add,
|
|
64
|
+
remove,
|
|
65
|
+
list
|
|
66
|
+
};
|
|
67
|
+
return [reaction];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { useReaction };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Result } from './common';
|
|
2
|
+
export declare const useRequest: () => readonly [{
|
|
3
|
+
friend: (params: {
|
|
4
|
+
flag: string;
|
|
5
|
+
approve: boolean;
|
|
6
|
+
remark?: string;
|
|
7
|
+
}) => Promise<Result>;
|
|
8
|
+
guild: (params: {
|
|
9
|
+
flag: string;
|
|
10
|
+
subType: string;
|
|
11
|
+
approve: boolean;
|
|
12
|
+
reason?: string;
|
|
13
|
+
}) => Promise<Result>;
|
|
14
|
+
}];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ResultCode } from '../../core/variable.js';
|
|
2
|
+
import '../store.js';
|
|
3
|
+
import { createResult } from '../../core/utils.js';
|
|
4
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
|
+
import 'fs';
|
|
6
|
+
import 'path';
|
|
7
|
+
import 'yaml';
|
|
8
|
+
import '../../cbp/processor/config.js';
|
|
9
|
+
import 'flatted';
|
|
10
|
+
import '../message-format-old.js';
|
|
11
|
+
import '../hook-event-context.js';
|
|
12
|
+
|
|
13
|
+
const useRequest = () => {
|
|
14
|
+
const friend = async (params) => {
|
|
15
|
+
if (!params.flag) {
|
|
16
|
+
return createResult(ResultCode.FailParams, 'Missing flag', null);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const results = await sendAction({
|
|
20
|
+
action: 'request.friend',
|
|
21
|
+
payload: { params: { flag: params.flag, approve: params.approve, remark: params.remark } }
|
|
22
|
+
});
|
|
23
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
24
|
+
return result || createResult(ResultCode.Warn, 'Friend request handling not supported or failed', null);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return createResult(ResultCode.Fail, 'Failed to handle friend request', null);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const guild = async (params) => {
|
|
31
|
+
if (!params.flag || !params.subType) {
|
|
32
|
+
return createResult(ResultCode.FailParams, 'Missing flag or subType', null);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const results = await sendAction({
|
|
36
|
+
action: 'request.guild',
|
|
37
|
+
payload: { params: { flag: params.flag, subType: params.subType, approve: params.approve, reason: params.reason } }
|
|
38
|
+
});
|
|
39
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
40
|
+
return result || createResult(ResultCode.Warn, 'Guild request handling not supported or failed', null);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return createResult(ResultCode.Fail, 'Failed to handle guild request', null);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const request = {
|
|
47
|
+
friend,
|
|
48
|
+
guild
|
|
49
|
+
};
|
|
50
|
+
return [request];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { useRequest };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventKeys, Events, Result, RoleInfo } from './common';
|
|
2
|
+
export declare const useRole: <T extends EventKeys>(event?: Events[T]) => readonly [{
|
|
3
|
+
list: (params?: {
|
|
4
|
+
guildId?: string;
|
|
5
|
+
}) => Promise<Result<RoleInfo[]>>;
|
|
6
|
+
create: (params: {
|
|
7
|
+
name: string;
|
|
8
|
+
color?: number;
|
|
9
|
+
permissions?: string;
|
|
10
|
+
guildId?: string;
|
|
11
|
+
}) => Promise<Result<RoleInfo | null>>;
|
|
12
|
+
update: (params: {
|
|
13
|
+
roleId: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
color?: number;
|
|
16
|
+
permissions?: string;
|
|
17
|
+
guildId?: string;
|
|
18
|
+
}) => Promise<Result>;
|
|
19
|
+
delete: (params: {
|
|
20
|
+
roleId: string;
|
|
21
|
+
guildId?: string;
|
|
22
|
+
}) => Promise<Result>;
|
|
23
|
+
assign: (params: {
|
|
24
|
+
userId: string;
|
|
25
|
+
roleId: string;
|
|
26
|
+
guildId?: string;
|
|
27
|
+
}) => Promise<Result>;
|
|
28
|
+
remove: (params: {
|
|
29
|
+
userId: string;
|
|
30
|
+
roleId: string;
|
|
31
|
+
guildId?: string;
|
|
32
|
+
}) => Promise<Result>;
|
|
33
|
+
}];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getEventOrThrow } from './common.js';
|
|
2
|
+
import { createResult } from '../../core/utils.js';
|
|
3
|
+
import { ResultCode } from '../../core/variable.js';
|
|
4
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
|
+
|
|
6
|
+
const useRole = (event) => {
|
|
7
|
+
const valueEvent = getEventOrThrow(event);
|
|
8
|
+
const getGuildId = (guildId) => guildId || valueEvent.GuildId;
|
|
9
|
+
const list = async (params) => {
|
|
10
|
+
const gid = getGuildId(params?.guildId);
|
|
11
|
+
if (!gid) {
|
|
12
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId', []);
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const results = await sendAction({
|
|
16
|
+
action: 'role.list',
|
|
17
|
+
payload: { GuildId: gid }
|
|
18
|
+
});
|
|
19
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
20
|
+
if (result) {
|
|
21
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved role list', result.data ?? []);
|
|
22
|
+
}
|
|
23
|
+
return createResult(ResultCode.Warn, 'No role list found', []);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return createResult(ResultCode.Fail, 'Failed to get role list', []);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const create = async (params) => {
|
|
30
|
+
const gid = getGuildId(params.guildId);
|
|
31
|
+
if (!gid) {
|
|
32
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId', null);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const results = await sendAction({
|
|
36
|
+
action: 'role.create',
|
|
37
|
+
payload: { GuildId: gid, params: { name: params.name, color: params.color, permissions: params.permissions } }
|
|
38
|
+
});
|
|
39
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
40
|
+
return result ? createResult(ResultCode.Ok, 'Role created', result.data ?? null) : createResult(ResultCode.Warn, 'Create not supported or failed', null);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return createResult(ResultCode.Fail, 'Failed to create role', null);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const update = async (params) => {
|
|
47
|
+
const gid = getGuildId(params.guildId);
|
|
48
|
+
if (!gid || !params.roleId) {
|
|
49
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or RoleId', null);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const results = await sendAction({
|
|
53
|
+
action: 'role.update',
|
|
54
|
+
payload: { GuildId: gid, RoleId: params.roleId, params: { name: params.name, color: params.color, permissions: params.permissions } }
|
|
55
|
+
});
|
|
56
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
57
|
+
return result || createResult(ResultCode.Warn, 'Update not supported or failed', null);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return createResult(ResultCode.Fail, 'Failed to update role', null);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const remove = async (params) => {
|
|
64
|
+
const gid = getGuildId(params.guildId);
|
|
65
|
+
if (!gid || !params.roleId) {
|
|
66
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or RoleId', null);
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const results = await sendAction({
|
|
70
|
+
action: 'role.delete',
|
|
71
|
+
payload: { GuildId: gid, RoleId: params.roleId }
|
|
72
|
+
});
|
|
73
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
74
|
+
return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return createResult(ResultCode.Fail, 'Failed to delete role', null);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const assign = async (params) => {
|
|
81
|
+
const gid = getGuildId(params.guildId);
|
|
82
|
+
if (!gid || !params.userId || !params.roleId) {
|
|
83
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId, UserId or RoleId', null);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const results = await sendAction({
|
|
87
|
+
action: 'role.assign',
|
|
88
|
+
payload: { GuildId: gid, UserId: params.userId, RoleId: params.roleId }
|
|
89
|
+
});
|
|
90
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
91
|
+
return result || createResult(ResultCode.Warn, 'Assign not supported or failed', null);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return createResult(ResultCode.Fail, 'Failed to assign role', null);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const revoke = async (params) => {
|
|
98
|
+
const gid = getGuildId(params.guildId);
|
|
99
|
+
if (!gid || !params.userId || !params.roleId) {
|
|
100
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId, UserId or RoleId', null);
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const results = await sendAction({
|
|
104
|
+
action: 'role.remove',
|
|
105
|
+
payload: { GuildId: gid, UserId: params.userId, RoleId: params.roleId }
|
|
106
|
+
});
|
|
107
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
108
|
+
return result || createResult(ResultCode.Warn, 'Remove not supported or failed', null);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return createResult(ResultCode.Fail, 'Failed to remove role', null);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const role = {
|
|
115
|
+
list,
|
|
116
|
+
create,
|
|
117
|
+
update,
|
|
118
|
+
delete: remove,
|
|
119
|
+
assign,
|
|
120
|
+
remove: revoke
|
|
121
|
+
};
|
|
122
|
+
return [role];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export { useRole };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ResultCode } from '../../core/variable.js';
|
|
2
|
+
import '../store.js';
|
|
3
|
+
import { createResult } from '../../core/utils.js';
|
|
4
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
|
+
import 'fs';
|
|
6
|
+
import 'path';
|
|
7
|
+
import 'yaml';
|
|
8
|
+
import '../../cbp/processor/config.js';
|
|
9
|
+
import 'flatted';
|
|
10
|
+
import '../message-format-old.js';
|
|
11
|
+
import '../hook-event-context.js';
|
|
12
|
+
|
|
13
|
+
const useUser = () => {
|
|
14
|
+
const info = async (params) => {
|
|
15
|
+
if (!params.userId) {
|
|
16
|
+
return createResult(ResultCode.FailParams, 'Missing UserId', null);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const results = await sendAction({
|
|
20
|
+
action: 'user.info',
|
|
21
|
+
payload: { UserId: params.userId }
|
|
22
|
+
});
|
|
23
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
24
|
+
if (result) {
|
|
25
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved user info', result.data ?? null);
|
|
26
|
+
}
|
|
27
|
+
return createResult(ResultCode.Warn, 'No user info found', null);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return createResult(ResultCode.Fail, 'Failed to get user info', null);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const user = {
|
|
34
|
+
info
|
|
35
|
+
};
|
|
36
|
+
return [user];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { useUser };
|
|
@@ -16,7 +16,7 @@ export declare const useMention: <T extends EventKeys>(event: Events[T]) => [{
|
|
|
16
16
|
count: number;
|
|
17
17
|
}>;
|
|
18
18
|
}];
|
|
19
|
-
export declare const useMessage: <T extends EventKeys>(event
|
|
19
|
+
export declare const useMessage: <T extends EventKeys>(event?: Events[T]) => readonly [{
|
|
20
20
|
send(params?: {
|
|
21
21
|
format: Format | DataEnums[];
|
|
22
22
|
replyId?: string;
|
|
@@ -114,8 +114,8 @@ export declare const useChannel: <T extends EventKeys>(event: Events[T]) => read
|
|
|
114
114
|
channelId: string;
|
|
115
115
|
}) => Promise<Result>;
|
|
116
116
|
}];
|
|
117
|
-
export declare const useSend: <T extends EventKeys>(event
|
|
118
|
-
export declare const useSends: <T extends EventKeys>(event
|
|
117
|
+
export declare const useSend: <T extends EventKeys>(event?: Events[T]) => (...val: DataEnums[]) => Promise<Result[]>;
|
|
118
|
+
export declare const useSends: <T extends EventKeys>(event?: Events[T]) => readonly [(params?: DataEnums[] | {
|
|
119
119
|
format: Format | DataEnums[];
|
|
120
120
|
replyId?: string;
|
|
121
121
|
}) => Promise<Result[]>];
|