@alemonjs/discord 0.2.2 → 0.2.3

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.
@@ -0,0 +1,3 @@
1
+ declare const activate: (context: any) => void;
2
+
3
+ export { activate };
package/lib/desktop.js ADDED
@@ -0,0 +1,58 @@
1
+ import { readFileSync } from 'fs';
2
+ import { dirname, join } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { getConfig, getConfigValue } from 'alemonjs';
5
+
6
+ // 当前目录
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ // 被激活的时候。
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 CIG = data.data;
32
+ const config = getConfig();
33
+ const value = config.value ?? {};
34
+ value['discord'] = {
35
+ token: CIG.token ?? '',
36
+ master_key: CIG.master_key.split(',')
37
+ };
38
+ config.saveValue(value);
39
+ context.notification('DC 配置保存成功~');
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.qq_bot ?? {}
49
+ });
50
+ }
51
+ }
52
+ catch (e) {
53
+ console.error(e);
54
+ }
55
+ });
56
+ };
57
+
58
+ export { activate };
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import * as alemonjs from 'alemonjs';
2
+ import { DCClient } from './sdk/platform/discord/sdk/wss.js';
3
+
4
+ type Client = typeof DCClient.prototype;
5
+ declare const client: Client;
6
+ declare const platform = "discord";
7
+ declare const _default: () => alemonjs.ClientAPI;
8
+
9
+ export { type Client, client, _default as default, platform };
package/lib/index.js CHANGED
@@ -21,7 +21,9 @@ const client = new Proxy({}, {
21
21
  });
22
22
  const platform = 'discord';
23
23
  var index = defineBot(() => {
24
- const value = getConfigValue();
24
+ let value = getConfigValue();
25
+ if (!value)
26
+ value = {};
25
27
  const config = value[platform];
26
28
  // 创建客户端
27
29
  const client = new DCClient({
@@ -79,6 +81,7 @@ var index = defineBot(() => {
79
81
  };
80
82
  // 定义消
81
83
  const e = {
84
+ name: 'message.create',
82
85
  // 事件类型
83
86
  Platform: platform,
84
87
  // guild