alemonjs 1.0.52 → 1.0.53

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/core/ip.js CHANGED
@@ -4,11 +4,12 @@ let myIp;
4
4
  * 得到本机IP地址
5
5
  * @returns
6
6
  */
7
- export async function getIP() {
7
+ export async function getIP(options = {}) {
8
8
  if (myIp)
9
9
  return myIp;
10
10
  return await publicIp({
11
- timeout: 10000
11
+ onlyHttps: true,
12
+ ...options
12
13
  }).then(ip => {
13
14
  if (/^(\d{1,3}\.){3}\d{1,3}$/.test(ip))
14
15
  myIp = ip;
@@ -4,7 +4,7 @@ import { nodeScripts } from './child_process.js';
4
4
  import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
5
5
  import { ClientNTQQ } from '../ntqq/sdk/index.js';
6
6
  import { command } from './command.js';
7
- import { createApp, setLanchConfig, loadInit, appsInit, setAppProCoinfg, startChrom } from '../core/index.js';
7
+ import { createApp, setLanchConfig, loadInit, appsInit, setAppProCoinfg, startChrom, getIP } from '../core/index.js';
8
8
  import { getPupPath, setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
9
9
  import { createWeb } from '../koa/index.js';
10
10
  import { autoClearImages } from '../koa/img.js';
@@ -159,8 +159,12 @@ export async function defineAlemonConfig(Options) {
159
159
  if (Options?.server?.state != false) {
160
160
  // 创建server端
161
161
  createWeb(Options?.server);
162
- // 定时清除
163
- autoClearImages();
162
+ if (Options?.server?.clear != false) {
163
+ // 定时清除
164
+ autoClearImages();
165
+ }
166
+ // 缓存ip
167
+ getIP();
164
168
  }
165
169
  /**
166
170
  * ***********
package/lib/koa/img.js CHANGED
@@ -56,10 +56,13 @@ export async function setLocalImg(img) {
56
56
  const imgSize = getServerConfig('imgSize');
57
57
  const port = getServerConfig('port');
58
58
  const http = getServerConfig('http');
59
- let ip = await getIP();
60
- const ipp = getServerConfig('ip');
61
- if (ipp != 'localhost')
62
- ip = ipp;
59
+ let ip = getServerConfig('ip');
60
+ if (ip == 'localhost') {
61
+ const ipp = await getIP();
62
+ if (ipp)
63
+ ip = ipp;
64
+ }
65
+ console.log('测试1');
63
66
  // 生成文件名
64
67
  const filename = `${Math.floor(Math.random() * imgSize)}.${(await fileTypeFromBuffer(img))?.ext}`;
65
68
  // 文件路径
@@ -56,7 +56,7 @@ export const C2C_MESSAGE_CREATE = async (event) => {
56
56
  const url = await ClientKOA.setLocalImg(msg[isBuffer]);
57
57
  if (!url)
58
58
  return false;
59
- return await ClientNTQQ.postMessageByUser(event.author.user_openid, `${cont} ![text #${dimensions.width}px #${dimensions.height}px](${url})`, select?.quote).catch(everyoneError);
59
+ return await ClientNTQQ.postMessageByUser(event.author.user_openid, `${cont} ![text #${dimensions.width}px #${dimensions.height}px](${url})`, event.id).catch(everyoneError);
60
60
  }
61
61
  catch (err) {
62
62
  console.error(err);
@@ -86,7 +86,7 @@ export const C2C_MESSAGE_CREATE = async (event) => {
86
86
  return await ClientNTQQ.postFilesByUsers(event.author.user_openid, url).catch(everyoneError);
87
87
  }
88
88
  }
89
- return await ClientNTQQ.postMessageByUser(event.author.user_openid, content, select?.quote).catch(everyoneError);
89
+ return await ClientNTQQ.postMessageByUser(event.author.user_openid, content, event.id).catch(everyoneError);
90
90
  };
91
91
  e.replyCard = async (arr) => {
92
92
  for (const item of arr) {
@@ -62,7 +62,7 @@ export const GROUP_AT_MESSAGE_CREATE = async (event) => {
62
62
  const url = await ClientKOA.setLocalImg(msg[isBuffer]);
63
63
  if (!url)
64
64
  return false;
65
- return await ClientNTQQ.postMessageByGroup(event.group_id, `${cont} ![text #${dimensions.width}px #${dimensions.height}px](${url})`, select?.quote).catch(everyoneError);
65
+ return await ClientNTQQ.postMessageByGroup(event.group_id, `${cont} ![text #${dimensions.width}px #${dimensions.height}px](${url})`, event.id).catch(everyoneError);
66
66
  }
67
67
  catch (err) {
68
68
  console.error(err);
@@ -92,7 +92,7 @@ export const GROUP_AT_MESSAGE_CREATE = async (event) => {
92
92
  return await ClientNTQQ.postFilesByGroup(event.group_id, url).catch(everyoneError);
93
93
  }
94
94
  }
95
- return await ClientNTQQ.postMessageByGroup(event.group_id, content, select?.quote).catch(everyoneError);
95
+ return await ClientNTQQ.postMessageByGroup(event.group_id, content, event.id).catch(everyoneError);
96
96
  };
97
97
  e.replyCard = async (arr) => {
98
98
  for (const item of arr) {
@@ -109,10 +109,12 @@ export function createClient({ bot_id, bot_secret, callback_url = '/api/mys/call
109
109
  await logFnc(port);
110
110
  }
111
111
  // 获取ip4
112
- let ip = await getIP();
113
- const ipp = getServerConfig('ip');
114
- if (ipp != 'localhost')
115
- ip = ipp;
112
+ let ip = getServerConfig('ip');
113
+ if (ip == 'localhost') {
114
+ const ipp = await getIP();
115
+ if (ipp)
116
+ ip = ipp;
117
+ }
116
118
  console.info('villa open', `http://${ip}:${port}${callback_url}`);
117
119
  if (!ip)
118
120
  console.error('vllia no public ip');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "1.0.52",
3
+ "version": "1.0.53",
4
4
  "description": "DOCS https://alemonjs.com/",
5
5
  "author": "ningmengchongshui",
6
6
  "license": "GPL-2.0",
@@ -1,5 +1,6 @@
1
+ import { Options } from 'public-ip';
1
2
  /**
2
3
  * 得到本机IP地址
3
4
  * @returns
4
5
  */
5
- export declare function getIP(): Promise<string | false>;
6
+ export declare function getIP(options?: Options): Promise<string | false>;
@@ -30,4 +30,9 @@ export interface ServerOptions {
30
30
  * 当前服务状态
31
31
  */
32
32
  state?: boolean;
33
+ /**
34
+ * 定时清除是否开启
35
+ * 默认关闭
36
+ */
37
+ clear?: boolean;
33
38
  }