@alemonjs/discord 0.0.3 → 0.0.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [https://lemonade-lab.github.io/alemonjs.com/](https://lemonade-lab.github.io/alemonjs.com/)
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
@@ -1,5 +1,3 @@
1
- import * as alemonjs from 'alemonjs'
1
+ declare const _default: () => typeof global.alemonjs;
2
2
 
3
- declare const _default: (_: alemonjs.ConfigType, __: any) => typeof global.alemonjs
4
-
5
- export { _default as default }
3
+ export { _default as default };
package/lib/index.js CHANGED
@@ -1,110 +1,109 @@
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(config => {
5
- // 创建客户端
6
- const client = new DCClient({
7
- token: config.token
8
- })
9
- // 连接
10
- client.connect()
11
- // 监听消息
12
- client.on('MESSAGE_CREATE', async event => {
13
- // 消除bot消息
14
- if (event.author?.bot) return
15
- const master_id = config?.master_id ?? []
16
- const isMaster = master_id.includes(event.author.id)
17
- // 艾特消息处理
18
- const at_users = []
19
- // 获取艾特用户
20
- for (const item of event.mentions) {
21
- at_users.push({
22
- id: item.id,
23
- name: item.username,
24
- avatar: client.userAvatar(item.id, item.avatar),
25
- bot: item.bot
26
- })
27
- }
28
- // 清除 @ 相关的消息
29
- let msg = event.content
30
- for await (const item of at_users) {
31
- msg = msg.replace(`<@${item.id}>`, '').trim()
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
+ tag: 'MESSAGE_CREATE',
70
+ //
71
+ value: null
72
+ };
73
+ // 当访问的时候获取
74
+ Object.defineProperty(e, 'value', {
75
+ get() {
76
+ return event;
77
+ }
78
+ });
79
+ // 处理消息
80
+ OnProcessor(e, 'message.create');
81
+ });
82
+ // 发送错误时
83
+ client.on('ERROR', msg => {
84
+ console.error(msg);
85
+ });
86
+ return {
87
+ api: {
88
+ use: {
89
+ send: (event, val) => {
90
+ if (val.length < 0)
91
+ return Promise.all([]);
92
+ const content = useParse(val, 'Text');
93
+ if (content) {
94
+ return Promise.all([content].map(item => client.channelsMessages(event.ChannelId, {
95
+ content: item
96
+ })));
97
+ }
98
+ const images = useParse(val, 'Image');
99
+ if (images) {
100
+ return Promise.all(images.map(item => client.channelsMessagesImage(event.ChannelId, item)));
101
+ }
102
+ return Promise.all([]);
103
+ }
104
+ }
105
+ }
106
+ };
107
+ });
109
108
 
110
- export { index as default }
109
+ export { index as default };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@alemonjs/discord",
3
- "version": "0.0.3",
4
- "description": "啊柠檬脚本",
5
- "author": "ningmengchongshui",
3
+ "version": "0.0.5",
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.4"
10
+ "chat-space": "^0.0.7"
11
11
  },
12
12
  "types": "lib",
13
13
  "exports": {
@@ -16,11 +16,19 @@
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
- "registry": "https://registry.npmjs.org"
26
+ "registry": "https://registry.npmjs.org",
27
+ "access": "public"
22
28
  },
23
- "keywords": [
24
- "alemonjs"
25
- ]
29
+ "bugs": "https://github.com/ningmengchongshui/alemonjs/issues",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/ningmengchongshui/alemonjs.git"
33
+ }
26
34
  }