@alemonjs/discord 0.2.6 → 0.2.7

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 (27) hide show
  1. package/README.md +3 -5
  2. package/dist/assets/index.css +1 -1
  3. package/dist/assets/index.js +1 -1
  4. package/lib/desktop.d.ts +2 -2
  5. package/lib/desktop.js +55 -52
  6. package/lib/index.d.ts +6 -7
  7. package/lib/index.js +67 -13
  8. package/lib/sdk/platform/discord/sdk/api.d.ts +907 -889
  9. package/lib/sdk/platform/discord/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +5 -5
  10. package/lib/sdk/platform/discord/sdk/message/CHANNEL_UPDATE.d.ts +42 -42
  11. package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_ADD.d.ts +23 -23
  12. package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_REMOVE.d.ts +12 -12
  13. package/lib/sdk/platform/discord/sdk/message/GUILD_MEMBER_UPDATE.d.ts +27 -27
  14. package/lib/sdk/platform/discord/sdk/message/MESSAGE_CREATE.d.ts +53 -53
  15. package/lib/sdk/platform/discord/sdk/message/MESSAGE_DELETE.d.ts +5 -5
  16. package/lib/sdk/platform/discord/sdk/message/MESSAGE_REACTION_ADD.d.ts +36 -36
  17. package/lib/sdk/platform/discord/sdk/message/MESSAGE_UPDATE.d.ts +50 -50
  18. package/lib/sdk/platform/discord/sdk/message/PRESENCE_UPDATE.d.ts +62 -56
  19. package/lib/sdk/platform/discord/sdk/message/READY.d.ts +7 -7
  20. package/lib/sdk/platform/discord/sdk/message/TYPING_START.d.ts +29 -29
  21. package/lib/sdk/platform/discord/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +5 -5
  22. package/lib/sdk/platform/discord/sdk/message/VOICE_STATE_UPDATE.d.ts +36 -36
  23. package/lib/sdk/platform/discord/sdk/message.d.ts +31 -31
  24. package/lib/sdk/platform/discord/sdk/types.d.ts +23 -3
  25. package/lib/sdk/platform/discord/sdk/wss.d.ts +23 -23
  26. package/lib/sdk/platform/discord/sdk/wss.types.d.ts +17 -17
  27. package/package.json +4 -1
package/lib/desktop.js CHANGED
@@ -1,58 +1,61 @@
1
- import { readFileSync } from 'fs';
2
- import { dirname, join } from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { getConfig, getConfigValue } from 'alemonjs';
1
+ import { readFileSync } from 'fs'
2
+ import { dirname, join } from 'path'
3
+ import { fileURLToPath } from 'url'
4
+ import { getConfig, getConfigValue } from 'alemonjs'
5
5
 
6
6
  // 当前目录
7
- const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ const __dirname = dirname(fileURLToPath(import.meta.url))
8
8
  // 被激活的时候。
9
9
  const activate = context => {
10
- // 创建一个 webview。
11
- const webView = context.createSidebarWebView(context);
12
- // 当命令被触发的时候。
13
- context.onCommand('open.discord', () => {
14
- const dir = join(__dirname, '../', 'dist', 'index.html');
15
- const scriptReg = /<script.*?src="(.+?)".*?>/;
16
- const styleReg = /<link.*?href="(.+?)".*?>/;
17
- // 创建 webview 路径
18
- const styleUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.css'));
19
- const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
20
- // 确保路径存在
21
- const html = readFileSync(dir, 'utf-8')
22
- .replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
23
- .replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
24
- // 立即渲染 webview
25
- webView.loadWebView(html);
26
- });
27
- // 监听 webview 的消息。
28
- webView.onMessage(data => {
29
- try {
30
- if (data.type === 'discord.form.save') {
31
- const db = data.data;
32
- const config = getConfig();
33
- const value = config.value ?? {};
34
- value['discord'] = {
35
- token: db.token ?? '',
36
- master_key: db.master_key?.split(',') ?? null
37
- };
38
- config.saveValue(value);
39
- context.notification('discord 配置保存成功~');
40
- }
41
- else if (data.type === 'discord.init') {
42
- let config = getConfigValue();
43
- if (!config)
44
- config = {};
45
- // 发送消息
46
- webView.postMessage({
47
- type: 'discord.init',
48
- data: config.discord ?? {}
49
- });
50
- }
10
+ // 创建一个 webview。
11
+ const webView = context.createSidebarWebView(context)
12
+ // 当命令被触发的时候。
13
+ context.onCommand('open.discord', () => {
14
+ const dir = join(__dirname, '../', 'dist', 'index.html')
15
+ const scriptReg = /<script.*?src="(.+?)".*?>/
16
+ const styleReg = /<link.*?rel="stylesheet".*?href="(.+?)".*?>/
17
+ const iconReg = /<link.*?rel="icon".*?href="(.+?)".*?>/g
18
+ // 创建 webview 路径
19
+ const styleUri = context.createExtensionDir(
20
+ join(__dirname, '../', 'dist', 'assets', 'index.css')
21
+ )
22
+ const scriptUri = context.createExtensionDir(
23
+ join(__dirname, '../', 'dist', 'assets', 'index.js')
24
+ )
25
+ // 确保路径存在
26
+ const html = readFileSync(dir, 'utf-8')
27
+ .replace(iconReg, ``)
28
+ .replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
29
+ .replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`)
30
+ // 立即渲染 webview
31
+ webView.loadWebView(html)
32
+ })
33
+ // 监听 webview 的消息。
34
+ webView.onMessage(data => {
35
+ try {
36
+ if (data.type === 'discord.form.save') {
37
+ const db = data.data
38
+ const config = getConfig()
39
+ const value = config.value ?? {}
40
+ value['discord'] = {
41
+ token: db.token ?? '',
42
+ master_key: db.master_key?.split(',') ?? null
51
43
  }
52
- catch (e) {
53
- console.error(e);
54
- }
55
- });
56
- };
44
+ config.saveValue(value)
45
+ context.notification('discord 配置保存成功~')
46
+ } else if (data.type === 'discord.init') {
47
+ let config = getConfigValue()
48
+ if (!config) config = {}
49
+ // 发送消息
50
+ webView.postMessage({
51
+ type: 'discord.init',
52
+ data: config.discord ?? {}
53
+ })
54
+ }
55
+ } catch (e) {
56
+ console.error(e)
57
+ }
58
+ })
59
+ }
57
60
 
58
- export { activate };
61
+ export { activate }
package/lib/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import * as alemonjs from 'alemonjs';
2
- import { DCClient } from './sdk/platform/discord/sdk/wss.js';
1
+ import { DCClient } from './sdk/platform/discord/sdk/wss.js'
3
2
 
4
- type Client = typeof DCClient.prototype;
5
- declare const client: Client;
6
- declare const platform = "discord";
7
- declare const _default: () => alemonjs.ClientAPI;
3
+ type Client = typeof DCClient.prototype
4
+ declare const client: Client
5
+ declare const platform = 'discord'
6
+ declare const _default: any
8
7
 
9
- export { type Client, client, _default as default, platform };
8
+ export { type Client, client, _default as default, platform }
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs';
1
+ import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
2
2
  import 'fs';
3
3
  import 'axios';
4
4
  import 'path';
@@ -103,31 +103,85 @@ var index = defineBot(() => {
103
103
  tag: 'MESSAGE_CREATE',
104
104
  value: null
105
105
  };
106
- // 当访问的时候获取
107
- Object.defineProperty(e, 'value', {
108
- get() {
109
- return event;
110
- }
111
- });
112
106
  // 处理消息
113
- OnProcessor(e, 'message.create');
107
+ onProcessor('message.create', e, event);
114
108
  });
115
109
  // 发送错误时
116
110
  client.on('ERROR', console.error);
117
111
  global.client = client;
118
112
  return {
113
+ platform,
119
114
  api: {
115
+ active: {
116
+ send: {
117
+ channel: (channel_id, val) => {
118
+ if (val.length < 0)
119
+ return Promise.all([]);
120
+ const content = val
121
+ .filter(item => item.type == 'Mention' || item.type == 'Text')
122
+ .map(item => {
123
+ // if (item.type == 'Link') {
124
+ // return `[${item.options?.title ?? item.value}](${item.value})`
125
+ // } else
126
+ if (item.type == 'Mention') {
127
+ if (item.value == 'everyone' ||
128
+ item.value == 'all' ||
129
+ item.value == '' ||
130
+ typeof item.value != 'string') {
131
+ return `<@everyone>`;
132
+ }
133
+ if (item.options?.belong == 'user') {
134
+ return `<@${item.value}>`;
135
+ }
136
+ else if (item.options?.belong == 'channel') {
137
+ return `<#${item.value}>`;
138
+ }
139
+ return '';
140
+ }
141
+ else if (item.type == 'Text') {
142
+ if (item.options?.style == 'block') {
143
+ return `\`${item.value}\``;
144
+ }
145
+ else if (item.options?.style == 'italic') {
146
+ return `*${item.value}*`;
147
+ }
148
+ else if (item.options?.style == 'bold') {
149
+ return `**${item.value}**`;
150
+ }
151
+ else if (item.options?.style == 'strikethrough') {
152
+ return `~~${item.value}~~`;
153
+ }
154
+ return item.value;
155
+ }
156
+ })
157
+ .join('');
158
+ if (content) {
159
+ return Promise.all([content].map(item => client.channelsMessages(channel_id, {
160
+ content: item
161
+ })));
162
+ }
163
+ const images = val.filter(item => item.type == 'Image').map(item => item.value);
164
+ if (images) {
165
+ return Promise.all(images.map(item => client.channelsMessagesImage(channel_id, item)));
166
+ }
167
+ return Promise.all([]);
168
+ },
169
+ user: (user_id, data) => {
170
+ return Promise.all([]);
171
+ }
172
+ }
173
+ },
120
174
  use: {
121
175
  send: (event, val) => {
122
176
  if (val.length < 0)
123
177
  return Promise.all([]);
124
178
  const content = val
125
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
179
+ .filter(item => item.type == 'Mention' || item.type == 'Text')
126
180
  .map(item => {
127
- if (item.type == 'Link') {
128
- return `[${item.options?.title ?? item.value}](${item.value})`;
129
- }
130
- else if (item.type == 'Mention') {
181
+ // if (item.type == 'Link') {
182
+ // return `[${item.options?.title ?? item.value}](${item.value})`
183
+ // } else
184
+ if (item.type == 'Mention') {
131
185
  if (item.value == 'everyone' ||
132
186
  item.value == 'all' ||
133
187
  item.value == '' ||