@alemonjs/discord 0.0.3 → 0.0.4
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/README.md +5 -13
- package/lib/index.d.ts +2 -4
- package/lib/index.js +105 -107
- package/package.json +15 -8
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# [https://
|
|
1
|
+
# [https://alemonjs.com/](https://alemonjs.com/)
|
|
2
2
|
|
|
3
3
|
跨平台开发的事件驱动机器人
|
|
4
4
|
|
|
@@ -16,19 +16,11 @@ yarn add @alemonjs/discord
|
|
|
16
16
|
discord:
|
|
17
17
|
# 令牌
|
|
18
18
|
token: ''
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
> 完整的
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
discord:
|
|
25
|
-
# 令牌
|
|
26
|
-
token: ''
|
|
27
|
-
# 前缀
|
|
28
|
-
intent: []
|
|
29
19
|
# 主人
|
|
30
|
-
master_id:
|
|
31
|
-
#
|
|
20
|
+
master_id: null
|
|
21
|
+
# 前缀(非必填)
|
|
22
|
+
intent: null
|
|
23
|
+
# 活动 非必填)
|
|
32
24
|
shard: null
|
|
33
25
|
```
|
|
34
26
|
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,110 +1,108 @@
|
|
|
1
|
-
import { defineBot, Text, At, OnProcessor, useParse } from 'alemonjs'
|
|
2
|
-
import { DCClient } from 'chat-space'
|
|
1
|
+
import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
2
|
+
import { DCClient } from 'chat-space';
|
|
3
3
|
|
|
4
|
-
var index = defineBot(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
// 定义消
|
|
34
|
-
const e = {
|
|
35
|
-
// 事件类型
|
|
36
|
-
Platform: 'discord',
|
|
37
|
-
// 频道
|
|
38
|
-
GuildId: event.guild_id,
|
|
39
|
-
// 子频道
|
|
40
|
-
ChannelId: event.channel_id,
|
|
41
|
-
// 是否是主人
|
|
42
|
-
IsMaster: isMaster,
|
|
43
|
-
// 用户ID
|
|
44
|
-
UserId: event.author.id,
|
|
45
|
-
// 用户名
|
|
46
|
-
UserName: event.author.username,
|
|
47
|
-
// 用户头像
|
|
48
|
-
UserAvatar: client.userAvatar(event.author.id, event.author.avatar),
|
|
49
|
-
// 格式化数据
|
|
50
|
-
MsgId: event.id,
|
|
51
|
-
// 用户消息
|
|
52
|
-
Megs: [
|
|
53
|
-
Text(msg),
|
|
54
|
-
...at_users.map(item =>
|
|
55
|
-
At(item.id, 'user', {
|
|
56
|
-
name: item.name,
|
|
57
|
-
avatar: item.avatar,
|
|
58
|
-
bot: item.bot
|
|
59
|
-
})
|
|
60
|
-
)
|
|
61
|
-
],
|
|
62
|
-
// 用户openId
|
|
63
|
-
OpenID: '',
|
|
64
|
-
// 创建时间
|
|
65
|
-
CreateAt: Date.now(),
|
|
66
|
-
//
|
|
67
|
-
value: null
|
|
68
|
-
}
|
|
69
|
-
// 当访问的时候获取
|
|
70
|
-
Object.defineProperty(e, 'value', {
|
|
71
|
-
get() {
|
|
72
|
-
return event
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
// 处理消息
|
|
76
|
-
OnProcessor(e, 'message.create')
|
|
77
|
-
})
|
|
78
|
-
// 发送错误时
|
|
79
|
-
client.on('ERROR', msg => {
|
|
80
|
-
console.error(msg)
|
|
81
|
-
})
|
|
82
|
-
return {
|
|
83
|
-
api: {
|
|
84
|
-
use: {
|
|
85
|
-
send: (event, val) => {
|
|
86
|
-
if (val.length < 0) return Promise.all([])
|
|
87
|
-
const content = useParse(val, 'Text')
|
|
88
|
-
if (content) {
|
|
89
|
-
return Promise.all(
|
|
90
|
-
[content].map(item =>
|
|
91
|
-
client.channelsMessages(event.ChannelId, {
|
|
92
|
-
content: item
|
|
93
|
-
})
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
const images = useParse(val, 'Image')
|
|
98
|
-
if (images) {
|
|
99
|
-
return Promise.all(
|
|
100
|
-
images.map(item => client.channelsMessagesImage(event.ChannelId, item))
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
return Promise.all([])
|
|
4
|
+
var index = defineBot(() => {
|
|
5
|
+
const cfg = getConfig();
|
|
6
|
+
const config = cfg.value?.discord;
|
|
7
|
+
if (!config)
|
|
8
|
+
return;
|
|
9
|
+
// 创建客户端
|
|
10
|
+
const client = new DCClient({
|
|
11
|
+
token: config.token
|
|
12
|
+
});
|
|
13
|
+
// 连接
|
|
14
|
+
client.connect();
|
|
15
|
+
// 监听消息
|
|
16
|
+
client.on('MESSAGE_CREATE', async (event) => {
|
|
17
|
+
// 消除bot消息
|
|
18
|
+
if (event.author?.bot)
|
|
19
|
+
return;
|
|
20
|
+
const master_id = config?.master_id ?? [];
|
|
21
|
+
const isMaster = master_id.includes(event.author.id);
|
|
22
|
+
// 艾特消息处理
|
|
23
|
+
const at_users = [];
|
|
24
|
+
// 获取艾特用户
|
|
25
|
+
for (const item of event.mentions) {
|
|
26
|
+
at_users.push({
|
|
27
|
+
id: item.id,
|
|
28
|
+
name: item.username,
|
|
29
|
+
avatar: client.userAvatar(item.id, item.avatar),
|
|
30
|
+
bot: item.bot
|
|
31
|
+
});
|
|
104
32
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
33
|
+
// 清除 @ 相关的消息
|
|
34
|
+
let msg = event.content;
|
|
35
|
+
for await (const item of at_users) {
|
|
36
|
+
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
37
|
+
}
|
|
38
|
+
// 定义消
|
|
39
|
+
const e = {
|
|
40
|
+
// 事件类型
|
|
41
|
+
Platform: 'discord',
|
|
42
|
+
// 频道
|
|
43
|
+
GuildId: event.guild_id,
|
|
44
|
+
// 子频道
|
|
45
|
+
ChannelId: event.channel_id,
|
|
46
|
+
// 是否是主人
|
|
47
|
+
IsMaster: isMaster,
|
|
48
|
+
// 用户ID
|
|
49
|
+
UserId: event.author.id,
|
|
50
|
+
// 用户名
|
|
51
|
+
UserName: event.author.username,
|
|
52
|
+
// 用户头像
|
|
53
|
+
UserAvatar: client.userAvatar(event.author.id, event.author.avatar),
|
|
54
|
+
// 格式化数据
|
|
55
|
+
MsgId: event.id,
|
|
56
|
+
// 用户消息
|
|
57
|
+
Megs: [
|
|
58
|
+
Text(msg),
|
|
59
|
+
...at_users.map(item => At(item.id, 'user', {
|
|
60
|
+
name: item.name,
|
|
61
|
+
avatar: item.avatar,
|
|
62
|
+
bot: item.bot
|
|
63
|
+
}))
|
|
64
|
+
],
|
|
65
|
+
// 用户openId
|
|
66
|
+
OpenID: '',
|
|
67
|
+
// 创建时间
|
|
68
|
+
CreateAt: Date.now(),
|
|
69
|
+
//
|
|
70
|
+
value: null
|
|
71
|
+
};
|
|
72
|
+
// 当访问的时候获取
|
|
73
|
+
Object.defineProperty(e, 'value', {
|
|
74
|
+
get() {
|
|
75
|
+
return event;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// 处理消息
|
|
79
|
+
OnProcessor(e, 'message.create');
|
|
80
|
+
});
|
|
81
|
+
// 发送错误时
|
|
82
|
+
client.on('ERROR', msg => {
|
|
83
|
+
console.error(msg);
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
api: {
|
|
87
|
+
use: {
|
|
88
|
+
send: (event, val) => {
|
|
89
|
+
if (val.length < 0)
|
|
90
|
+
return Promise.all([]);
|
|
91
|
+
const content = useParse(val, 'Text');
|
|
92
|
+
if (content) {
|
|
93
|
+
return Promise.all([content].map(item => client.channelsMessages(event.ChannelId, {
|
|
94
|
+
content: item
|
|
95
|
+
})));
|
|
96
|
+
}
|
|
97
|
+
const images = useParse(val, 'Image');
|
|
98
|
+
if (images) {
|
|
99
|
+
return Promise.all(images.map(item => client.channelsMessagesImage(event.ChannelId, item)));
|
|
100
|
+
}
|
|
101
|
+
return Promise.all([]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
});
|
|
109
107
|
|
|
110
|
-
export { index as default }
|
|
108
|
+
export { index as default };
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/discord",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "discord-bot",
|
|
5
|
+
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"chat-space": "^0.0.
|
|
10
|
+
"chat-space": "^0.0.6"
|
|
11
11
|
},
|
|
12
12
|
"types": "lib",
|
|
13
13
|
"exports": {
|
|
@@ -16,11 +16,18 @@
|
|
|
16
16
|
"types": "./lib/index.d.ts"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"alemonjs",
|
|
21
|
+
"discord",
|
|
22
|
+
"bot",
|
|
23
|
+
"chat-bot"
|
|
24
|
+
],
|
|
19
25
|
"publishConfig": {
|
|
20
|
-
"access": "public",
|
|
21
26
|
"registry": "https://registry.npmjs.org"
|
|
22
27
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
"bugs": "https://github.com/ningmengchongshui/alemonjs/issues",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/ningmengchongshui/alemonjs.git"
|
|
32
|
+
}
|
|
26
33
|
}
|