alemonjs 1.0.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 (169) hide show
  1. package/LICENSE +340 -0
  2. package/README.md +54 -0
  3. package/lib/alemon/app.js +38 -0
  4. package/lib/alemon/apps.js +121 -0
  5. package/lib/alemon/buffer.js +38 -0
  6. package/lib/alemon/dealmsg.js +423 -0
  7. package/lib/alemon/dialogue.js +61 -0
  8. package/lib/alemon/index.js +40 -0
  9. package/lib/alemon/message.js +27 -0
  10. package/lib/alemon/plugin.js +44 -0
  11. package/lib/alemon/puppeteer.js +226 -0
  12. package/lib/alemon/qrcode.js +66 -0
  13. package/lib/alemon/screenshot.js +126 -0
  14. package/lib/alemon/typings.js +96 -0
  15. package/lib/config.js +25 -0
  16. package/lib/discord/alemon/api.js +44 -0
  17. package/lib/discord/alemon/bot.js +11 -0
  18. package/lib/discord/alemon/conversation.js +7 -0
  19. package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +185 -0
  20. package/lib/discord/alemon/segment.js +62 -0
  21. package/lib/discord/index.js +50 -0
  22. package/lib/discord/login.js +99 -0
  23. package/lib/index.js +12 -0
  24. package/lib/kook/alemon/bot.js +11 -0
  25. package/lib/kook/alemon/conversation.js +56 -0
  26. package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +195 -0
  27. package/lib/kook/alemon/segment.js +90 -0
  28. package/lib/kook/index.js +39 -0
  29. package/lib/kook/login.js +53 -0
  30. package/lib/login.js +112 -0
  31. package/lib/main.js +106 -0
  32. package/lib/ntqq/alemon/bot.js +11 -0
  33. package/lib/ntqq/alemon/conversation.js +18 -0
  34. package/lib/ntqq/alemon/message/C2C_MESSAGE_CREATE.js +142 -0
  35. package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +218 -0
  36. package/lib/ntqq/alemon/segment.js +29 -0
  37. package/lib/ntqq/alemon/types.js +1 -0
  38. package/lib/ntqq/index.js +77 -0
  39. package/lib/ntqq/login.js +74 -0
  40. package/lib/ntqq/sdk/api.js +158 -0
  41. package/lib/ntqq/sdk/config.js +46 -0
  42. package/lib/ntqq/sdk/index.js +5 -0
  43. package/lib/ntqq/sdk/intents.js +69 -0
  44. package/lib/ntqq/sdk/types.js +1 -0
  45. package/lib/ntqq/sdk/typings.js +9 -0
  46. package/lib/ntqq/sdk/web/client.js +89 -0
  47. package/lib/ntqq/sdk/web/img.js +76 -0
  48. package/lib/ntqq/sdk/web/index.js +4 -0
  49. package/lib/ntqq/sdk/web/ip.js +24 -0
  50. package/lib/ntqq/sdk/wss.js +178 -0
  51. package/lib/qq/alemon/apidoc.js +216 -0
  52. package/lib/qq/alemon/bot.js +11 -0
  53. package/lib/qq/alemon/console.js +13 -0
  54. package/lib/qq/alemon/conversation.js +139 -0
  55. package/lib/qq/alemon/doc.js +93 -0
  56. package/lib/qq/alemon/e.js +41 -0
  57. package/lib/qq/alemon/message/AUDIO_ACTION.js +57 -0
  58. package/lib/qq/alemon/message/DIRECT_MESSAGE.js +202 -0
  59. package/lib/qq/alemon/message/FORUMS_EVENT.js +66 -0
  60. package/lib/qq/alemon/message/GUILDS.js +65 -0
  61. package/lib/qq/alemon/message/GUILD_MEMBERS.js +153 -0
  62. package/lib/qq/alemon/message/GUILD_MESSAGES.js +50 -0
  63. package/lib/qq/alemon/message/GUILD_MESSAGE_REACTIONS.js +37 -0
  64. package/lib/qq/alemon/message/INTERACTION.js +36 -0
  65. package/lib/qq/alemon/message/MESSAGE.js +303 -0
  66. package/lib/qq/alemon/message/MESSAGE_AUDIT.js +41 -0
  67. package/lib/qq/alemon/message/OPEN_FORUMS_EVENT.js +74 -0
  68. package/lib/qq/alemon/message/PUBLIC_GUILD_MESSAGES.js +52 -0
  69. package/lib/qq/alemon/permissions.js +43 -0
  70. package/lib/qq/alemon/privatechat.js +78 -0
  71. package/lib/qq/alemon/segment.js +25 -0
  72. package/lib/qq/alemon/types.js +25 -0
  73. package/lib/qq/index.js +44 -0
  74. package/lib/qq/login.js +151 -0
  75. package/lib/types.js +5 -0
  76. package/lib/villa/alemon/conversation.js +48 -0
  77. package/lib/villa/alemon/message/GUILDS.js +124 -0
  78. package/lib/villa/alemon/message/GUILD_MEMBERS.js +128 -0
  79. package/lib/villa/alemon/message/GUILD_MESSAGE_REACTIONS.js +127 -0
  80. package/lib/villa/alemon/message/MESSAGES.js +334 -0
  81. package/lib/villa/alemon/message/MESSAGE_AUDIT.js +128 -0
  82. package/lib/villa/alemon/message/e.js +41 -0
  83. package/lib/villa/alemon/segment.js +34 -0
  84. package/lib/villa/index.js +46 -0
  85. package/lib/villa/login.js +62 -0
  86. package/package.json +63 -0
  87. package/types/alemon/app.d.ts +22 -0
  88. package/types/alemon/apps.d.ts +41 -0
  89. package/types/alemon/buffer.d.ts +13 -0
  90. package/types/alemon/dealmsg.d.ts +41 -0
  91. package/types/alemon/dialogue.d.ts +55 -0
  92. package/types/alemon/index.d.ts +40 -0
  93. package/types/alemon/message.d.ts +17 -0
  94. package/types/alemon/plugin.d.ts +69 -0
  95. package/types/alemon/puppeteer.d.ts +53 -0
  96. package/types/alemon/qrcode.d.ts +20 -0
  97. package/types/alemon/screenshot.d.ts +23 -0
  98. package/types/alemon/typings.d.ts +525 -0
  99. package/types/config.d.ts +12 -0
  100. package/types/discord/alemon/api.d.ts +11 -0
  101. package/types/discord/alemon/bot.d.ts +6 -0
  102. package/types/discord/alemon/conversation.d.ts +6 -0
  103. package/types/discord/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +7 -0
  104. package/types/discord/alemon/segment.d.ts +46 -0
  105. package/types/discord/index.d.ts +1 -0
  106. package/types/discord/login.d.ts +7 -0
  107. package/types/index.d.ts +6 -0
  108. package/types/kook/alemon/bot.d.ts +8 -0
  109. package/types/kook/alemon/conversation.d.ts +7 -0
  110. package/types/kook/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +6 -0
  111. package/types/kook/alemon/segment.d.ts +66 -0
  112. package/types/kook/index.d.ts +5 -0
  113. package/types/kook/login.d.ts +7 -0
  114. package/types/login.d.ts +18 -0
  115. package/types/main.d.ts +15 -0
  116. package/types/ntqq/alemon/bot.d.ts +8 -0
  117. package/types/ntqq/alemon/conversation.d.ts +8 -0
  118. package/types/ntqq/alemon/message/C2C_MESSAGE_CREATE.d.ts +2 -0
  119. package/types/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.d.ts +8 -0
  120. package/types/ntqq/alemon/segment.d.ts +20 -0
  121. package/types/ntqq/alemon/types.d.ts +11 -0
  122. package/types/ntqq/index.d.ts +1 -0
  123. package/types/ntqq/login.d.ts +6 -0
  124. package/types/ntqq/sdk/api.d.ts +44 -0
  125. package/types/ntqq/sdk/config.d.ts +23 -0
  126. package/types/ntqq/sdk/index.d.ts +5 -0
  127. package/types/ntqq/sdk/intents.d.ts +2 -0
  128. package/types/ntqq/sdk/types.d.ts +11 -0
  129. package/types/ntqq/sdk/typings.d.ts +17 -0
  130. package/types/ntqq/sdk/web/client.d.ts +8 -0
  131. package/types/ntqq/sdk/web/img.d.ts +20 -0
  132. package/types/ntqq/sdk/web/index.d.ts +4 -0
  133. package/types/ntqq/sdk/web/ip.d.ts +5 -0
  134. package/types/ntqq/sdk/wss.d.ts +35 -0
  135. package/types/qq/alemon/apidoc.d.ts +154 -0
  136. package/types/qq/alemon/bot.d.ts +8 -0
  137. package/types/qq/alemon/console.d.ts +1 -0
  138. package/types/qq/alemon/conversation.d.ts +5 -0
  139. package/types/qq/alemon/doc.d.ts +93 -0
  140. package/types/qq/alemon/e.d.ts +38 -0
  141. package/types/qq/alemon/message/AUDIO_ACTION.d.ts +15 -0
  142. package/types/qq/alemon/message/DIRECT_MESSAGE.d.ts +16 -0
  143. package/types/qq/alemon/message/FORUMS_EVENT.d.ts +25 -0
  144. package/types/qq/alemon/message/GUILDS.d.ts +19 -0
  145. package/types/qq/alemon/message/GUILD_MEMBERS.d.ts +11 -0
  146. package/types/qq/alemon/message/GUILD_MESSAGES.d.ts +12 -0
  147. package/types/qq/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +9 -0
  148. package/types/qq/alemon/message/INTERACTION.d.ts +8 -0
  149. package/types/qq/alemon/message/MESSAGE.d.ts +16 -0
  150. package/types/qq/alemon/message/MESSAGE_AUDIT.d.ts +9 -0
  151. package/types/qq/alemon/message/OPEN_FORUMS_EVENT.d.ts +28 -0
  152. package/types/qq/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +12 -0
  153. package/types/qq/alemon/permissions.d.ts +29 -0
  154. package/types/qq/alemon/privatechat.d.ts +14 -0
  155. package/types/qq/alemon/segment.d.ts +19 -0
  156. package/types/qq/alemon/types.d.ts +82 -0
  157. package/types/qq/index.d.ts +6 -0
  158. package/types/qq/login.d.ts +6 -0
  159. package/types/types.d.ts +85 -0
  160. package/types/villa/alemon/conversation.d.ts +7 -0
  161. package/types/villa/alemon/message/GUILDS.d.ts +10 -0
  162. package/types/villa/alemon/message/GUILD_MEMBERS.d.ts +14 -0
  163. package/types/villa/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +7 -0
  164. package/types/villa/alemon/message/MESSAGES.d.ts +7 -0
  165. package/types/villa/alemon/message/MESSAGE_AUDIT.d.ts +10 -0
  166. package/types/villa/alemon/message/e.d.ts +37 -0
  167. package/types/villa/alemon/segment.d.ts +26 -0
  168. package/types/villa/index.d.ts +1 -0
  169. package/types/villa/login.d.ts +7 -0
@@ -0,0 +1,90 @@
1
+ export const segmentKOOK = {
2
+ /**
3
+ * 艾特某人
4
+ * @param uid
5
+ * @returns
6
+ */
7
+ at: function (uid) {
8
+ return `(met)${uid}(met)`;
9
+ },
10
+ /**
11
+ * 艾特全体
12
+ * @returns
13
+ */
14
+ atAll: function atAll() {
15
+ return `(met)all(met)`;
16
+ },
17
+ /**
18
+ * 子频道引用
19
+ * @param channel_id
20
+ * @returns
21
+ */
22
+ atChannel: function (channel_id) {
23
+ return `(chn)${channel_id}(chn)`;
24
+ },
25
+ /**
26
+ * 蓝链接
27
+ * @param name
28
+ * @param url
29
+ * @returns
30
+ */
31
+ link: function (name, url) {
32
+ return `[${name}](${url})`;
33
+ },
34
+ /**
35
+ *
36
+ * @param role_id 角色
37
+ */
38
+ role: function (role_id) {
39
+ return `(rol)${role_id}(rol)`;
40
+ },
41
+ /**
42
+ * 点击后才显示
43
+ * @param content 内容
44
+ */
45
+ spoiler: function (content) {
46
+ return ``;
47
+ },
48
+ /**
49
+ *
50
+ * @param name 服务器表情名
51
+ * @param id 服务器表情id
52
+ */
53
+ expression: function (name, id) {
54
+ return `(emj)${name}(emj)[${id}]`;
55
+ },
56
+ /**
57
+ * 加粗
58
+ * @param txt
59
+ */
60
+ Bold: function (txt) {
61
+ return `**${txt}**`;
62
+ },
63
+ /**
64
+ * 斜体
65
+ * @param txt
66
+ */
67
+ italic: function (txt) {
68
+ return `*${txt}*`;
69
+ },
70
+ /**
71
+ * 加粗斜体
72
+ */
73
+ boldItalic: function (txt) {
74
+ return `***${txt}***`;
75
+ },
76
+ /**
77
+ * 删除线
78
+ * @param txt
79
+ */
80
+ strikethrough: function (txt) {
81
+ return `~~${txt}~~`;
82
+ },
83
+ /**
84
+ * 代码块
85
+ * @param txt
86
+ */
87
+ block: function (txt) {
88
+ return `\`${txt}\``;
89
+ }
90
+ };
@@ -0,0 +1,39 @@
1
+ import { checkRobotByKOOK } from './login.js';
2
+ import { callBackByKOOK } from './alemon/conversation.js';
3
+ import { createClient, KOOKApiClient } from 'kook-ws';
4
+ import { setBotMsgByKOOK } from './alemon/bot.js';
5
+ import { getBotConfigByKey } from '../login.js';
6
+ /**
7
+ * 创建实例
8
+ * @returns
9
+ */
10
+ export async function createAlemonByKOOK() {
11
+ /**
12
+ * 创建登录配置
13
+ */
14
+ if (await checkRobotByKOOK().catch(err => {
15
+ console.error(err);
16
+ process.exit();
17
+ })) {
18
+ /**
19
+ * 读取配置
20
+ */
21
+ const cfg = await getBotConfigByKey('kook');
22
+ /**
23
+ * 创建连接
24
+ */
25
+ await createClient(cfg.token, callBackByKOOK).then(async (res) => {
26
+ const data = await KOOKApiClient.getBotInformation();
27
+ if (data) {
28
+ setBotMsgByKOOK({
29
+ id: data.id,
30
+ name: data.username,
31
+ avatar: data.avatar
32
+ });
33
+ console.info('[KOOK] 欢迎回来~', data.username);
34
+ }
35
+ });
36
+ return true;
37
+ }
38
+ return false;
39
+ }
@@ -0,0 +1,53 @@
1
+ import prompts from 'prompts';
2
+ import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
3
+ import { getToml, writeToml } from '../config.js';
4
+ /**
5
+ * 登录配置
6
+ * @param Bcf
7
+ * @param val
8
+ * @returns
9
+ */
10
+ export async function checkRobotByKOOK() {
11
+ /**
12
+ * 读取配置
13
+ */
14
+ if (process.argv.indexOf('login') == -1) {
15
+ const config = getBotConfigByKey('kook');
16
+ if ((config ?? '') !== '' && (config.token ?? '') !== '') {
17
+ setBotConfigByKey('kook', config);
18
+ return true;
19
+ }
20
+ }
21
+ console.info('[LOGIN]', '-----------------------');
22
+ const timeoutId = setTimeout(() => {
23
+ throw '超过1分钟未完成登录';
24
+ }, 60000);
25
+ const { token } = await prompts([
26
+ {
27
+ type: 'password',
28
+ name: 'token',
29
+ message: 'BotToken: ',
30
+ validate: (value) => value !== '' && typeof value === 'string' ? true : '机器人 token: '
31
+ }
32
+ ]).catch((err) => {
33
+ console.error(err);
34
+ process.exit();
35
+ });
36
+ if (!token)
37
+ return false;
38
+ clearTimeout(timeoutId);
39
+ // 得到已变更的配置
40
+ const db = getBotConfigByKey('kook');
41
+ // 得到配置
42
+ const data = getToml();
43
+ data.kook = {
44
+ ...db,
45
+ // 覆盖新配置
46
+ token
47
+ };
48
+ // 写入配置
49
+ writeToml(data);
50
+ // 设置配置
51
+ setBotConfigByKey('kook', data.kook);
52
+ return true;
53
+ }
package/lib/login.js ADDED
@@ -0,0 +1,112 @@
1
+ const config = {
2
+ redis: {
3
+ host: '127.0.0.1',
4
+ port: 6379,
5
+ password: '',
6
+ db: 1
7
+ },
8
+ mysql: {
9
+ host: '127.0.0.1',
10
+ port: 3306,
11
+ user: 'root',
12
+ password: '',
13
+ database: 'alemon'
14
+ },
15
+ discord: {
16
+ token: '',
17
+ masterID: '',
18
+ password: '',
19
+ intents: []
20
+ },
21
+ kook: {
22
+ token: '',
23
+ masterID: '',
24
+ password: ''
25
+ },
26
+ villa: {
27
+ bot_id: '',
28
+ secret: '',
29
+ pub_key: '',
30
+ masterID: '',
31
+ password: '',
32
+ http: 'http',
33
+ url: '/api/mys/callback',
34
+ port: 8080,
35
+ size: 999999,
36
+ img_url: '/api/mys/img',
37
+ IMAGE_DIR: '/data/mys/img'
38
+ },
39
+ qq: {
40
+ appID: '',
41
+ token: '',
42
+ masterID: '',
43
+ password: '',
44
+ intents: [],
45
+ isPrivate: false,
46
+ sandbox: false
47
+ },
48
+ ntqq: {
49
+ appID: '',
50
+ token: '',
51
+ secret: '',
52
+ masterID: '',
53
+ password: '',
54
+ intents: [],
55
+ port: 9090,
56
+ size: 999999,
57
+ img_url: '/api/mys/img',
58
+ IMAGE_DIR: '/data/mys/img',
59
+ http: 'http'
60
+ },
61
+ server: {
62
+ host: '127.0.0.1',
63
+ port: 5000
64
+ },
65
+ puppeteer: {
66
+ headless: 'new',
67
+ timeout: 30000,
68
+ args: [
69
+ '--disable-gpu',
70
+ '--disable-dev-shm-usage',
71
+ '--disable-setuid-sandbox',
72
+ '--no-first-run',
73
+ '--no-sandbox',
74
+ '--no-zygote',
75
+ '--single-process'
76
+ ]
77
+ }
78
+ };
79
+ /**
80
+ * 初始化配置
81
+ * @param val
82
+ */
83
+ export function setBotConfig(val) {
84
+ // 分布覆盖
85
+ for (const item in val) {
86
+ // 当且仅当存在同key的时候才会覆盖默认配置
87
+ for (const i in val[item]) {
88
+ // 当前仅当同属性名的时候才会覆盖默认配置
89
+ config[item][i] = val[item][i];
90
+ }
91
+ }
92
+ }
93
+ /**
94
+ * 设置
95
+ * @param key
96
+ * @param val
97
+ */
98
+ export function setBotConfigByKey(key, val) {
99
+ // 分布覆盖
100
+ for (const item in val) {
101
+ // 当前仅当同属性名的时候才会覆盖默认配置
102
+ config[key][item] = val[item];
103
+ }
104
+ }
105
+ /**
106
+ * 得到配置
107
+ * @param key
108
+ * @returns
109
+ */
110
+ export function getBotConfigByKey(key) {
111
+ return config[key];
112
+ }
package/lib/main.js ADDED
@@ -0,0 +1,106 @@
1
+ import { setLanchConfig } from './alemon/index.js';
2
+ import { getBotConfigByKey, setBotConfig } from './login.js';
3
+ import { getToml } from './config.js';
4
+ import { loadInit } from './alemon/index.js';
5
+ import { ClientAPIByQQ } from './ntqq/sdk/index.js';
6
+ import { compilationTools } from 'alemon-rollup';
7
+ /**
8
+ * 启动机器人
9
+ */
10
+ const createAlemon = {
11
+ qq: async () => {
12
+ const { createAlemonByQQ: qq } = await import('./qq/index.js');
13
+ return qq().catch(err => {
14
+ console.error(err);
15
+ console.error('QQ机器人启动失败~');
16
+ return false;
17
+ });
18
+ },
19
+ villa: async () => {
20
+ const { createAlemonByVilla: villa } = await import('./villa/index.js');
21
+ return villa().catch(err => {
22
+ console.error(err);
23
+ console.error('Villa机器人启动失败~');
24
+ return false;
25
+ });
26
+ },
27
+ kook: async () => {
28
+ const { createAlemonByKOOK: kook } = await import('./kook/index.js');
29
+ return kook().catch(err => {
30
+ console.error(err);
31
+ console.error('KOOK机器人启动失败~');
32
+ return false;
33
+ });
34
+ },
35
+ discord: async () => {
36
+ const { createAlemonByDiscord: dc } = await import('./discord/index.js');
37
+ return dc().catch(err => {
38
+ console.error(err);
39
+ console.error('Discord机器人启动失败~');
40
+ return false;
41
+ });
42
+ },
43
+ ntqq: async () => {
44
+ const { createAlemonByNtqq: ntqq } = await import('./ntqq/index.js');
45
+ return ntqq().catch(err => {
46
+ console.error(err);
47
+ console.error('Ntqq机器人启动失败~');
48
+ return false;
49
+ });
50
+ }
51
+ };
52
+ /**
53
+ * 创建机器人
54
+ * @param val
55
+ * @returns
56
+ */
57
+ export async function createBot(val = {
58
+ args: process.argv.slice(2),
59
+ mount: false,
60
+ address: '/application'
61
+ }) {
62
+ const { args, mount, cfg, address } = val;
63
+ /**
64
+ * 加载配置
65
+ */
66
+ await setBotConfig(getToml(cfg));
67
+ /**
68
+ * 设置浏览器配置
69
+ */
70
+ await setLanchConfig(getBotConfigByKey('puppeteer'));
71
+ /**
72
+ * 控制
73
+ */
74
+ const arr = [];
75
+ /**
76
+ * 开始启动
77
+ */
78
+ for await (const item of args ?? process.argv.slice(2)) {
79
+ if (arr.indexOf(item) != -1)
80
+ continue;
81
+ if (!createAlemon[item])
82
+ continue;
83
+ arr.push(item);
84
+ await createAlemon[item]();
85
+ }
86
+ /**
87
+ * 启动插件加载
88
+ */
89
+ await loadInit({
90
+ mount: mount == undefined ? false : mount,
91
+ address: address == undefined ? '/application' : address
92
+ });
93
+ return compilationTools;
94
+ }
95
+ // 机器人配置
96
+ export { getBotConfigByKey, setBotConfigByKey } from './login.js';
97
+ // 设置独立鉴权路径
98
+ export const setAuthenticationByNtqq = ClientAPIByQQ.setAuthentication;
99
+ // 监听退出
100
+ process.on('SIGINT', signals => {
101
+ console.info(signals);
102
+ if (process.pid) {
103
+ process.exit();
104
+ }
105
+ return;
106
+ });
@@ -0,0 +1,11 @@
1
+ let bot = {
2
+ id: '',
3
+ name: '',
4
+ avatar: 'string'
5
+ };
6
+ export function setBotMsgByNtqq(val) {
7
+ bot = val;
8
+ }
9
+ export function getBotMsgByNtqq() {
10
+ return bot;
11
+ }
@@ -0,0 +1,18 @@
1
+ import { GROUP_AT_MESSAGE_CREATE } from './message/GROUP_AT_MESSAGE_CREATE.js';
2
+ import { C2C_MESSAGE_CREATE } from './message/C2C_MESSAGE_CREATE.js';
3
+ import { setBotMsgByNtqq } from './bot.js';
4
+ /**
5
+ * 回话对象
6
+ */
7
+ export const conversation = {
8
+ READY: async (data) => {
9
+ // 设置bot信息
10
+ setBotMsgByNtqq({
11
+ id: data.user.id,
12
+ name: data.user.name,
13
+ avatar: 'string'
14
+ });
15
+ },
16
+ GROUP_AT_MESSAGE_CREATE: GROUP_AT_MESSAGE_CREATE,
17
+ C2C_MESSAGE_CREATE: C2C_MESSAGE_CREATE
18
+ };
@@ -0,0 +1,142 @@
1
+ import { InstructionMatching } from '../../../alemon/index.js';
2
+ import { ClientAPIByQQ as Client, ClinetWeb, getWebConfig } from '../../sdk/index.js';
3
+ import { segmentQQ } from '../segment.js';
4
+ import { getBotMsgByNtqq } from '../bot.js';
5
+ import IMGS from 'image-size';
6
+ /**
7
+ * 获取ip
8
+ */
9
+ const ip = await ClinetWeb.getIP();
10
+ export const C2C_MESSAGE_CREATE = async (event) => {
11
+ const e = {};
12
+ const webCfg = getWebConfig();
13
+ e.platform = 'ntqq';
14
+ e.bot = getBotMsgByNtqq();
15
+ e.event = 'MESSAGES';
16
+ e.eventType = 'CREATE';
17
+ e.isPrivate = false;
18
+ e.isRecall = false;
19
+ e.isGroup = false;
20
+ /* 消息发送机制 */
21
+ e.reply = async (msg, img, name) => {
22
+ if (Buffer.isBuffer(msg)) {
23
+ try {
24
+ let url = '';
25
+ if (Buffer.isBuffer(msg)) {
26
+ const uul = await ClinetWeb.setLocalImg(msg);
27
+ url = `${webCfg.http}://${ip}:${webCfg.callback_port}${uul}`;
28
+ return await Client.postFilesByGroup(event.group_id, url).catch(err => {
29
+ console.error(err);
30
+ return false;
31
+ });
32
+ }
33
+ }
34
+ catch (err) {
35
+ console.error(err);
36
+ return false;
37
+ }
38
+ }
39
+ const content = Array.isArray(msg)
40
+ ? msg.join('')
41
+ : typeof msg === 'string'
42
+ ? msg
43
+ : undefined;
44
+ if (Buffer.isBuffer(img)) {
45
+ try {
46
+ let url = '';
47
+ const dimensions = IMGS.imageSize(img);
48
+ const uul = await ClinetWeb.setLocalImg(img);
49
+ url = `${webCfg.http}://${ip}:${webCfg.callback_port}${uul}`;
50
+ return await Client.postMessageByGroup(event.group_id, `${content} ![text #${dimensions.width}px #${dimensions.height}px](${url})`, event.id)
51
+ .then(() => true)
52
+ .catch((err) => {
53
+ console.error(err);
54
+ return false;
55
+ });
56
+ }
57
+ catch (err) {
58
+ console.error(err);
59
+ return false;
60
+ }
61
+ }
62
+ return await Client.postMessageByUser(event.author.id, content, event.id)
63
+ .then(() => true)
64
+ .catch((err) => {
65
+ console.error(err);
66
+ return false;
67
+ });
68
+ };
69
+ e.replyCard = async (arr) => {
70
+ for (const item of arr) {
71
+ try {
72
+ if (item.type == 'qq_ark' || item.type == 'qq_embed') {
73
+ console.info('暂不可用');
74
+ return false;
75
+ }
76
+ else {
77
+ return false;
78
+ }
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ return true;
85
+ };
86
+ /**
87
+ * 发送表情表态
88
+ * @param mid
89
+ * @param boj { emoji_type: number; emoji_id: string }
90
+ * @returns
91
+ */
92
+ e.replyEmoji = async (mid, boj) => {
93
+ console.info('不可用');
94
+ return false;
95
+ };
96
+ /**
97
+ * 删除表情表态
98
+ * @param mid
99
+ * @param boj
100
+ * @returns
101
+ */
102
+ e.deleteEmoji = async (mid, boj) => {
103
+ console.info('不可用');
104
+ return false;
105
+ };
106
+ e.msg_txt = event.content;
107
+ e.msg = event.content;
108
+ /**
109
+ * 消息编号
110
+ */
111
+ e.msg_id = event.id;
112
+ e.user_id = event.author.id;
113
+ e.user_avatar = 'https://q1.qlogo.cn/g?b=qq&s=0&nk=1715713638';
114
+ e.user_name = '柠檬冲水';
115
+ e.channel_id = event.group_id;
116
+ e.guild_id = event.group_id;
117
+ e.segment = segmentQQ;
118
+ e.at_users = [];
119
+ e.at_user = {
120
+ id: '0',
121
+ avatar: '0',
122
+ name: '0',
123
+ bot: false
124
+ };
125
+ /**
126
+ * 艾特消息处理
127
+ */
128
+ e.at = false;
129
+ /**
130
+ * 消息处理
131
+ */
132
+ await InstructionMatching(e)
133
+ .then(() => {
134
+ console.info(console.info(`\n[${e.channel_id}] [${e.user_name}] [${true}] \n ${e.msg_txt}`));
135
+ return true;
136
+ })
137
+ .catch((err) => {
138
+ console.error(err);
139
+ console.info(console.info(`\n[${e.channel_id}] [${e.user_name}] [${false}] \n ${e.msg_txt}`));
140
+ return false;
141
+ });
142
+ };