alemonjs 1.0.2 → 1.0.4

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 (75) hide show
  1. package/README.md +6 -22
  2. package/bin/main.js +17 -0
  3. package/lib/alemon/dealmsg.js +66 -18
  4. package/lib/alemon/puppeteer.js +9 -16
  5. package/lib/config/index.js +8 -0
  6. package/lib/config/login.js +87 -0
  7. package/lib/config/pup.js +75 -0
  8. package/lib/config/types.js +1 -0
  9. package/lib/default/login/discord.js +16 -0
  10. package/lib/default/login/kook.js +5 -0
  11. package/lib/default/login/ntqq.js +17 -0
  12. package/lib/default/login/qq.js +16 -0
  13. package/lib/default/login/villa.js +13 -0
  14. package/lib/default/mysql.js +7 -0
  15. package/lib/default/pup.js +15 -0
  16. package/lib/default/redis.js +6 -0
  17. package/lib/default/server.js +4 -0
  18. package/lib/{types.js → default/types.js} +8 -2
  19. package/lib/define/api.js +23 -0
  20. package/lib/define/child_process.js +10 -0
  21. package/lib/define/command.js +22 -0
  22. package/lib/define/index.js +7 -0
  23. package/lib/define/main.js +205 -0
  24. package/lib/define/map.js +47 -0
  25. package/lib/define/plugin.js +25 -0
  26. package/lib/define/types.js +1 -0
  27. package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +1 -1
  28. package/lib/discord/index.js +1 -1
  29. package/lib/discord/login.js +18 -63
  30. package/lib/index.js +23 -7
  31. package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +1 -1
  32. package/lib/kook/index.js +1 -1
  33. package/lib/kook/login.js +7 -40
  34. package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +1 -1
  35. package/lib/ntqq/index.js +2 -2
  36. package/lib/ntqq/login.js +15 -64
  37. package/lib/ntqq/sdk/wss.js +0 -1
  38. package/lib/qq/alemon/conversation.js +1 -1
  39. package/lib/qq/alemon/message/MESSAGE.js +1 -1
  40. package/lib/qq/index.js +14 -3
  41. package/lib/qq/login.js +3 -125
  42. package/lib/villa/alemon/message/MESSAGES.js +1 -1
  43. package/lib/villa/index.js +1 -1
  44. package/lib/villa/login.js +11 -52
  45. package/package.json +62 -60
  46. package/types/alemon/dealmsg.d.ts +10 -0
  47. package/types/config/index.d.ts +8 -0
  48. package/types/config/pup.d.ts +7 -0
  49. package/types/config/types.d.ts +18 -0
  50. package/types/default/login/discord.d.ts +8 -0
  51. package/types/default/login/kook.d.ts +6 -0
  52. package/types/default/login/ntqq.d.ts +16 -0
  53. package/types/default/login/qq.d.ts +12 -0
  54. package/types/default/login/villa.d.ts +14 -0
  55. package/types/default/mysql.d.ts +8 -0
  56. package/types/default/pup.d.ts +3 -0
  57. package/types/default/redis.d.ts +7 -0
  58. package/types/default/server.d.ts +5 -0
  59. package/types/default/types.d.ts +300 -0
  60. package/types/define/api.d.ts +30 -0
  61. package/types/define/child_process.d.ts +1 -0
  62. package/types/define/command.d.ts +1 -0
  63. package/types/define/index.d.ts +7 -0
  64. package/types/define/main.d.ts +20 -0
  65. package/types/define/map.d.ts +12 -0
  66. package/types/define/plugin.d.ts +4 -0
  67. package/types/define/types.d.ts +111 -0
  68. package/types/index.d.ts +17 -2
  69. package/lib/bot.js +0 -98
  70. package/lib/config.js +0 -25
  71. package/lib/login.js +0 -115
  72. package/types/bot.d.ts +0 -15
  73. package/types/config.d.ts +0 -12
  74. package/types/types.d.ts +0 -135
  75. /package/types/{login.d.ts → config/login.d.ts} +0 -0
package/lib/qq/index.js CHANGED
@@ -3,7 +3,7 @@ import { createOpenAPI, createWebsocket } from 'qq-guild-bot';
3
3
  import { setBotConfig } from 'qq-channel';
4
4
  import { checkRobotByQQ } from './login.js';
5
5
  import { createConversationByQQ } from './alemon/conversation.js';
6
- import { getBotConfigByKey } from '../login.js';
6
+ import { getBotConfigByKey } from '../config/index.js';
7
7
  export async function createAlemonByQQ() {
8
8
  /**
9
9
  * 登录
@@ -19,7 +19,11 @@ export async function createAlemonByQQ() {
19
19
  /**
20
20
  * 创建 clientApiByQQ
21
21
  */
22
- global.clientApiByQQ = createOpenAPI(cfg);
22
+ global.clientApiByQQ = createOpenAPI({
23
+ appID: cfg.appID,
24
+ token: cfg.token,
25
+ sandbox: cfg.sandbox ?? false
26
+ });
23
27
  /**
24
28
  * 设置 qq-channal 配置
25
29
  */
@@ -33,7 +37,14 @@ export async function createAlemonByQQ() {
33
37
  /**
34
38
  * 创建 websocket
35
39
  */
36
- const WebsocketClient = createWebsocket(cfg);
40
+ const WebsocketClient = createWebsocket({
41
+ appID: cfg.appID,
42
+ token: cfg.token,
43
+ sandbox: cfg.sandbox,
44
+ // shards?:[],
45
+ intents: cfg.intents
46
+ // maxRetry:
47
+ });
37
48
  /**
38
49
  * 创建 conversation
39
50
  */
package/lib/qq/login.js CHANGED
@@ -1,7 +1,5 @@
1
- import prompts from 'prompts';
2
1
  import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
3
- import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
4
- import { getToml, writeToml } from '../config.js';
2
+ import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
5
3
  /**
6
4
  * 登录配置
7
5
  * @param Bcf
@@ -26,126 +24,6 @@ export async function checkRobotByQQ() {
26
24
  }
27
25
  }
28
26
  console.info('[LOGIN]', '-----------------------');
29
- console.info('[LOGIN]', '推荐将机器人设置', '订阅推送', '打开');
30
- console.info('[LOGIN]', '推荐将机器人设置', '私聊权限', '打开');
31
- console.info('[LOGIN]', '非管理类机器推荐', '普通成员', '身份');
32
- console.info('[LOGIN]', '-----------------------');
33
- console.info('[LOGIN]', '退出重来?可按', '[CTRL+C]');
34
- console.info('[LOGIN]', '更改登录?执行', 'npm run login');
35
- console.info('[LOGIN]', '-----------------------');
36
- const timeoutId = setTimeout(() => {
37
- throw '超过1分钟未完成登录';
38
- }, 60000);
39
- const { appID, token, inputBot, imputDev } = await prompts([
40
- {
41
- type: 'password',
42
- name: 'appID',
43
- message: 'BotAppID: ',
44
- validate: value => value !== '' && typeof value === 'string' ? true : '机器人 appID: '
45
- },
46
- {
47
- type: 'password',
48
- name: 'token',
49
- message: 'BotToken: ',
50
- validate: value => value !== '' && typeof value === 'string' ? true : '机器人 token: '
51
- },
52
- {
53
- type: 'select',
54
- name: 'inputBot',
55
- message: '请选择机器人类型 :',
56
- choices: [
57
- { title: '公域', value: '0' },
58
- { title: '私域', value: '1' }
59
- ],
60
- /**
61
- * 默认公域
62
- */
63
- initial: 0
64
- },
65
- {
66
- type: 'select',
67
- name: 'imputDev',
68
- message: '请选择机器人环境 :',
69
- choices: [
70
- { title: '部署环境', value: '0' },
71
- { title: '开发环境', value: '1' }
72
- ],
73
- /**
74
- * 默认部署
75
- */
76
- initial: 0
77
- }
78
- ]).catch((err) => {
79
- console.error(err);
80
- process.exit();
81
- });
82
- if (!appID || !token || !inputBot || !imputDev) {
83
- return false;
84
- }
85
- clearTimeout(timeoutId);
86
- /**
87
- * 默认公域机器人
88
- */
89
- let intents = [
90
- AvailableIntentsEventsEnum.GUILDS,
91
- AvailableIntentsEventsEnum.GUILD_MEMBERS,
92
- AvailableIntentsEventsEnum.DIRECT_MESSAGE,
93
- /**
94
- * 公域特有
95
- */
96
- AvailableIntentsEventsEnum.PUBLIC_GUILD_MESSAGES //公域事件
97
- ];
98
- /**
99
- * 默认公域机器人
100
- */
101
- let isPrivate = false;
102
- if (inputBot == '1') {
103
- /**
104
- * 私域机器人
105
- */
106
- intents = [
107
- AvailableIntentsEventsEnum.GUILDS,
108
- AvailableIntentsEventsEnum.GUILD_MEMBERS,
109
- AvailableIntentsEventsEnum.DIRECT_MESSAGE,
110
- /**
111
- * 需申请的
112
- */
113
- AvailableIntentsEventsEnum.AUDIO_ACTION,
114
- AvailableIntentsEventsEnum.MESSAGE_AUDIT,
115
- AvailableIntentsEventsEnum.INTERACTION,
116
- AvailableIntentsEventsEnum.GUILD_MESSAGE_REACTIONS,
117
- /**
118
- * 私域特有
119
- */
120
- AvailableIntentsEventsEnum.GUILD_MESSAGES,
121
- AvailableIntentsEventsEnum.FORUMS_EVENT //私域论坛
122
- ];
123
- /**
124
- * 私域机器人
125
- */
126
- isPrivate = true;
127
- }
128
- // 默认部署
129
- let sandbox = false;
130
- // 开发环境
131
- if (imputDev == '1')
132
- sandbox = true;
133
- // 得到已变更的配置
134
- const db = getBotConfigByKey('qq');
135
- // 得到配置
136
- const data = getToml();
137
- data.qq = {
138
- ...db,
139
- // 覆盖新配置
140
- appID,
141
- token,
142
- intents,
143
- isPrivate,
144
- sandbox
145
- };
146
- // 写入配置
147
- writeToml(data);
148
- // 设置配置
149
- setBotConfigByKey('qq', data.qq);
150
- return true;
27
+ console.info('[LOGIN]', 'qq配置加载失败~');
28
+ process.exit();
151
29
  }
@@ -2,7 +2,7 @@ import { InstructionMatching } from '../../../alemon/index.js';
2
2
  import { Client } from 'mys-villa';
3
3
  import IMGS from 'image-size';
4
4
  import { segmentVilla } from '../segment.js';
5
- import { getBotConfigByKey } from '../../../login.js';
5
+ import { getBotConfigByKey } from '../../../config/index.js';
6
6
  import { now_e } from './e.js';
7
7
  /**
8
8
  * 获取ip
@@ -1,7 +1,7 @@
1
1
  import { callBackByVilla } from './alemon/conversation.js';
2
2
  import { checkRobotByVilla } from './login.js';
3
3
  import { createClient, Client, hmacSha256 } from 'mys-villa';
4
- import { getBotConfigByKey } from '../login.js';
4
+ import { getBotConfigByKey } from '../config/index.js';
5
5
  export async function createAlemonByVilla() {
6
6
  /**
7
7
  * 登录
@@ -1,6 +1,4 @@
1
- import prompts from 'prompts';
2
- import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
3
- import { getToml, writeToml } from '../config.js';
1
+ import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
4
2
  /**
5
3
  * 登录配置
6
4
  * @param Bcf
@@ -8,55 +6,16 @@ import { getToml, writeToml } from '../config.js';
8
6
  * @returns
9
7
  */
10
8
  export async function checkRobotByVilla() {
11
- // 重写登录
12
- if (process.argv.indexOf('login') == -1) {
13
- // 启动
14
- const config = getBotConfigByKey('villa');
15
- // 存在
16
- if ((config ?? '') !== '' &&
17
- (config.bot_id ?? '') !== '' &&
18
- (config.secret ?? '') !== '') {
19
- setBotConfigByKey('villa', config);
20
- return true;
21
- }
9
+ // 启动
10
+ const config = getBotConfigByKey('villa');
11
+ // 存在
12
+ if ((config ?? '') !== '' &&
13
+ (config.bot_id ?? '') !== '' &&
14
+ (config.secret ?? '') !== '') {
15
+ setBotConfigByKey('villa', config);
16
+ return true;
22
17
  }
23
18
  console.info('[LOGIN]', '-----------------------');
24
- const timeoutId = setTimeout(() => {
25
- throw '超过1分钟未完成登录';
26
- }, 60000);
27
- const { bot_id, secret } = await prompts([
28
- {
29
- type: 'password',
30
- name: 'bot_id',
31
- message: 'bot_id: ',
32
- validate: (value) => value !== '' && typeof value === 'string' ? true : 'bot_id: '
33
- },
34
- {
35
- type: 'password',
36
- name: 'secret',
37
- message: 'secret: ',
38
- validate: (value) => value !== '' && typeof value === 'string' ? true : 'secret: '
39
- }
40
- ]).catch((err) => {
41
- console.error(err);
42
- process.exit();
43
- });
44
- if (!bot_id || !secret)
45
- return false;
46
- clearTimeout(timeoutId);
47
- // 得到已变更的配置
48
- const db = getBotConfigByKey('villa');
49
- // 得到配置
50
- const data = getToml();
51
- data.villa = {
52
- ...db,
53
- // 覆盖新配置
54
- bot_id,
55
- secret
56
- };
57
- // 写入配置
58
- writeToml(data);
59
- // 设置配置
60
- setBotConfigByKey('villa', data.villa);
61
- return true;
19
+ console.info('[LOGIN]', 'villa配置加载失败~');
20
+ process.exit();
62
21
  }
package/package.json CHANGED
@@ -1,60 +1,62 @@
1
- {
2
- "name": "alemonjs",
3
- "version": "1.0.2",
4
- "description": "阿柠檬框架",
5
- "author": "ningmengchongshui",
6
- "main": "lib/index.js",
7
- "license": "GPL-2.0",
8
- "type": "module",
9
- "scripts": {
10
- "app": "ts-node index.ts",
11
- "login": "ts-node index.ts login",
12
- "tsc": "npx tsc",
13
- "format": "prettier --write .",
14
- "lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
15
- },
16
- "dependencies": {
17
- "@discordjs/builders": "^1.6.3",
18
- "@discordjs/core": "^0.6.0",
19
- "@discordjs/rest": "^1.7.1",
20
- "@iarna/toml": "^2.2.5",
21
- "alemon-rollup": "^1.0.2",
22
- "axios": "^1.4.0",
23
- "discord.js": "^14.11.0",
24
- "image-size": "^1.0.2",
25
- "kook-ws": "^1.0.4",
26
- "lodash": "^4.17.21",
27
- "mys-villa": "^1.1.8",
28
- "prompts": "^2.4.2",
29
- "puppeteer": "^20.7.1",
30
- "qq-channel": "^1.0.0",
31
- "qq-guild-bot": "^2.9.5",
32
- "qrcode": "^1.5.3"
33
- },
34
- "devDependencies": {
35
- "@types/lodash": "^4.14.186",
36
- "@types/node": "^20.2.4",
37
- "@types/progress": "^2.0.5",
38
- "@types/qrcode": "^1.5.0",
39
- "@types/ws": "^8.5.5",
40
- "@typescript-eslint/eslint-plugin": "^5.60.0",
41
- "@typescript-eslint/parser": "^5.60.0",
42
- "eslint": "^8.43.0",
43
- "eslint-config-prettier": "^8.8.0",
44
- "eslint-plugin-prettier": "^4.2.1",
45
- "prettier": "^2.8.8",
46
- "ts-node": "^10.9.1",
47
- "typescript": ">=5.0.4 <5.1.0"
48
- },
49
- "types": "types",
50
- "files": [
51
- "lib",
52
- "types"
53
- ],
54
- "publishConfig": {
55
- "registry": "https://registry.npmjs.org"
56
- },
57
- "engines": {
58
- "node": ">=16.14.0"
59
- }
60
- }
1
+ {
2
+ "name": "alemonjs",
3
+ "version": "1.0.4",
4
+ "description": "阿柠檬框架",
5
+ "author": "ningmengchongshui",
6
+ "main": "lib/index.js",
7
+ "license": "GPL-2.0",
8
+ "type": "module",
9
+ "scripts": {
10
+ "app": "alemonjs",
11
+ "dev": "alemonjs dev",
12
+ "tsc": "npx tsc",
13
+ "format": "prettier --write .",
14
+ "lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
15
+ },
16
+ "dependencies": {
17
+ "@discordjs/builders": "^1.6.3",
18
+ "@discordjs/core": "^0.6.0",
19
+ "@discordjs/rest": "^1.7.1",
20
+ "alemon-rollup": "^1.0.2",
21
+ "axios": "^1.4.0",
22
+ "discord.js": "^14.11.0",
23
+ "image-size": "^1.0.2",
24
+ "kook-ws": "^1.0.4",
25
+ "lodash": "^4.17.21",
26
+ "mys-villa": "^1.1.8",
27
+ "puppeteer": "^20.7.1",
28
+ "qq-channel": "^1.0.0",
29
+ "qq-guild-bot": "^2.9.5",
30
+ "qrcode": "^1.5.3"
31
+ },
32
+ "devDependencies": {
33
+ "@types/lodash": "^4.14.186",
34
+ "@types/node": "^20.2.4",
35
+ "@types/progress": "^2.0.5",
36
+ "@types/qrcode": "^1.5.0",
37
+ "@types/ws": "^8.5.5",
38
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
39
+ "@typescript-eslint/parser": "^5.60.0",
40
+ "eslint": "^8.43.0",
41
+ "eslint-config-prettier": "^8.8.0",
42
+ "eslint-plugin-prettier": "^4.2.1",
43
+ "prettier": "^2.8.8",
44
+ "ts-node": "^10.9.1",
45
+ "typescript": ">=5.0.4 <5.1.0"
46
+ },
47
+ "types": "types",
48
+ "files": [
49
+ "bin",
50
+ "lib",
51
+ "types"
52
+ ],
53
+ "bin": {
54
+ "alemonjs": "bin/main.js"
55
+ },
56
+ "publishConfig": {
57
+ "registry": "https://registry.npmjs.org"
58
+ },
59
+ "engines": {
60
+ "node": ">=16.14.0"
61
+ }
62
+ }
@@ -1,4 +1,13 @@
1
1
  import { AMessage } from './typings.js';
2
+ interface RegexControl {
3
+ RegexOpen?: RegExp;
4
+ RegexClose?: RegExp;
5
+ }
6
+ /**
7
+ * 插件名匹配
8
+ * @param val
9
+ */
10
+ export declare function setAppRegex(val: RegexControl): void;
2
11
  /**
3
12
  * 设置指令json地址
4
13
  * @param rt '/public/defset'
@@ -39,3 +48,4 @@ export declare function InstructionMatching(e: AMessage): Promise<boolean>;
39
48
  * @returns
40
49
  */
41
50
  export declare function typeMessage(e: AMessage): Promise<boolean>;
51
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * ********
3
+ * 配置管理器
4
+ * ********
5
+ */
6
+ export * from './login.js';
7
+ export * from './types.js';
8
+ export * from './pup.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @type {import("puppeteer").Configuration}
3
+ */
4
+ export declare function getPupPath(): {
5
+ skipDownload: boolean;
6
+ executablePath: string;
7
+ };
@@ -0,0 +1,18 @@
1
+ import { PuppeteerLaunchOptions } from 'puppeteer';
2
+ import { DiscordOptions, KookOptionsg, MysqlOptions, NtQQOptions, QqGuildOptions, RedisOptions, VillaOptions, ServerOptions } from '../default/types.js';
3
+ /**
4
+ * ******
5
+ * config
6
+ * ******
7
+ */
8
+ export interface ConfigType {
9
+ redis: RedisOptions;
10
+ mysql: MysqlOptions;
11
+ discord: DiscordOptions;
12
+ kook: KookOptionsg;
13
+ villa: VillaOptions;
14
+ qq: QqGuildOptions;
15
+ server: ServerOptions;
16
+ puppeteer: PuppeteerLaunchOptions;
17
+ ntqq: NtQQOptions;
18
+ }
@@ -0,0 +1,8 @@
1
+ import { GatewayIntentBits } from 'discord.js';
2
+ declare const _default: {
3
+ token: string;
4
+ masterID: string;
5
+ password: string;
6
+ intents: GatewayIntentBits[];
7
+ };
8
+ export default _default;
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ token: string;
3
+ masterID: string;
4
+ password: string;
5
+ };
6
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { NtQQEventsEnum } from '../types.js';
2
+ declare const _default: {
3
+ appID: string;
4
+ token: string;
5
+ secret: string;
6
+ masterID: string;
7
+ password: string;
8
+ intents: NtQQEventsEnum[];
9
+ shard: number[];
10
+ port: number;
11
+ size: number;
12
+ img_url: string;
13
+ IMAGE_DIR: string;
14
+ http: string;
15
+ };
16
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
2
+ declare const _default: {
3
+ appID: string;
4
+ token: string;
5
+ secret: string;
6
+ masterID: string;
7
+ password: string;
8
+ intents: AvailableIntentsEventsEnum[];
9
+ isPrivate: boolean;
10
+ sandbox: boolean;
11
+ };
12
+ export default _default;
@@ -0,0 +1,14 @@
1
+ declare const _default: {
2
+ bot_id: string;
3
+ secret: string;
4
+ pub_key: string;
5
+ masterID: string;
6
+ password: string;
7
+ http: string;
8
+ url: string;
9
+ port: number;
10
+ size: number;
11
+ img_url: string;
12
+ IMAGE_DIR: string;
13
+ };
14
+ export default _default;
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ host: string;
3
+ port: number;
4
+ user: string;
5
+ password: string;
6
+ database: string;
7
+ };
8
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { PuppeteerLaunchOptions } from 'puppeteer';
2
+ declare const _default: PuppeteerLaunchOptions;
3
+ export default _default;
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ host: string;
3
+ port: number;
4
+ password: string;
5
+ db: number;
6
+ };
7
+ export default _default;
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ host: string;
3
+ port: number;
4
+ };
5
+ export default _default;