@alemonjs/qq-bot 0.0.18 → 0.0.19

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/lib/hook.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { EventKeys, Events } from 'alemonjs';
2
+
3
+ /**
4
+ * 判断当前模式
5
+ * @param event
6
+ * @returns
7
+ */
8
+ declare const useMode: <T extends EventKeys>(event: Events[T]) => (mode: "guild" | "group") => boolean;
9
+
10
+ export { useMode };
package/lib/hook.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 判断当前模式
3
+ * @param event
4
+ * @returns
5
+ */
6
+ const useMode = (event) => {
7
+ const tag = event.tag;
8
+ let currentMode = 'group';
9
+ // 群at
10
+ if (tag == 'GROUP_AT_MESSAGE_CREATE') {
11
+ currentMode = 'group';
12
+ }
13
+ // 私聊
14
+ if (tag == 'C2C_MESSAGE_CREATE') {
15
+ currentMode = 'group';
16
+ }
17
+ // 频道私聊
18
+ if (tag == 'DIRECT_MESSAGE_CREATE') {
19
+ currentMode = 'guild';
20
+ }
21
+ // 频道at
22
+ if (tag == 'AT_MESSAGE_CREATE') {
23
+ currentMode = 'guild';
24
+ }
25
+ // 频道消息
26
+ if (tag == 'MESSAGE_CREATE') {
27
+ currentMode = 'guild';
28
+ }
29
+ const isMode = (mode) => {
30
+ return currentMode == mode;
31
+ };
32
+ return isMode;
33
+ };
34
+
35
+ export { useMode };
package/lib/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import * as alemonjs from 'alemonjs';
2
2
  import { QQBotAPI } from './sdk/api.js';
3
+ export { useMode } from './hook.js';
3
4
 
4
5
  type Client = typeof QQBotAPI.prototype;
5
6
  declare const client: Client;
6
7
  declare const platform = "qq-bot";
8
+
7
9
  declare const _default: alemonjs.DefinePlatformValue;
8
10
 
9
11
  export { type Client, client, _default as default, platform };
@@ -1,10 +1,10 @@
1
- import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
1
+ import { getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
2
2
  import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
3
3
  import { QQBotGroupClient } from './sdk/websoket.group.js';
4
4
  import { isGuild } from './utils.js';
5
5
 
6
6
  const platform = 'qq-bot';
7
- var QQBotGroup = defineBot(() => {
7
+ var QQBotGroup = definePlatform(() => {
8
8
  let value = getConfigValue();
9
9
  if (!value)
10
10
  value = {};
@@ -1,10 +1,10 @@
1
- import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
1
+ import { getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
2
2
  import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
3
3
  import { QQBotGuildClient } from './sdk/websoket.guild.js';
4
4
  import { isGuild } from './utils.js';
5
5
 
6
6
  const platform = 'qq-bot';
7
- var QQBotGuild = defineBot(() => {
7
+ var QQBotGuild = definePlatform(() => {
8
8
  let value = getConfigValue();
9
9
  if (!value)
10
10
  value = {};
package/lib/index.js CHANGED
@@ -4,6 +4,7 @@ import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_
4
4
  import QQBotGroup from './index.group.js';
5
5
  import QQBotGuild from './index.guild.js';
6
6
  import { isGuild } from './utils.js';
7
+ export { useMode } from './hook.js';
7
8
 
8
9
  const client = new Proxy({}, {
9
10
  get: (_, prop) => {
@@ -93,7 +93,7 @@ class QQBotGroupClient extends QQBotAPI {
93
93
  await this.#setTimeoutBotConfig();
94
94
  // 请求url
95
95
  if (!this.#gatewayUrl) {
96
- this.#gatewayUrl = gatewayURL ?? await this.gateway().then(res => res?.url);
96
+ this.#gatewayUrl = gatewayURL ?? (await this.gateway().then(res => res?.url));
97
97
  }
98
98
  if (!this.#gatewayUrl)
99
99
  return;
@@ -70,15 +70,17 @@ class QQBotGuildClient extends QQBotAPI {
70
70
  */
71
71
  async connect(gatewayURL) {
72
72
  //
73
- this.#gatewayUrl = gatewayURL ?? await this.gateway()
74
- .then(res => res.url)
75
- .catch(err => {
76
- if (this.#events['ERROR']) {
77
- for (const item of this.#events['ERROR']) {
78
- item(err);
79
- }
80
- }
81
- });
73
+ this.#gatewayUrl =
74
+ gatewayURL ??
75
+ (await this.gateway()
76
+ .then(res => res.url)
77
+ .catch(err => {
78
+ if (this.#events['ERROR']) {
79
+ for (const item of this.#events['ERROR']) {
80
+ item(err);
81
+ }
82
+ }
83
+ }));
82
84
  // 请求url
83
85
  if (!this.#gatewayUrl)
84
86
  return this;
package/lib/send/index.js CHANGED
@@ -12,27 +12,27 @@ const createButtonsData = (rows) => {
12
12
  const options = button.options;
13
13
  id++;
14
14
  return {
15
- "id": String(id),
16
- "render_data": {
17
- "label": typeof value == 'object' ? value.title : value,
18
- "visited_label": typeof value == 'object' ? value.label : value,
15
+ id: String(id),
16
+ render_data: {
17
+ label: typeof value == 'object' ? value.title : value,
18
+ visited_label: typeof value == 'object' ? value.label : value,
19
19
  // tudo
20
- "style": 0
20
+ style: 0
21
21
  },
22
- "action": {
23
- // 0 link 1 callback , 2 command
24
- "type": typeof options.data === 'object' ? 1 : (options?.isLink ? 0 : 2),
25
- "permission": {
22
+ action: {
23
+ // 0 link 1 callback , 2 command
24
+ type: typeof options.data === 'object' ? 1 : options?.isLink ? 0 : 2,
25
+ permission: {
26
26
  // 所有人
27
- "type": 2,
27
+ type: 2
28
28
  // "specify_role_ids": ["1", "2", "3"]
29
29
  },
30
30
  // "click_limit": 10,
31
- "unsupport_tips": options?.toolTip ?? '',
32
- "data": options?.data ?? '',
31
+ unsupport_tips: options?.toolTip ?? '',
32
+ data: options?.data ?? '',
33
33
  // reply: true,
34
- "at_bot_show_channel_list": options.showList ?? false,
35
- "enter": options?.autoEnter ?? false
34
+ at_bot_show_channel_list: options.showList ?? false,
35
+ enter: options?.autoEnter ?? false
36
36
  }
37
37
  };
38
38
  })
@@ -47,7 +47,7 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
47
47
  .map(item => {
48
48
  // if (item.type == 'Link') {
49
49
  // return `[${item.options?.title ?? item.value}](${item.value})`
50
- // } else
50
+ // } else
51
51
  if (item.type == 'Mention') {
52
52
  if (item.value == 'everyone' ||
53
53
  item.value == 'all' ||
@@ -126,7 +126,7 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
126
126
  });
127
127
  }
128
128
  const rows = item.value;
129
- // 构造成按钮
129
+ // 构造成按钮
130
130
  const data = createButtonsData(rows);
131
131
  return client.groupOpenMessages(event.GuildId, {
132
132
  content: '',
@@ -216,7 +216,7 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
216
216
  rows.map(row => {
217
217
  return row;
218
218
  });
219
- // 构造成按钮
219
+ // 构造成按钮
220
220
  const data = createButtonsData(rows);
221
221
  return client.groupOpenMessages(event.GuildId, {
222
222
  content: '',
@@ -284,7 +284,7 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
284
284
  .map(item => {
285
285
  // if (item.type == 'Link') {
286
286
  // return `[${item.options?.title ?? item.value}](${item.value})`
287
- // } else
287
+ // } else
288
288
  if (item.type == 'Mention') {
289
289
  if (item.value == 'everyone' ||
290
290
  item.value == 'all' ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "阿柠檬qqbot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",