alemonjs 1.0.2 → 1.0.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.
package/README.md CHANGED
@@ -13,33 +13,19 @@
13
13
  | cli | 脚手架 | 开发模板脚手架 |
14
14
  | web | 网站 | 共享平台插件贡献地址 |
15
15
 
16
- ## 快速开始
17
-
18
- ```shell
19
- npm init almeonjs@latest -y #安装
20
- ```
21
-
22
- ```shell
23
- cd alemon-bot #进入
24
- ```
25
-
26
- ```shell
27
- npm run app qq #启动
28
- ```
29
-
30
16
  ## 配置管理
31
17
 
32
- 打开 alemon.toml 文件
18
+ 参考配置说明进行
33
19
 
34
- 参考配置说明进行更改[config](./config.md)
20
+ 更改[alemon.toml](./alemon.md)
35
21
 
36
22
  ### 共享平台
37
23
 
38
24
  > 仓库只做资源收集,对齐安全性不做任何检查,请谨慎选择
39
25
 
40
- Gitee ☞[贡献资源](https://gitee.com/ningmengchongshui/alemon/tree/web/docs/root/examples/about/plugins.md)
26
+ [Gitee ☞ 贡献资源](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
41
27
 
42
- Github ☞[贡献资源](https://github.com/ningmengchongshui/alemon/tree/web/docs/root/examples/about/plugins.md)
28
+ [Github ☞ 贡献资源](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
43
29
 
44
30
  ### 平台推送
45
31
 
package/lib/bot.js CHANGED
@@ -1,54 +1,24 @@
1
1
  import { setLanchConfig } from './alemon/index.js';
2
- import { getBotConfigByKey, setBotConfig } from './login.js';
3
- import { getToml } from './config.js';
2
+ import { getBotConfigByKey, setBotConfig, getToml } from './config/index.js';
4
3
  import { loadInit } from './alemon/index.js';
5
4
  import { ClientAPIByQQ } from './ntqq/sdk/index.js';
6
5
  import { compilationTools } from 'alemon-rollup';
6
+ import { createAlemon } from './map.js';
7
+ // 设置独立鉴权路径
8
+ export const setAuthenticationByNtqq = ClientAPIByQQ.setAuthentication;
9
+ let appDir = 'application';
7
10
  /**
8
- * 启动机器人
11
+ * 应用模块集成
12
+ * @param AppName
13
+ * @param name
14
+ * @returns
9
15
  */
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
- };
16
+ export function ApplicationTools(AppName, name = 'apps') {
17
+ return compilationTools({
18
+ aInput: `${appDir}/${AppName}/${name}/**/*.ts`,
19
+ aOutput: `${appDir}/${AppName}/apps.js`
20
+ });
21
+ }
52
22
  /**
53
23
  * 创建机器人
54
24
  * @param val
@@ -57,9 +27,11 @@ const createAlemon = {
57
27
  export async function createBot(val = {
58
28
  args: process.argv.slice(2),
59
29
  mount: false,
60
- address: '/application'
30
+ address: 'application'
61
31
  }) {
62
32
  const { args, mount, cfg, address } = val;
33
+ // 配置快捷路径
34
+ appDir = address == undefined ? 'application' : address;
63
35
  /**
64
36
  * 加载配置
65
37
  */
@@ -88,11 +60,7 @@ export async function createBot(val = {
88
60
  */
89
61
  await loadInit({
90
62
  mount: mount == undefined ? false : mount,
91
- address: address == undefined ? '/application' : address
63
+ address: address == undefined ? '/application' : `/${address}`
92
64
  });
93
65
  return compilationTools;
94
66
  }
95
- // 机器人配置
96
- export { getBotConfigByKey, setBotConfigByKey } from './login.js';
97
- // 设置独立鉴权路径
98
- export const setAuthenticationByNtqq = ClientAPIByQQ.setAuthentication;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * ********
3
+ * 配置管理器
4
+ * ********
5
+ */
6
+ export * from './login.js';
7
+ export * from './toml.js';
8
+ export * from './types.js';
@@ -65,6 +65,9 @@ const config = {
65
65
  host: '127.0.0.1',
66
66
  port: 5000
67
67
  },
68
+ /**
69
+ * pup的配置的繁多的
70
+ */
68
71
  puppeteer: {
69
72
  headless: 'new',
70
73
  timeout: 30000,
@@ -85,11 +88,29 @@ const config = {
85
88
  */
86
89
  export function setBotConfig(val) {
87
90
  // 分布覆盖
88
- for (const item in val) {
91
+ for (const i in val) {
89
92
  // 当且仅当存在同key的时候才会覆盖默认配置
90
- for (const i in val[item]) {
91
- // 当前仅当同属性名的时候才会覆盖默认配置
92
- config[item][i] = val[item][i];
93
+ if (Object.prototype.hasOwnProperty.call(config, i)) {
94
+ if (i == 'puppeteer') {
95
+ // pup 不用检查 直接覆盖
96
+ for (const j in val[i]) {
97
+ config[i][j] = val[i][j];
98
+ }
99
+ }
100
+ else {
101
+ for (const j in val[i]) {
102
+ // 当前仅当同属性名的时候才会覆盖默认配置
103
+ if (Object.prototype.hasOwnProperty.call(config[i], j)) {
104
+ config[i][j] = val[i][j];
105
+ }
106
+ else {
107
+ console.log('[alemonjs][存在无效参数]', val[i]);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ else {
113
+ console.log('[alemonjs][存在无效参数]', val[i]);
93
114
  }
94
115
  }
95
116
  }
@@ -99,10 +120,22 @@ export function setBotConfig(val) {
99
120
  * @param val
100
121
  */
101
122
  export function setBotConfigByKey(key, val) {
102
- // 分布覆盖
103
- for (const item in val) {
104
- // 当前仅当同属性名的时候才会覆盖默认配置
105
- config[key][item] = val[item];
123
+ if (key == 'puppeteer') {
124
+ // pup 不用检查 直接覆盖
125
+ for (const item in val) {
126
+ config[key][item] = val[item];
127
+ }
128
+ }
129
+ else {
130
+ for (const item in val) {
131
+ // 当前仅当同属性名的时候才会覆盖默认配置
132
+ if (Object.prototype.hasOwnProperty.call(config[key], item)) {
133
+ config[key][item] = val[item];
134
+ }
135
+ else {
136
+ console.log('[alemonjs][存在无效参数]', val[item]);
137
+ }
138
+ }
106
139
  }
107
140
  }
108
141
  /**
@@ -2,7 +2,7 @@ import { InstructionMatching } from '../../../alemon/index.js';
2
2
  import { segmentDiscord } from '../segment.js';
3
3
  import { getBotMsgByDiscord } from '../bot.js';
4
4
  import { postImage } from '../api.js';
5
- import { getBotConfigByKey } from '../../../login.js';
5
+ import { getBotConfigByKey } from '../../../config/index.js';
6
6
  /**
7
7
  * 公共
8
8
  * @param event
@@ -2,7 +2,7 @@ import { Client } from 'discord.js';
2
2
  import { checkRobotByDiscord } from './login.js';
3
3
  import { callBackByDisdord } from './alemon/conversation.js';
4
4
  import { setBotMsgByDiscord } from './alemon/bot.js';
5
- import { getBotConfigByKey } from '../login.js';
5
+ import { getBotConfigByKey } from '../config/index.js';
6
6
  export async function createAlemonByDiscord() {
7
7
  /**
8
8
  * 登录
@@ -1,7 +1,6 @@
1
1
  import prompts from 'prompts';
2
2
  import { GatewayIntentBits } from 'discord.js';
3
- import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
4
- import { getToml, writeToml } from '../config.js';
3
+ import { setBotConfigByKey, getBotConfigByKey, getToml, writeToml } from '../config/index.js';
5
4
  /**
6
5
  * 登录配置
7
6
  * @param Bcf
package/lib/index.js CHANGED
@@ -8,6 +8,8 @@ export { compilationTools, integration } from 'alemon-rollup';
8
8
  export * from './alemon/index.js';
9
9
  // 导出机器人
10
10
  export * from './bot.js';
11
+ // 机器配置管理
12
+ export * from './config/index.js';
11
13
  // 监听退出
12
14
  process.on('SIGINT', signals => {
13
15
  console.info(signals);
@@ -2,7 +2,7 @@ import { InstructionMatching } from '../../../alemon/index.js';
2
2
  import { KOOKApiClient } from 'kook-ws';
3
3
  import { segmentKOOK } from '../segment.js';
4
4
  import { getBotMsgByKOOK } from '../bot.js';
5
- import { getBotConfigByKey } from '../../../login.js';
5
+ import { getBotConfigByKey } from '../../../config/index.js';
6
6
  /**
7
7
  *
8
8
  * @param event
package/lib/kook/index.js CHANGED
@@ -2,7 +2,7 @@ import { checkRobotByKOOK } from './login.js';
2
2
  import { callBackByKOOK } from './alemon/conversation.js';
3
3
  import { createClient, KOOKApiClient } from 'kook-ws';
4
4
  import { setBotMsgByKOOK } from './alemon/bot.js';
5
- import { getBotConfigByKey } from '../login.js';
5
+ import { getBotConfigByKey } from '../config/index.js';
6
6
  /**
7
7
  * 创建实例
8
8
  * @returns
package/lib/kook/login.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import prompts from 'prompts';
2
- import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
3
- import { getToml, writeToml } from '../config.js';
2
+ import { setBotConfigByKey, getBotConfigByKey, getToml, writeToml } from '../config/index.js';
4
3
  /**
5
4
  * 登录配置
6
5
  * @param Bcf
package/lib/map.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 启动机器人
3
+ */
4
+ export const createAlemon = {
5
+ qq: async () => {
6
+ const { createAlemonByQQ: qq } = await import('./qq/index.js');
7
+ return qq().catch(err => {
8
+ console.error(err);
9
+ console.error('QQ机器人启动失败~');
10
+ return false;
11
+ });
12
+ },
13
+ villa: async () => {
14
+ const { createAlemonByVilla: villa } = await import('./villa/index.js');
15
+ return villa().catch(err => {
16
+ console.error(err);
17
+ console.error('Villa机器人启动失败~');
18
+ return false;
19
+ });
20
+ },
21
+ kook: async () => {
22
+ const { createAlemonByKOOK: kook } = await import('./kook/index.js');
23
+ return kook().catch(err => {
24
+ console.error(err);
25
+ console.error('KOOK机器人启动失败~');
26
+ return false;
27
+ });
28
+ },
29
+ discord: async () => {
30
+ const { createAlemonByDiscord: dc } = await import('./discord/index.js');
31
+ return dc().catch(err => {
32
+ console.error(err);
33
+ console.error('Discord机器人启动失败~');
34
+ return false;
35
+ });
36
+ },
37
+ ntqq: async () => {
38
+ const { createAlemonByNtqq: ntqq } = await import('./ntqq/index.js');
39
+ return ntqq().catch(err => {
40
+ console.error(err);
41
+ console.error('Ntqq机器人启动失败~');
42
+ return false;
43
+ });
44
+ }
45
+ };
@@ -2,7 +2,7 @@ import { InstructionMatching } from '../../../alemon/index.js';
2
2
  import { ClientAPIByQQ as Client, ClinetWeb, getWebConfig } from '../../sdk/index.js';
3
3
  import { segmentQQ } from '../segment.js';
4
4
  import { getBotMsgByNtqq } from '../bot.js';
5
- import { getBotConfigByKey } from '../../../login.js';
5
+ import { getBotConfigByKey } from '../../../config/index.js';
6
6
  import IMGS from 'image-size';
7
7
  /**
8
8
  * 获取ip
package/lib/ntqq/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { checkRobotByQQ } from './login.js';
2
- import { getBotConfigByKey } from '../login.js';
2
+ import { getBotConfigByKey } from '../config/index.js';
3
3
  import { conversation } from './alemon/conversation.js';
4
4
  import { setBotConfig, createClient, ClientAPIByQQ, ClinetWeb, getWebConfig } from './sdk/index.js';
5
5
  import { createWeb } from './sdk/web/client.js';
package/lib/ntqq/login.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import prompts from 'prompts';
2
- import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
3
- import { getToml, writeToml } from '../config.js';
4
- import { NtQQEventsEnum } from '../types.js';
2
+ import { NtQQEventsEnum, setBotConfigByKey, getBotConfigByKey, getToml, writeToml } from '../config/index.js';
5
3
  /**
6
4
  * 登录配置
7
5
  * @param Bcf
@@ -11,7 +11,7 @@ import { MESSAGE_AUDIT } from './message/MESSAGE_AUDIT.js';
11
11
  import { AUDIO_ACTION } from './message/AUDIO_ACTION.js';
12
12
  import { FORUMS_EVENT } from './message/FORUMS_EVENT.js';
13
13
  import { setBotMsgByQQ } from './bot.js';
14
- import { getBotConfigByKey } from '../../login.js';
14
+ import { getBotConfigByKey } from '../../config/index.js';
15
15
  /**
16
16
  * 会话事件分类
17
17
  * @param ws
@@ -3,7 +3,7 @@ import { ClientAPIByQQ as Client } from 'qq-channel';
3
3
  import { Private } from '../privatechat.js';
4
4
  import { segmentQQ } from '../segment.js';
5
5
  import { setBotMsgByQQ } from '../bot.js';
6
- import { getBotConfigByKey } from '../../../login.js';
6
+ import { getBotConfigByKey } from '../../../config/index.js';
7
7
  /**
8
8
  * 公私域合并
9
9
  * @param e
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
  * 登录
package/lib/qq/login.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import prompts from 'prompts';
2
2
  import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
3
- import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
4
- import { getToml, writeToml } from '../config.js';
3
+ import { setBotConfigByKey, getBotConfigByKey, getToml, writeToml } from '../config/index.js';
5
4
  /**
6
5
  * 登录配置
7
6
  * @param Bcf
@@ -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,5 @@
1
1
  import prompts from 'prompts';
2
- import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
3
- import { getToml, writeToml } from '../config.js';
2
+ import { setBotConfigByKey, getBotConfigByKey, getToml, writeToml } from '../config/index.js';
4
3
  /**
5
4
  * 登录配置
6
5
  * @param Bcf
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "阿柠檬框架",
5
5
  "author": "ningmengchongshui",
6
6
  "main": "lib/index.js",
@@ -57,4 +57,4 @@
57
57
  "engines": {
58
58
  "node": ">=16.14.0"
59
59
  }
60
- }
60
+ }
package/types/bot.d.ts CHANGED
@@ -1,15 +1,20 @@
1
1
  import { ClientAPIByQQ } from './ntqq/sdk/index.js';
2
- interface botOpoint {
3
- args?: string[];
4
- mount?: boolean;
5
- address?: string;
6
- cfg?: string;
7
- }
2
+ export declare const setAuthenticationByNtqq: typeof ClientAPIByQQ.setAuthentication;
3
+ /**
4
+ * 应用模块集成
5
+ * @param AppName
6
+ * @param name
7
+ * @returns
8
+ */
9
+ export declare function ApplicationTools(AppName: string, name?: string): any;
8
10
  /**
9
11
  * 创建机器人
10
12
  * @param val
11
13
  * @returns
12
14
  */
13
- export declare function createBot(val?: botOpoint): Promise<any>;
14
- export { getBotConfigByKey, setBotConfigByKey } from './login.js';
15
- export declare const setAuthenticationByNtqq: typeof ClientAPIByQQ.setAuthentication;
15
+ export declare function createBot(val?: {
16
+ args?: string[];
17
+ mount?: boolean;
18
+ address?: string;
19
+ cfg?: string;
20
+ }): Promise<any>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * ********
3
+ * 配置管理器
4
+ * ********
5
+ */
6
+ export * from './login.js';
7
+ export * from './toml.js';
8
+ export * from './types.js';
@@ -1,20 +1,21 @@
1
1
  import { GatewayIntentBits } from 'discord.js';
2
2
  import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
3
+ import { PuppeteerLaunchOptions } from 'puppeteer';
3
4
  /**
4
- * ****
5
+ * ******
5
6
  * config
6
- * /////
7
+ * ******
7
8
  */
8
9
  export interface ConfigType {
9
- redis?: RedisConfig;
10
- mysql?: MysqlConfig;
11
- discord?: DiscordConfig;
12
- kook?: KookConfig;
13
- villa?: VillaConfig;
14
- qq?: QQConfig;
15
- server?: ServerConfig;
16
- puppeteer?: PuppeteerConfig;
17
- ntqq?: NtQQConfig;
10
+ redis: RedisConfig;
11
+ mysql: MysqlConfig;
12
+ discord: DiscordConfig;
13
+ kook: KookConfig;
14
+ villa: VillaConfig;
15
+ qq: QQConfig;
16
+ server: ServerConfig;
17
+ puppeteer: PuppeteerLaunchOptions;
18
+ ntqq: NtQQConfig;
18
19
  }
19
20
  /**
20
21
  * ****
@@ -123,13 +124,3 @@ export interface ServerConfig {
123
124
  host: string;
124
125
  port: number;
125
126
  }
126
- /**
127
- * ********
128
- * pup
129
- * *******
130
- */
131
- export interface PuppeteerConfig {
132
- args: string[];
133
- headless: 'new';
134
- timeout: number;
135
- }
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { compilationTools, integration } from 'alemon-rollup';
2
2
  export * from './alemon/index.js';
3
3
  export * from './bot.js';
4
+ export * from './config/index.js';
package/types/map.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 启动机器人
3
+ */
4
+ export declare const createAlemon: {
5
+ qq: () => Promise<boolean>;
6
+ villa: () => Promise<boolean>;
7
+ kook: () => Promise<boolean>;
8
+ discord: () => Promise<boolean>;
9
+ ntqq: () => Promise<boolean>;
10
+ };
File without changes
File without changes
File without changes
File without changes