@alemonjs/discord 2.1.0-alpha.8 → 2.1.0-alpha.9

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/config.js CHANGED
@@ -2,13 +2,13 @@ import { getConfigValue, useUserHashKey } from 'alemonjs';
2
2
 
3
3
  // 平台
4
4
  const platform = 'discord';
5
- const getDiscordConfigValue = () => {
5
+ const getDiscordConfig = () => {
6
6
  const value = getConfigValue() || {};
7
7
  const config = value[platform] || {};
8
8
  return config;
9
9
  };
10
10
  const getMaster = (UserId) => {
11
- const config = getDiscordConfigValue();
11
+ const config = getDiscordConfig();
12
12
  const master_key = config.master_key || [];
13
13
  const master_id = config.master_id || [];
14
14
  const UserKey = useUserHashKey({
@@ -19,4 +19,4 @@ const getMaster = (UserId) => {
19
19
  return [is, UserKey];
20
20
  };
21
21
 
22
- export { getDiscordConfigValue, getMaster, platform };
22
+ export { getDiscordConfig, getMaster, platform };
package/lib/hook.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { EventKeys, Events } from 'alemonjs';
2
+ import { DCAPI } from './sdk/api.js';
3
+ import { MESSAGE_CREATE_TYPE } from './sdk/message/MESSAGE_CREATE.js';
4
+ import { INTERACTION_CREATE_TYPE } from './sdk/message/INTERACTION_CREATE.js';
5
+
6
+ type MAP = {
7
+ 'message.create': MESSAGE_CREATE_TYPE;
8
+ 'private.message.create': MESSAGE_CREATE_TYPE;
9
+ 'interaction.create': INTERACTION_CREATE_TYPE;
10
+ 'private.interaction.create': INTERACTION_CREATE_TYPE;
11
+ 'message.update': undefined;
12
+ 'message.delete': undefined;
13
+ 'message.reaction.add': undefined;
14
+ 'message.reaction.remove': undefined;
15
+ 'channal.create': undefined;
16
+ 'channal.delete': undefined;
17
+ 'guild.join': undefined;
18
+ 'guild.exit': undefined;
19
+ 'member.add': undefined;
20
+ 'member.remove': undefined;
21
+ 'private.message.update': undefined;
22
+ 'private.message.delete': undefined;
23
+ 'private.friend.add': undefined;
24
+ 'private.guild.add': undefined;
25
+ };
26
+ /**
27
+ *
28
+ * @param event
29
+ * @returns
30
+ */
31
+ declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
32
+ /**
33
+ *
34
+ * @param event
35
+ * @returns
36
+ */
37
+ declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [DCAPI, MAP[T]];
38
+
39
+ export { useClient, useValue };
package/lib/hook.js ADDED
@@ -0,0 +1,24 @@
1
+ import { createEventValue, useClient as useClient$1 } from 'alemonjs';
2
+ import { DCAPI } from './sdk/api.js';
3
+
4
+ /**
5
+ *
6
+ * @param event
7
+ * @returns
8
+ */
9
+ const useValue = (event) => {
10
+ const value = createEventValue(event);
11
+ return [value];
12
+ };
13
+ /**
14
+ *
15
+ * @param event
16
+ * @returns
17
+ */
18
+ const useClient = (event) => {
19
+ const [client] = useClient$1(event, DCAPI);
20
+ const value = createEventValue(event);
21
+ return [client, value];
22
+ };
23
+
24
+ export { useClient, useValue };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { platform } from './config.js';
2
2
  export { DCAPI as API } from './sdk/api.js';
3
+ export { useClient, useValue } from './hook.js';
3
4
 
4
5
  declare const _default: () => void;
5
6
 
package/lib/index.js CHANGED
@@ -2,12 +2,13 @@ import './env.js';
2
2
  import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
3
3
  import { sendchannel, senduser } from './send.js';
4
4
  import { DCClient } from './sdk/wss.js';
5
- import { getDiscordConfigValue, getMaster, platform } from './config.js';
5
+ import { getDiscordConfig, getMaster, platform } from './config.js';
6
6
  export { DCAPI as API } from './sdk/api.js';
7
+ export { useClient, useValue } from './hook.js';
7
8
 
8
9
  // main
9
10
  var index = () => {
10
- const value = getDiscordConfigValue();
11
+ const value = getDiscordConfig();
11
12
  const port = process.env?.port || value?.port || 17117;
12
13
  /**
13
14
  * 连接 alemonjs 服务器。
package/lib/sdk/api.js CHANGED
@@ -4,7 +4,7 @@ import { existsSync, createReadStream } from 'fs';
4
4
  import { Readable, isReadable } from 'stream';
5
5
  import { basename } from 'path';
6
6
  import { fileTypeFromBuffer, fileTypeFromStream } from 'file-type';
7
- import { getDiscordConfigValue } from '../config.js';
7
+ import { getDiscordConfig } from '../config.js';
8
8
 
9
9
  /**
10
10
  * 创建form
@@ -53,7 +53,7 @@ class DCAPI {
53
53
  * @returns
54
54
  */
55
55
  request(options) {
56
- const value = getDiscordConfigValue();
56
+ const value = getDiscordConfig();
57
57
  const token = value.token;
58
58
  const service = axios.create({
59
59
  baseURL: API_URL,
@@ -71,7 +71,7 @@ class DCAPI {
71
71
  * @returns
72
72
  */
73
73
  requestCDN(options) {
74
- const value = getDiscordConfigValue();
74
+ const value = getDiscordConfig();
75
75
  const token = value.token;
76
76
  const service = axios.create({
77
77
  baseURL: CDB_URL,
@@ -0,0 +1,126 @@
1
+ interface User {
2
+ username: string;
3
+ public_flags: number;
4
+ primary_guild: null;
5
+ id: string;
6
+ global_name: string | null;
7
+ discriminator: string;
8
+ collectibles: null;
9
+ clan: null;
10
+ avatar_decoration_data: null;
11
+ avatar: string;
12
+ }
13
+ type Message = {
14
+ type: number;
15
+ tts: boolean;
16
+ timestamp: string;
17
+ pinned: boolean;
18
+ mentions: unknown[];
19
+ mention_roles: unknown[];
20
+ mention_everyone: boolean;
21
+ id: string;
22
+ flags: number;
23
+ embeds: unknown[];
24
+ edited_timestamp: string | null;
25
+ content: string;
26
+ components: unknown[];
27
+ channel_id: string;
28
+ author: User;
29
+ attachments: unknown[];
30
+ };
31
+ type Member = {
32
+ user: User;
33
+ unusual_dm_activity_until: string | null;
34
+ roles: string[];
35
+ premium_since: string | null;
36
+ permissions: string;
37
+ pending: boolean;
38
+ nick: string | null;
39
+ mute: boolean;
40
+ joined_at: string;
41
+ flags: number;
42
+ deaf: boolean;
43
+ communication_disabled_until: string | null;
44
+ banner: string | null;
45
+ avatar: string | null;
46
+ };
47
+ type DiscordGuild = {
48
+ locale: string;
49
+ id: string;
50
+ features: string[];
51
+ };
52
+ type PublicChannel = {
53
+ type: number;
54
+ topic: string | null;
55
+ theme_color: number | null;
56
+ rate_limit_per_user: number;
57
+ position: number;
58
+ permissions: string;
59
+ parent_id: string;
60
+ nsfw: boolean;
61
+ name: string;
62
+ last_message_id: string;
63
+ id: string;
64
+ icon_emoji: {
65
+ name: string;
66
+ id: string | null;
67
+ };
68
+ guild_id: string;
69
+ flags: number;
70
+ };
71
+ interface Channel {
72
+ type: number;
73
+ recipients: any[];
74
+ recipient_flags: number;
75
+ last_message_id: string;
76
+ id: string;
77
+ flags: number;
78
+ }
79
+ interface Data {
80
+ id: number;
81
+ custom_id: string;
82
+ component_type: number;
83
+ }
84
+ type Public = {
85
+ version: number;
86
+ type: number;
87
+ token: string;
88
+ member: Member;
89
+ message: Message;
90
+ locale: string;
91
+ id: string;
92
+ guild_locale: string;
93
+ guild_id: string;
94
+ guild: DiscordGuild;
95
+ entitlement_sku_ids: any[];
96
+ entitlements: any[];
97
+ data: Data;
98
+ context: number;
99
+ channel_id: string;
100
+ channel: PublicChannel;
101
+ authorizing_integration_owners: Record<string, string>;
102
+ attachment_size_limit: number;
103
+ application_id: string;
104
+ app_permissions: string;
105
+ };
106
+ type Private = {
107
+ version: number;
108
+ type: number;
109
+ token: string;
110
+ user: User;
111
+ message: Message;
112
+ locale: string;
113
+ id: string;
114
+ entitlements: any[];
115
+ data: Data;
116
+ context: number;
117
+ channel_id: string;
118
+ channel: Channel;
119
+ authorizing_integration_owners: Record<string, string>;
120
+ attachment_size_limit: number;
121
+ application_id: string;
122
+ app_permissions: string;
123
+ };
124
+ type INTERACTION_CREATE_TYPE = Public | Private;
125
+
126
+ export type { INTERACTION_CREATE_TYPE };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * 基础消息
3
+ * @param event
4
+ */
5
+ type MESSAGE_CREATE_TYPE = {
6
+ type: number;
7
+ tts: boolean;
8
+ timestamp: string;
9
+ referenced_message: null;
10
+ pinned: boolean;
11
+ nonce: string;
12
+ mentions: {
13
+ username: string;
14
+ public_flags: number;
15
+ member: any;
16
+ id: string;
17
+ global_name: null;
18
+ discriminator: string;
19
+ bot: boolean;
20
+ avatar_decoration_data: null;
21
+ avatar: string;
22
+ }[];
23
+ mention_roles: any[];
24
+ mention_everyone: boolean;
25
+ member: {
26
+ roles: any[];
27
+ premium_since: null;
28
+ pending: boolean;
29
+ nick: null;
30
+ mute: boolean;
31
+ joined_at: string;
32
+ flags: number;
33
+ deaf: boolean;
34
+ communication_disabled_until: null;
35
+ avatar: null;
36
+ };
37
+ id: string;
38
+ flags: number;
39
+ embeds: any[];
40
+ edited_timestamp: null;
41
+ content: string;
42
+ components: any[];
43
+ channel_id: string;
44
+ author: {
45
+ username: string;
46
+ public_flags: number;
47
+ premium_type: number;
48
+ id: string;
49
+ global_name: string;
50
+ discriminator: string;
51
+ avatar_decoration_data: null;
52
+ avatar: string;
53
+ bot?: boolean;
54
+ };
55
+ attachments: any[];
56
+ guild_id: string;
57
+ };
58
+
59
+ export type { MESSAGE_CREATE_TYPE };
package/lib/sdk/wss.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import WebSocket from 'ws';
2
2
  import { DCAPI } from './api.js';
3
3
  import { getIntents } from './intents.js';
4
- import { getDiscordConfigValue } from '../config.js';
4
+ import { getDiscordConfig } from '../config.js';
5
5
 
6
6
  class DCClient extends DCAPI {
7
7
  #heartbeat_interval = 0;
@@ -19,7 +19,7 @@ class DCClient extends DCAPI {
19
19
  * @returns
20
20
  */
21
21
  #aut() {
22
- const value = getDiscordConfigValue();
22
+ const value = getDiscordConfig();
23
23
  const token = value.token;
24
24
  const intent = value.intent || [];
25
25
  const shard = value.shard || [0, 1];
@@ -55,7 +55,7 @@ class DCClient extends DCAPI {
55
55
  * @returns
56
56
  */
57
57
  async connect() {
58
- const value = getDiscordConfigValue();
58
+ const value = getDiscordConfig();
59
59
  const gatewayURL = value.gatewayURL;
60
60
  // 清除序列号
61
61
  this.#seq = null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alemonjs/discord",
3
- "version": "2.1.0-alpha.8",
4
- "description": "阿柠檬discord平台连接",
3
+ "version": "2.1.0-alpha.9",
4
+ "description": "discord platform connection",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
7
7
  "type": "module",