alemonjs 2.1.47 → 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-processor.js +13 -13
- 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-old.d.ts +2 -2
- package/lib/app/message-format.js +1 -1
- package/lib/cbp/connects/client.js +5 -4
- package/lib/client.js +3 -2
- package/lib/core/config.d.ts +37 -0
- package/lib/core/index.js +1 -1
- package/lib/core/utils.d.ts +2 -1
- package/lib/core/utils.js +12 -9
- package/lib/global.d.ts +3 -1
- package/lib/index.js +19 -4
- package/lib/types/message/markdown.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './announce';
|
|
2
|
+
export * from './channel';
|
|
3
|
+
export * from './client';
|
|
4
|
+
export * from './guild';
|
|
5
|
+
export * from './history';
|
|
6
|
+
export * from './media';
|
|
7
|
+
export * from './me';
|
|
8
|
+
export * from './member';
|
|
9
|
+
export * from './mention';
|
|
10
|
+
export * from './message';
|
|
11
|
+
export * from './permission';
|
|
12
|
+
export * from './reaction';
|
|
13
|
+
export * from './request';
|
|
14
|
+
export * from './role';
|
|
15
|
+
export * from './user';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { useAnnounce } from './announce.js';
|
|
2
|
+
export { useChannel } from './channel.js';
|
|
3
|
+
export { useClient } from './client.js';
|
|
4
|
+
export { useGuild } from './guild.js';
|
|
5
|
+
export { useHistory } from './history.js';
|
|
6
|
+
export { useMedia } from './media.js';
|
|
7
|
+
export { useMe } from './me.js';
|
|
8
|
+
export { useMember } from './member.js';
|
|
9
|
+
export { useMention } from './mention.js';
|
|
10
|
+
export { useMessage, useSend, useSends } from './message.js';
|
|
11
|
+
export { usePermission } from './permission.js';
|
|
12
|
+
export { useReaction } from './reaction.js';
|
|
13
|
+
export { useRequest } from './request.js';
|
|
14
|
+
export { useRole } from './role.js';
|
|
15
|
+
export { useUser } from './user.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GuildInfo, Result, User } from './common';
|
|
2
|
+
export declare const useMe: () => readonly [{
|
|
3
|
+
info: () => Promise<Result<User | null>>;
|
|
4
|
+
guilds: () => Promise<Result<GuildInfo[]>>;
|
|
5
|
+
threads: () => Promise<Result<User | null>>;
|
|
6
|
+
friends: () => Promise<Result<User | null>>;
|
|
7
|
+
}];
|
|
@@ -0,0 +1,90 @@
|
|
|
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 useMe = () => {
|
|
14
|
+
const info = async () => {
|
|
15
|
+
try {
|
|
16
|
+
const results = await sendAction({
|
|
17
|
+
action: 'me.info',
|
|
18
|
+
payload: {}
|
|
19
|
+
});
|
|
20
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
21
|
+
if (result) {
|
|
22
|
+
const data = result?.data ?? null;
|
|
23
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
24
|
+
}
|
|
25
|
+
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const guilds = async () => {
|
|
32
|
+
try {
|
|
33
|
+
const results = await sendAction({
|
|
34
|
+
action: 'me.guilds',
|
|
35
|
+
payload: {}
|
|
36
|
+
});
|
|
37
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
38
|
+
if (result) {
|
|
39
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved guild list', result.data ?? []);
|
|
40
|
+
}
|
|
41
|
+
return createResult(ResultCode.Warn, 'No guild list found', []);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return createResult(ResultCode.Fail, 'Failed to get guild list', []);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const threads = async () => {
|
|
48
|
+
try {
|
|
49
|
+
const results = await sendAction({
|
|
50
|
+
action: 'me.threads',
|
|
51
|
+
payload: {}
|
|
52
|
+
});
|
|
53
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
54
|
+
if (result) {
|
|
55
|
+
const data = result?.data ?? null;
|
|
56
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
57
|
+
}
|
|
58
|
+
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const friends = async () => {
|
|
65
|
+
try {
|
|
66
|
+
const results = await sendAction({
|
|
67
|
+
action: 'me.friends',
|
|
68
|
+
payload: {}
|
|
69
|
+
});
|
|
70
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
71
|
+
if (result) {
|
|
72
|
+
const data = result?.data ?? null;
|
|
73
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
74
|
+
}
|
|
75
|
+
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const control = {
|
|
82
|
+
info,
|
|
83
|
+
guilds,
|
|
84
|
+
threads,
|
|
85
|
+
friends
|
|
86
|
+
};
|
|
87
|
+
return [control];
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export { useMe };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventKeys, Events, Result } from './common';
|
|
2
|
+
export declare const useMedia: <T extends EventKeys>(event?: Events[T]) => readonly [{
|
|
3
|
+
upload: (params: {
|
|
4
|
+
type: "image" | "audio" | "video" | "file";
|
|
5
|
+
url?: string;
|
|
6
|
+
data?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
}) => Promise<Result>;
|
|
9
|
+
sendChannel: (params: {
|
|
10
|
+
type: "image" | "audio" | "video" | "file";
|
|
11
|
+
url?: string;
|
|
12
|
+
data?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
channelId?: string;
|
|
15
|
+
}) => Promise<Result>;
|
|
16
|
+
sendUser: (params: {
|
|
17
|
+
userId: string;
|
|
18
|
+
type: "image" | "audio" | "video" | "file";
|
|
19
|
+
url?: string;
|
|
20
|
+
data?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
}) => Promise<Result>;
|
|
23
|
+
}];
|
|
@@ -0,0 +1,62 @@
|
|
|
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 useMedia = (event) => {
|
|
7
|
+
const valueEvent = getEventOrThrow(event);
|
|
8
|
+
const upload = async (params) => {
|
|
9
|
+
try {
|
|
10
|
+
const results = await sendAction({
|
|
11
|
+
action: 'media.upload',
|
|
12
|
+
payload: { params }
|
|
13
|
+
});
|
|
14
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
15
|
+
return result || createResult(ResultCode.Warn, 'Media upload not supported or failed', null);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return createResult(ResultCode.Fail, 'Failed to upload media', null);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const sendChannel = async (params) => {
|
|
22
|
+
const cid = params.channelId || valueEvent.ChannelId;
|
|
23
|
+
if (!cid) {
|
|
24
|
+
return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const results = await sendAction({
|
|
28
|
+
action: 'media.send.channel',
|
|
29
|
+
payload: { ChannelId: cid, params: { type: params.type, url: params.url, data: params.data, name: params.name } }
|
|
30
|
+
});
|
|
31
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
32
|
+
return result || createResult(ResultCode.Warn, 'Media send not supported or failed', null);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return createResult(ResultCode.Fail, 'Failed to send media to channel', null);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const sendUser = async (params) => {
|
|
39
|
+
if (!params.userId) {
|
|
40
|
+
return createResult(ResultCode.FailParams, 'Missing UserId', null);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const results = await sendAction({
|
|
44
|
+
action: 'media.send.user',
|
|
45
|
+
payload: { UserId: params.userId, params: { type: params.type, url: params.url, data: params.data, name: params.name } }
|
|
46
|
+
});
|
|
47
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
48
|
+
return result || createResult(ResultCode.Warn, 'Media send not supported or failed', null);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return createResult(ResultCode.Fail, 'Failed to send media to user', null);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const media = {
|
|
55
|
+
upload,
|
|
56
|
+
sendChannel,
|
|
57
|
+
sendUser
|
|
58
|
+
};
|
|
59
|
+
return [media];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { useMedia };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { EventKeys, Events, MemberInfo, PaginationParams, PaginatedResult, Result } from './common';
|
|
2
|
+
export declare const useMember: <T extends EventKeys>(event?: Events[T]) => readonly [{
|
|
3
|
+
info: (params: {
|
|
4
|
+
userId: string;
|
|
5
|
+
guildId?: string;
|
|
6
|
+
}) => Promise<Result<MemberInfo | null>>;
|
|
7
|
+
information: (params: {
|
|
8
|
+
userId: string;
|
|
9
|
+
}) => Promise<Result<MemberInfo>>;
|
|
10
|
+
list: (params?: {
|
|
11
|
+
guildId?: string;
|
|
12
|
+
pagination?: PaginationParams;
|
|
13
|
+
}) => Promise<Result<PaginatedResult<MemberInfo>>>;
|
|
14
|
+
kick: (params: {
|
|
15
|
+
userId: string;
|
|
16
|
+
guildId?: string;
|
|
17
|
+
}) => Promise<Result>;
|
|
18
|
+
ban: (params: {
|
|
19
|
+
userId: string;
|
|
20
|
+
guildId?: string;
|
|
21
|
+
reason?: string;
|
|
22
|
+
duration?: number;
|
|
23
|
+
}) => Promise<Result>;
|
|
24
|
+
unban: (params: {
|
|
25
|
+
userId: string;
|
|
26
|
+
guildId?: string;
|
|
27
|
+
}) => Promise<Result>;
|
|
28
|
+
search: (params: {
|
|
29
|
+
keyword: string;
|
|
30
|
+
guildId?: string;
|
|
31
|
+
limit?: number;
|
|
32
|
+
}) => Promise<Result>;
|
|
33
|
+
mute(params: {
|
|
34
|
+
userId: string;
|
|
35
|
+
duration: number;
|
|
36
|
+
guildId?: string;
|
|
37
|
+
}): Promise<Result>;
|
|
38
|
+
admin(params: {
|
|
39
|
+
userId: string;
|
|
40
|
+
enable: boolean;
|
|
41
|
+
guildId?: string;
|
|
42
|
+
}): Promise<Result>;
|
|
43
|
+
card(params: {
|
|
44
|
+
userId: string;
|
|
45
|
+
card: string;
|
|
46
|
+
guildId?: string;
|
|
47
|
+
}): Promise<Result>;
|
|
48
|
+
title(params: {
|
|
49
|
+
userId: string;
|
|
50
|
+
title: string;
|
|
51
|
+
guildId?: string;
|
|
52
|
+
duration?: number;
|
|
53
|
+
}): Promise<Result>;
|
|
54
|
+
}];
|
|
@@ -0,0 +1,200 @@
|
|
|
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 useMember = (event) => {
|
|
7
|
+
const valueEvent = getEventOrThrow(event);
|
|
8
|
+
const getGuildId = (guildId) => guildId || valueEvent.GuildId;
|
|
9
|
+
const info = async (params) => {
|
|
10
|
+
try {
|
|
11
|
+
const results = await sendAction({
|
|
12
|
+
action: 'member.info',
|
|
13
|
+
payload: {
|
|
14
|
+
event: valueEvent,
|
|
15
|
+
params: {
|
|
16
|
+
userId: params.userId,
|
|
17
|
+
guildId: getGuildId(params.guildId)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
22
|
+
if (result) {
|
|
23
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved member information', result.data ?? null);
|
|
24
|
+
}
|
|
25
|
+
return createResult(ResultCode.Warn, 'No member information found', null);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return createResult(ResultCode.Fail, 'Failed to get member information', null);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const list = async (params) => {
|
|
32
|
+
const guildId = getGuildId(params?.guildId);
|
|
33
|
+
if (!guildId) {
|
|
34
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId', { Items: [] });
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const results = await sendAction({
|
|
38
|
+
action: 'member.list',
|
|
39
|
+
payload: { GuildId: guildId, params: params?.pagination }
|
|
40
|
+
});
|
|
41
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
42
|
+
if (result) {
|
|
43
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved member list', result.data ?? { Items: [] });
|
|
44
|
+
}
|
|
45
|
+
return createResult(ResultCode.Warn, 'No member list found', { Items: [] });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return createResult(ResultCode.Fail, 'Failed to get member list', { Items: [] });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const kick = async (params) => {
|
|
52
|
+
const gid = getGuildId(params.guildId);
|
|
53
|
+
if (!gid || !params.userId) {
|
|
54
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const results = await sendAction({
|
|
58
|
+
action: 'member.kick',
|
|
59
|
+
payload: { GuildId: gid, UserId: params.userId }
|
|
60
|
+
});
|
|
61
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
62
|
+
return result || createResult(ResultCode.Warn, 'Kick not supported or failed', null);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return createResult(ResultCode.Fail, 'Failed to kick member', null);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const ban = async (params) => {
|
|
69
|
+
const gid = getGuildId(params.guildId);
|
|
70
|
+
if (!gid || !params.userId) {
|
|
71
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const results = await sendAction({
|
|
75
|
+
action: 'member.ban',
|
|
76
|
+
payload: { GuildId: gid, UserId: params.userId, params: { reason: params.reason, duration: params.duration } }
|
|
77
|
+
});
|
|
78
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
79
|
+
return result || createResult(ResultCode.Warn, 'Ban not supported or failed', null);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return createResult(ResultCode.Fail, 'Failed to ban member', null);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const unban = async (params) => {
|
|
86
|
+
const gid = getGuildId(params.guildId);
|
|
87
|
+
if (!gid || !params.userId) {
|
|
88
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const results = await sendAction({
|
|
92
|
+
action: 'member.unban',
|
|
93
|
+
payload: { GuildId: gid, UserId: params.userId }
|
|
94
|
+
});
|
|
95
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
96
|
+
return result || createResult(ResultCode.Warn, 'Unban not supported or failed', null);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return createResult(ResultCode.Fail, 'Failed to unban member', null);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const information = (params) => info(params);
|
|
103
|
+
const search = async (params) => {
|
|
104
|
+
const gid = getGuildId(params.guildId);
|
|
105
|
+
if (!gid || !params.keyword) {
|
|
106
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or keyword', null);
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const results = await sendAction({
|
|
110
|
+
action: 'member.search',
|
|
111
|
+
payload: { GuildId: gid, params: { keyword: params.keyword, limit: params.limit } }
|
|
112
|
+
});
|
|
113
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
114
|
+
return result || createResult(ResultCode.Warn, 'Member search not supported or failed', null);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return createResult(ResultCode.Fail, 'Failed to search members', null);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const member = {
|
|
121
|
+
info,
|
|
122
|
+
information,
|
|
123
|
+
list,
|
|
124
|
+
kick,
|
|
125
|
+
ban,
|
|
126
|
+
unban,
|
|
127
|
+
search,
|
|
128
|
+
async mute(params) {
|
|
129
|
+
const gid = getGuildId(params.guildId);
|
|
130
|
+
if (!gid || !params.userId) {
|
|
131
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const results = await sendAction({
|
|
135
|
+
action: 'member.mute',
|
|
136
|
+
payload: { GuildId: gid, UserId: params.userId, params: { duration: params.duration } }
|
|
137
|
+
});
|
|
138
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
139
|
+
return result || createResult(ResultCode.Warn, 'Mute not supported or failed', null);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return createResult(ResultCode.Fail, 'Failed to mute member', null);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
async admin(params) {
|
|
146
|
+
const gid = getGuildId(params.guildId);
|
|
147
|
+
if (!gid || !params.userId) {
|
|
148
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const results = await sendAction({
|
|
152
|
+
action: 'member.admin',
|
|
153
|
+
payload: { GuildId: gid, UserId: params.userId, params: { enable: params.enable } }
|
|
154
|
+
});
|
|
155
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
156
|
+
return result || createResult(ResultCode.Warn, 'Admin set not supported or failed', null);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return createResult(ResultCode.Fail, 'Failed to set admin', null);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
async card(params) {
|
|
163
|
+
const gid = getGuildId(params.guildId);
|
|
164
|
+
if (!gid || !params.userId) {
|
|
165
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const results = await sendAction({
|
|
169
|
+
action: 'member.card',
|
|
170
|
+
payload: { GuildId: gid, UserId: params.userId, params: { card: params.card } }
|
|
171
|
+
});
|
|
172
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
173
|
+
return result || createResult(ResultCode.Warn, 'Card set not supported or failed', null);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return createResult(ResultCode.Fail, 'Failed to set member card', null);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
async title(params) {
|
|
180
|
+
const gid = getGuildId(params.guildId);
|
|
181
|
+
if (!gid || !params.userId) {
|
|
182
|
+
return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const results = await sendAction({
|
|
186
|
+
action: 'member.title',
|
|
187
|
+
payload: { GuildId: gid, UserId: params.userId, params: { title: params.title, duration: params.duration ?? -1 } }
|
|
188
|
+
});
|
|
189
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
190
|
+
return result || createResult(ResultCode.Warn, 'Title set not supported or failed', null);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return createResult(ResultCode.Fail, 'Failed to set member title', null);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
return [member];
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export { useMember };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventKeys, Events, Options, Result, User } from './common';
|
|
2
|
+
export declare const useMention: <T extends EventKeys>(event?: Events[T]) => [{
|
|
3
|
+
find: (options?: Options) => Promise<Result<User[]> & {
|
|
4
|
+
count: number;
|
|
5
|
+
}>;
|
|
6
|
+
findOne: (options?: Options) => Promise<Result<User | null> & {
|
|
7
|
+
count: number;
|
|
8
|
+
}>;
|
|
9
|
+
}];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getEventOrThrow } from './common.js';
|
|
2
|
+
import { ResultCode } from '../../core/variable.js';
|
|
3
|
+
import { createResult } from '../../core/utils.js';
|
|
4
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
5
|
+
|
|
6
|
+
const useMention = (event) => {
|
|
7
|
+
const valueEvent = getEventOrThrow(event);
|
|
8
|
+
let res = null;
|
|
9
|
+
const load = async () => {
|
|
10
|
+
if (res) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const results = await sendAction({
|
|
14
|
+
action: 'mention.get',
|
|
15
|
+
payload: { event: valueEvent }
|
|
16
|
+
});
|
|
17
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
18
|
+
if (result) {
|
|
19
|
+
res = result.data;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const match = (item, options) => {
|
|
23
|
+
if (options.UserId !== undefined && item.UserId !== options.UserId) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (options.UserKey !== undefined && item.UserKey !== options.UserKey) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (options.IsBot === undefined && item.IsBot) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
const mention = {
|
|
44
|
+
find: async (options = {}) => {
|
|
45
|
+
try {
|
|
46
|
+
await load();
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
const result = createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
|
|
50
|
+
return {
|
|
51
|
+
...result,
|
|
52
|
+
count: 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (!Array.isArray(res)) {
|
|
56
|
+
return {
|
|
57
|
+
...createResult(ResultCode.Warn, 'No mention data found', null),
|
|
58
|
+
count: 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const data = res.filter(item => match(item, options));
|
|
62
|
+
const result = createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
|
|
63
|
+
return {
|
|
64
|
+
...result,
|
|
65
|
+
count: data.length || 0
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
findOne: async (options = {}) => {
|
|
69
|
+
const results = await mention.find(options);
|
|
70
|
+
if (results.code !== ResultCode.Ok || !results.data?.length) {
|
|
71
|
+
const result = createResult(results.code, results.message, null);
|
|
72
|
+
return {
|
|
73
|
+
...result,
|
|
74
|
+
count: 0
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const data = results?.data[0];
|
|
78
|
+
const result = createResult(ResultCode.Ok, results.message, data);
|
|
79
|
+
return {
|
|
80
|
+
...result,
|
|
81
|
+
count: results.data?.length || 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return [mention];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { useMention };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DataEnums, EventKeys, Events, Format, Result } from './common';
|
|
2
|
+
export declare const useMessage: <T extends EventKeys>(event?: Events[T]) => readonly [{
|
|
3
|
+
send(params?: {
|
|
4
|
+
format: Format | DataEnums[];
|
|
5
|
+
replyId?: string;
|
|
6
|
+
} | DataEnums[]): Promise<Result[]>;
|
|
7
|
+
delete(params?: {
|
|
8
|
+
messageId?: string;
|
|
9
|
+
}): Promise<Result>;
|
|
10
|
+
edit(params: {
|
|
11
|
+
format: Format | DataEnums[];
|
|
12
|
+
messageId?: string;
|
|
13
|
+
}): Promise<Result>;
|
|
14
|
+
pin(params?: {
|
|
15
|
+
messageId?: string;
|
|
16
|
+
}): Promise<Result>;
|
|
17
|
+
unpin(params?: {
|
|
18
|
+
messageId?: string;
|
|
19
|
+
}): Promise<Result>;
|
|
20
|
+
get(params?: {
|
|
21
|
+
messageId?: string;
|
|
22
|
+
}): Promise<Result>;
|
|
23
|
+
}];
|
|
24
|
+
export declare const useSend: <T extends EventKeys>(event?: Events[T]) => (...val: DataEnums[]) => Promise<Result[]>;
|
|
25
|
+
export declare const useSends: <T extends EventKeys>(event?: Events[T]) => readonly [(params?: DataEnums[] | {
|
|
26
|
+
format: Format | DataEnums[];
|
|
27
|
+
replyId?: string;
|
|
28
|
+
}) => Promise<Result[]>];
|