@alemonjs/discord 0.0.4 → 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.
- package/lib/index.d.ts +5 -1
- package/lib/index.js +24 -5
- package/lib/sdk/core/config.js +46 -0
- package/lib/sdk/core/utils/from.js +42 -0
- package/lib/sdk/platform/discord/sdk/api.d.ts +896 -0
- package/lib/sdk/platform/discord/sdk/api.js +1554 -0
- package/lib/sdk/platform/discord/sdk/config.js +29 -0
- package/lib/sdk/platform/discord/sdk/intents.js +36 -0
- package/lib/sdk/platform/discord/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +11 -0
- package/lib/sdk/platform/discord/sdk/message/CHANNEL_UPDATE.d.ts +48 -0
- package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_ADD.d.ts +28 -0
- package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_REMOVE.d.ts +18 -0
- package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_UPDATE.d.ts +33 -0
- package/lib/sdk/platform/discord/sdk/message/MESSAGE_CREATE.d.ts +59 -0
- package/lib/sdk/platform/discord/sdk/message/MESSAGE_DELETE.d.ts +11 -0
- package/lib/sdk/platform/discord/sdk/message/MESSAGE_REACTION_ADD.d.ts +42 -0
- package/lib/sdk/platform/discord/sdk/message/MESSAGE_UPDATE.d.ts +56 -0
- package/lib/sdk/platform/discord/sdk/message/PRESENCE_UPDATE.d.ts +63 -0
- package/lib/sdk/platform/discord/sdk/message/READY.d.ts +9 -0
- package/lib/sdk/platform/discord/sdk/message/TYPING_START.d.ts +35 -0
- package/lib/sdk/platform/discord/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +10 -0
- package/lib/sdk/platform/discord/sdk/message/VOICE_STATE_UPDATE.d.ts +41 -0
- package/lib/sdk/platform/discord/sdk/message.d.ts +37 -0
- package/lib/sdk/platform/discord/sdk/types.d.ts +4 -0
- package/lib/sdk/platform/discord/sdk/wss.d.ts +27 -0
- package/lib/sdk/platform/discord/sdk/wss.js +201 -0
- package/lib/sdk/platform/discord/sdk/wss.types.d.ts +26 -0
- package/package.json +5 -7
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
|
|
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
|
-
|
|
69
|
+
MessageBody: [
|
|
58
70
|
Text(msg),
|
|
59
71
|
...at_users.map(item => At(item.id, 'user', {
|
|
60
72
|
name: item.name,
|
|
@@ -62,10 +74,12 @@ var index = defineBot(() => {
|
|
|
62
74
|
bot: item.bot
|
|
63
75
|
}))
|
|
64
76
|
],
|
|
77
|
+
MessageText: msg,
|
|
65
78
|
// 用户openId
|
|
66
79
|
OpenID: '',
|
|
67
80
|
// 创建时间
|
|
68
81
|
CreateAt: Date.now(),
|
|
82
|
+
tag: 'MESSAGE_CREATE',
|
|
69
83
|
//
|
|
70
84
|
value: null
|
|
71
85
|
};
|
|
@@ -82,19 +96,24 @@ var index = defineBot(() => {
|
|
|
82
96
|
client.on('ERROR', msg => {
|
|
83
97
|
console.error(msg);
|
|
84
98
|
});
|
|
99
|
+
global.client = client;
|
|
85
100
|
return {
|
|
86
101
|
api: {
|
|
87
102
|
use: {
|
|
88
103
|
send: (event, val) => {
|
|
89
104
|
if (val.length < 0)
|
|
90
105
|
return Promise.all([]);
|
|
91
|
-
const content = useParse(
|
|
106
|
+
const content = useParse({
|
|
107
|
+
MessageBody: val
|
|
108
|
+
}, 'Text');
|
|
92
109
|
if (content) {
|
|
93
110
|
return Promise.all([content].map(item => client.channelsMessages(event.ChannelId, {
|
|
94
111
|
content: item
|
|
95
112
|
})));
|
|
96
113
|
}
|
|
97
|
-
const images = useParse(
|
|
114
|
+
const images = useParse({
|
|
115
|
+
MessageBody: val
|
|
116
|
+
}, 'Image');
|
|
98
117
|
if (images) {
|
|
99
118
|
return Promise.all(images.map(item => client.channelsMessagesImage(event.ChannelId, item)));
|
|
100
119
|
}
|
|
@@ -105,4 +124,4 @@ var index = defineBot(() => {
|
|
|
105
124
|
};
|
|
106
125
|
});
|
|
107
126
|
|
|
108
|
-
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 };
|