@alemonjs/kook 0.2.7 → 2.1.0-alpha.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.
Files changed (32) hide show
  1. package/lib/config.js +20 -0
  2. package/lib/desktop.d.ts +2 -2
  3. package/lib/desktop.js +54 -55
  4. package/lib/hook.d.ts +38 -0
  5. package/lib/hook.js +24 -0
  6. package/lib/index.d.ts +6 -7
  7. package/lib/index.js +314 -274
  8. package/lib/sdk/api.d.ts +275 -0
  9. package/lib/sdk/{platform/kook/sdk/api.js → api.js} +25 -26
  10. package/lib/sdk/{platform/kook/sdk/config.js → config.js} +1 -1
  11. package/lib/sdk/{platform/kook/sdk/message.js → message.js} +1 -4
  12. package/lib/sdk/typings.d.ts +109 -0
  13. package/package.json +2 -2
  14. package/dist/assets/index.css +0 -1
  15. package/dist/assets/index.js +0 -49
  16. package/dist/index.html +0 -15
  17. package/lib/sdk/core/utils/from.js +0 -42
  18. package/lib/sdk/platform/kook/sdk/api.d.ts +0 -288
  19. package/lib/sdk/platform/kook/sdk/message/INTERACTION.d.ts +0 -8
  20. package/lib/sdk/platform/kook/sdk/message/MEMBER_ADD.d.ts +0 -10
  21. package/lib/sdk/platform/kook/sdk/message/MEMBER_REMOVE.d.ts +0 -10
  22. package/lib/sdk/platform/kook/sdk/message/MESSAGES_DIRECT.d.ts +0 -10
  23. package/lib/sdk/platform/kook/sdk/message/MESSAGES_PUBLIC.d.ts +0 -10
  24. package/lib/sdk/platform/kook/sdk/message/REACTIONS.d.ts +0 -10
  25. package/lib/sdk/platform/kook/sdk/message.d.ts +0 -18
  26. package/lib/sdk/platform/kook/sdk/typings.d.ts +0 -221
  27. package/lib/sdk/platform/kook/sdk/wss.d.ts +0 -26
  28. package/lib/sdk/platform/kook/sdk/wss.types.d.ts +0 -12
  29. /package/lib/{sdk/core → core}/config.js +0 -0
  30. /package/lib/sdk/{platform/kook/sdk/conversation.js → conversation.js} +0 -0
  31. /package/lib/sdk/{platform/kook/sdk/typings.js → typings.js} +0 -0
  32. /package/lib/sdk/{platform/kook/sdk/wss.js → wss.js} +0 -0
package/lib/config.js ADDED
@@ -0,0 +1,20 @@
1
+ import { useUserHashKey, getConfigValue } from 'alemonjs';
2
+
3
+ const platform = 'telegram';
4
+ const getKOOKConfig = () => {
5
+ const value = getConfigValue() || {};
6
+ return value[platform] || {};
7
+ };
8
+ const getMaster = (UserId) => {
9
+ const config = getKOOKConfig();
10
+ const master_key = config.master_key || [];
11
+ const master_id = config.master_id || [];
12
+ const UserKey = useUserHashKey({
13
+ Platform: platform,
14
+ UserId: UserId
15
+ });
16
+ const is = master_key.includes(UserKey) || master_id.includes(UserId);
17
+ return [is, UserKey];
18
+ };
19
+
20
+ export { getKOOKConfig, getMaster, platform };
package/lib/desktop.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const activate: (context: any) => void
1
+ declare const activate: (context: any) => void;
2
2
 
3
- export { activate }
3
+ export { activate };
package/lib/desktop.js CHANGED
@@ -1,61 +1,60 @@
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.kook', () => {
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 === 'kook.form.save') {
37
- const db = data.data
38
- const config = getConfig()
39
- const value = config.value ?? {}
40
- value['kook'] = {
41
- token: db.token ?? '',
42
- master_key: db.master_key?.split(',') ?? null
10
+ // 创建一个 webview。
11
+ const webView = context.createSidebarWebView(context);
12
+ // 当命令被触发的时候。
13
+ context.onCommand('open.kook', () => {
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(join(__dirname, '../', 'dist', 'assets', 'index.css'));
20
+ const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
21
+ // 确保路径存在
22
+ const html = readFileSync(dir, 'utf-8')
23
+ .replace(iconReg, ``)
24
+ .replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
25
+ .replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
26
+ // 立即渲染 webview
27
+ webView.loadWebView(html);
28
+ });
29
+ // 监听 webview 的消息。
30
+ webView.onMessage(data => {
31
+ try {
32
+ if (data.type === 'kook.form.save') {
33
+ const db = data.data;
34
+ const config = getConfig();
35
+ const value = config.value ?? {};
36
+ value['kook'] = {
37
+ token: db.token ?? '',
38
+ master_key: db.master_key?.split(',') ?? null
39
+ };
40
+ config.saveValue(value);
41
+ context.notification('KOOK 配置保存成功~');
42
+ }
43
+ else if (data.type === 'kook.init') {
44
+ let config = getConfigValue();
45
+ if (!config)
46
+ config = {};
47
+ // 发送消息
48
+ webView.postMessage({
49
+ type: 'kook.init',
50
+ data: config.kook ?? {}
51
+ });
52
+ }
43
53
  }
44
- config.saveValue(value)
45
- context.notification('KOOK 配置保存成功~')
46
- } else if (data.type === 'kook.init') {
47
- let config = getConfigValue()
48
- if (!config) config = {}
49
- // 发送消息
50
- webView.postMessage({
51
- type: 'kook.init',
52
- data: config.kook ?? {}
53
- })
54
- }
55
- } catch (e) {
56
- console.error(e)
57
- }
58
- })
59
- }
54
+ catch (e) {
55
+ console.error(e);
56
+ }
57
+ });
58
+ };
60
59
 
61
- export { activate }
60
+ export { activate };
package/lib/hook.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { EventKeys, Events } from 'alemonjs';
2
+ import API from 'node-telegram-bot-api';
3
+ import { EventData } from './sdk/typings.js';
4
+
5
+ type MAP = {
6
+ 'message.create': EventData;
7
+ 'private.message.create': EventData;
8
+ 'interaction.create': undefined;
9
+ 'private.interaction.create': undefined;
10
+ 'message.update': undefined;
11
+ 'message.delete': undefined;
12
+ 'message.reaction.add': undefined;
13
+ 'message.reaction.remove': undefined;
14
+ 'channal.create': undefined;
15
+ 'channal.delete': undefined;
16
+ 'guild.join': undefined;
17
+ 'guild.exit': undefined;
18
+ 'member.add': undefined;
19
+ 'member.remove': undefined;
20
+ 'private.message.update': undefined;
21
+ 'private.message.delete': undefined;
22
+ 'private.friend.add': undefined;
23
+ 'private.guild.add': undefined;
24
+ };
25
+ /**
26
+ *
27
+ * @param event
28
+ * @returns
29
+ */
30
+ declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
31
+ /**
32
+ *
33
+ * @param event
34
+ * @returns
35
+ */
36
+ declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
37
+
38
+ export { useClient, useValue };
package/lib/hook.js ADDED
@@ -0,0 +1,24 @@
1
+ import { createEventValue, useClient as useClient$1 } from 'alemonjs';
2
+ import API from 'node-telegram-bot-api';
3
+
4
+ /**
5
+ *
6
+ * @param event
7
+ * @returns
8
+ */
9
+ const useValue = (event) => {
10
+ const value = createEventValue(event);
11
+ return [value];
12
+ };
13
+ /**
14
+ *
15
+ * @param event
16
+ * @returns
17
+ */
18
+ const useClient = (event) => {
19
+ const [client] = useClient$1(event, API);
20
+ const value = createEventValue(event);
21
+ return [client, value];
22
+ };
23
+
24
+ export { useClient, useValue };
package/lib/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import * as alemonjs from 'alemonjs'
2
- import { KOOKClient } from './sdk/platform/kook/sdk/wss.js'
1
+ export { useClient, useValue } from './hook.js';
2
+ export { KOOKAPI as API } from './sdk/api.js';
3
3
 
4
- type Client = typeof KOOKClient.prototype
5
- declare const platform = 'kook'
6
- declare const client: Client
7
- declare const _default: alemonjs.DefineBotValue
4
+ declare const platform = "kook";
8
5
 
9
- export { type Client, client, _default as default, platform }
6
+ declare const _default: () => void;
7
+
8
+ export { _default as default, platform };