@alemonjs/discord 2.1.0-alpha.3 → 2.1.0-alpha.5

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/dist/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>AlemonJS</title>
8
8
  <script type="module" crossorigin src="/assets/index.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index.css">
9
+ <link rel="stylesheet" crossorigin href="/assets/index.css" />
10
10
  </head>
11
11
 
12
12
  <body>
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import './env.js';
2
- import { getConfigValue, cbpPlatform, useUserHashKey } from 'alemonjs';
2
+ import { getConfigValue, cbpPlatform, useUserHashKey, createResult, ResultCode } from 'alemonjs';
3
3
  import { sendchannel, senduser } from './send.js';
4
4
  import { DCClient } from './sdk/wss.js';
5
5
  import { AvailableIntentsEventsEnum } from './sdk/types.js';
@@ -189,45 +189,51 @@ var index = () => {
189
189
  const api = {
190
190
  active: {
191
191
  send: {
192
- channel: (channel_id, val) => {
193
- return sendchannel(client, { channel_id }, val);
192
+ channel: async (channel_id, val) => {
193
+ const res = await sendchannel(client, { channel_id }, val);
194
+ return [createResult(ResultCode.Ok, '请求完成', res)];
194
195
  },
195
196
  user: async (author_id, val) => {
196
- return senduser(client, { author_id: author_id }, val);
197
+ const res = await senduser(client, { author_id: author_id }, val);
198
+ return [createResult(ResultCode.Ok, '请求完成', res)];
197
199
  }
198
200
  }
199
201
  },
200
202
  use: {
201
203
  send: async (event, val) => {
202
204
  if (val.length < 0) {
203
- return Promise.all([]);
205
+ return [];
204
206
  }
205
207
  const tag = event.tag;
206
208
  if (tag == 'message.create') {
207
209
  const ChannelId = event.value.channel_id;
208
- return sendchannel(client, { channel_id: ChannelId }, val);
210
+ const res = await sendchannel(client, { channel_id: ChannelId }, val);
211
+ return [createResult(ResultCode.Ok, '请求完成', res)];
209
212
  }
210
213
  else if (tag == 'private.message.create') {
211
214
  const UserId = event.value.author.id;
212
215
  const ChannelId = event.value.channel_id;
213
- return senduser(client, {
216
+ const res = await senduser(client, {
214
217
  channel_id: ChannelId,
215
218
  author_id: UserId
216
219
  }, val);
220
+ return [createResult(ResultCode.Ok, '请求完成', res)];
217
221
  }
218
222
  else if (tag == 'interaction.create') {
219
223
  const ChannelId = event.value.channel_id;
220
- return sendchannel(client, { channel_id: ChannelId }, val);
224
+ const res = await sendchannel(client, { channel_id: ChannelId }, val);
225
+ return [createResult(ResultCode.Ok, '请求完成', res)];
221
226
  }
222
227
  else if (tag == 'private.interaction.create') {
223
228
  const UserId = event.value.user.id;
224
229
  const ChannelId = event.value.channel_id;
225
- return senduser(client, {
230
+ const res = await senduser(client, {
226
231
  channel_id: ChannelId,
227
232
  author_id: UserId
228
233
  }, val);
234
+ return [createResult(ResultCode.Ok, '请求完成', res)];
229
235
  }
230
- return Promise.all([]);
236
+ return [];
231
237
  },
232
238
  mention: async (e) => {
233
239
  const event = e.value;
@@ -276,7 +282,7 @@ var index = () => {
276
282
  else if (data.action === 'mention.get') {
277
283
  const event = data.payload.event;
278
284
  const res = await api.use.mention(event);
279
- consume(res);
285
+ consume([createResult(ResultCode.Ok, '请求完成', res)]);
280
286
  }
281
287
  });
282
288
  };
package/lib/sdk/api.js CHANGED
@@ -107,7 +107,7 @@ class DCAPI {
107
107
  headers: {
108
108
  'Content-Type': 'multipart/form-data'
109
109
  }
110
- });
110
+ }).then(res => res.data);
111
111
  }
112
112
  /**
113
113
  * ************
package/lib/send.js CHANGED
@@ -1,4 +1,3 @@
1
- import { createResult, ResultCode } from 'alemonjs';
2
1
  import { readFileSync } from 'fs';
3
2
 
4
3
  const ImageURLToBuffer = async (url) => {
@@ -29,9 +28,9 @@ const createButtonsData = (rows) => {
29
28
  };
30
29
  });
31
30
  };
32
- const sendchannel = (client, param, val) => {
31
+ const sendchannel = async (client, param, val) => {
33
32
  if (val.length < 0)
34
- return Promise.all([]);
33
+ return [];
35
34
  const channel_id = param?.channel_id ?? '';
36
35
  // images
37
36
  const images = val.filter(item => item.type == 'Image' || item.type == 'ImageURL' || item.type == 'ImageFile');
@@ -86,7 +85,9 @@ const sendchannel = (client, param, val) => {
86
85
  }
87
86
  isText = true;
88
87
  if (item.type == 'Image') {
89
- return client.channelsMessagesImage(channel_id, Buffer.from(item.value, 'base64'), { content: text });
88
+ return client.channelsMessagesImage(channel_id, Buffer.from(item.value, 'base64'), {
89
+ content: text
90
+ });
90
91
  }
91
92
  else if (item.type == 'ImageURL') {
92
93
  return client.channelsMessagesImage(channel_id, await ImageURLToBuffer(item.value), {
@@ -108,12 +109,10 @@ const sendchannel = (client, param, val) => {
108
109
  content: content,
109
110
  components: data
110
111
  });
111
- return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
112
+ return {
112
113
  id: res.id
113
- });
114
- })).catch(err => [
115
- createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
116
- ]);
114
+ };
115
+ }));
117
116
  }
118
117
  if (content) {
119
118
  return Promise.all([content].map(item => client.channelsMessages(channel_id, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/discord",
3
- "version": "2.1.0-alpha.3",
3
+ "version": "2.1.0-alpha.5",
4
4
  "description": "阿柠檬discord平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",