@alemonjs/discord 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/lib/index.d.ts +5 -1
  2. package/lib/index.js +23 -5
  3. package/lib/sdk/core/config.js +46 -0
  4. package/lib/sdk/core/utils/from.js +42 -0
  5. package/lib/sdk/platform/discord/sdk/api.d.ts +896 -0
  6. package/lib/sdk/platform/discord/sdk/api.js +1554 -0
  7. package/lib/sdk/platform/discord/sdk/config.js +29 -0
  8. package/lib/sdk/platform/discord/sdk/intents.js +36 -0
  9. package/lib/sdk/platform/discord/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +11 -0
  10. package/lib/sdk/platform/discord/sdk/message/CHANNEL_UPDATE.d.ts +48 -0
  11. package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_ADD.d.ts +28 -0
  12. package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_REMOVE.d.ts +18 -0
  13. package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_UPDATE.d.ts +33 -0
  14. package/lib/sdk/platform/discord/sdk/message/MESSAGE_CREATE.d.ts +59 -0
  15. package/lib/sdk/platform/discord/sdk/message/MESSAGE_DELETE.d.ts +11 -0
  16. package/lib/sdk/platform/discord/sdk/message/MESSAGE_REACTION_ADD.d.ts +42 -0
  17. package/lib/sdk/platform/discord/sdk/message/MESSAGE_UPDATE.d.ts +56 -0
  18. package/lib/sdk/platform/discord/sdk/message/PRESENCE_UPDATE.d.ts +63 -0
  19. package/lib/sdk/platform/discord/sdk/message/READY.d.ts +9 -0
  20. package/lib/sdk/platform/discord/sdk/message/TYPING_START.d.ts +35 -0
  21. package/lib/sdk/platform/discord/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +10 -0
  22. package/lib/sdk/platform/discord/sdk/message/VOICE_STATE_UPDATE.d.ts +41 -0
  23. package/lib/sdk/platform/discord/sdk/message.d.ts +37 -0
  24. package/lib/sdk/platform/discord/sdk/types.d.ts +4 -0
  25. package/lib/sdk/platform/discord/sdk/wss.d.ts +27 -0
  26. package/lib/sdk/platform/discord/sdk/wss.js +201 -0
  27. package/lib/sdk/platform/discord/sdk/wss.types.d.ts +26 -0
  28. package/package.json +3 -6
package/lib/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ import { DCClient } from './sdk/platform/discord/sdk/wss.js';
2
+
3
+ type Client = typeof DCClient.prototype;
4
+ declare const client: Client;
1
5
  declare const _default: () => typeof global.alemonjs;
2
6
 
3
- export { _default as default };
7
+ export { type Client, client, _default as default };
package/lib/index.js CHANGED
@@ -1,6 +1,15 @@
1
1
  import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
2
- import { DCClient } from 'chat-space';
2
+ import 'fs';
3
+ import 'axios';
4
+ import 'path';
5
+ import 'qrcode';
6
+ import 'public-ip';
7
+ import 'stream';
8
+ import 'file-type';
9
+ import 'form-data';
10
+ import { DCClient } from './sdk/platform/discord/sdk/wss.js';
3
11
 
12
+ const client = global.client;
4
13
  var index = defineBot(() => {
5
14
  const cfg = getConfig();
6
15
  const config = cfg.value?.discord;
@@ -49,12 +58,15 @@ var index = defineBot(() => {
49
58
  UserId: event.author.id,
50
59
  // 用户名
51
60
  UserName: event.author.username,
61
+ GuildIdName: '',
62
+ GuildIdAvatar: '',
63
+ ChannelName: '',
52
64
  // 用户头像
53
65
  UserAvatar: client.userAvatar(event.author.id, event.author.avatar),
54
66
  // 格式化数据
55
67
  MsgId: event.id,
56
68
  // 用户消息
57
- Megs: [
69
+ MessageBody: [
58
70
  Text(msg),
59
71
  ...at_users.map(item => At(item.id, 'user', {
60
72
  name: item.name,
@@ -62,6 +74,7 @@ var index = defineBot(() => {
62
74
  bot: item.bot
63
75
  }))
64
76
  ],
77
+ MessageText: msg,
65
78
  // 用户openId
66
79
  OpenID: '',
67
80
  // 创建时间
@@ -83,19 +96,24 @@ var index = defineBot(() => {
83
96
  client.on('ERROR', msg => {
84
97
  console.error(msg);
85
98
  });
99
+ global.client = client;
86
100
  return {
87
101
  api: {
88
102
  use: {
89
103
  send: (event, val) => {
90
104
  if (val.length < 0)
91
105
  return Promise.all([]);
92
- const content = useParse(val, 'Text');
106
+ const content = useParse({
107
+ MessageBody: val
108
+ }, 'Text');
93
109
  if (content) {
94
110
  return Promise.all([content].map(item => client.channelsMessages(event.ChannelId, {
95
111
  content: item
96
112
  })));
97
113
  }
98
- const images = useParse(val, 'Image');
114
+ const images = useParse({
115
+ MessageBody: val
116
+ }, 'Image');
99
117
  if (images) {
100
118
  return Promise.all(images.map(item => client.channelsMessagesImage(event.ChannelId, item)));
101
119
  }
@@ -106,4 +124,4 @@ var index = defineBot(() => {
106
124
  };
107
125
  });
108
126
 
109
- export { index as default };
127
+ export { client, index as default };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 基础配置结构
3
+ */
4
+ class BaseConfig {
5
+ #data = null;
6
+ constructor(val) {
7
+ this.#data = val;
8
+ }
9
+ /**
10
+ * 设置配置
11
+ * @param key
12
+ * @param val
13
+ */
14
+ set(key, val) {
15
+ if (val !== undefined)
16
+ this.#data[key] = val;
17
+ return this;
18
+ }
19
+ /**
20
+ *
21
+ * @param key
22
+ * @returns
23
+ */
24
+ has(key) {
25
+ if (Object.prototype.hasOwnProperty.call(this.#data, key)) ;
26
+ return false;
27
+ }
28
+ /**
29
+ * 读取配置
30
+ * @param key
31
+ * @returns
32
+ */
33
+ all() {
34
+ return this.#data;
35
+ }
36
+ /**
37
+ * 读取配置
38
+ * @param key
39
+ * @returns
40
+ */
41
+ get(key) {
42
+ return this.#data[key];
43
+ }
44
+ }
45
+
46
+ export { BaseConfig };
@@ -0,0 +1,42 @@
1
+ import { existsSync, createReadStream } from 'fs';
2
+ import { Readable, isReadable } from 'stream';
3
+ import { basename } from 'path';
4
+ import { fileTypeFromBuffer, fileTypeFromStream } from 'file-type';
5
+
6
+ /**
7
+ * 创建form
8
+ * @param image
9
+ * @param name
10
+ * @returns
11
+ */
12
+ async function createPicFrom(image, name = 'image.jpg') {
13
+ let picData;
14
+ // 是 string
15
+ if (typeof image === 'string') {
16
+ if (!existsSync(image))
17
+ return false;
18
+ if (!name)
19
+ name = basename(image);
20
+ picData = createReadStream(image);
21
+ // 是 buffer
22
+ }
23
+ else if (Buffer.isBuffer(image)) {
24
+ if (!name)
25
+ name = 'file.' + (await fileTypeFromBuffer(image)).ext;
26
+ picData = new Readable();
27
+ picData.push(image);
28
+ picData.push(null);
29
+ // 是 文件流
30
+ }
31
+ else if (isReadable(image)) {
32
+ if (!name)
33
+ name = 'file.' + (await fileTypeFromStream(image)).ext;
34
+ picData = image;
35
+ }
36
+ else {
37
+ return false;
38
+ }
39
+ return { picData, image, name };
40
+ }
41
+
42
+ export { createPicFrom };