alemonjs 1.0.42 → 1.0.43

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.
@@ -11,7 +11,8 @@ const ApplicationProcessingConfiguration = {
11
11
  closeRegex: undefined,
12
12
  event: [],
13
13
  route: '/public/defset',
14
- regex: true
14
+ regex: true,
15
+ character: /^(#\/)/
15
16
  };
16
17
  /**
17
18
  * 设置插件解析配置
@@ -102,6 +102,7 @@ async function synthesis(AppsObj, appname) {
102
102
  }
103
103
  CommandApp[itemX] = {
104
104
  name: appname,
105
+ character: keys['character'] ?? '/',
105
106
  APP: AppsObj[item]
106
107
  };
107
108
  for await (const key of keys['rule']) {
@@ -283,6 +284,22 @@ export function getMergedRegex() {
283
284
  export async function loadInit() {
284
285
  await loadPlugins(join(process.cwd(), getAppProCoinfg('dir')));
285
286
  }
287
+ /**
288
+ * 起始符转换器
289
+ * @param reg
290
+ * @returns
291
+ */
292
+ function getStartSymbol(reg) {
293
+ const source = reg.source;
294
+ let startSymbol = '';
295
+ if (source.startsWith('#')) {
296
+ startSymbol = '#';
297
+ }
298
+ else if (source.startsWith('/')) {
299
+ startSymbol = '/';
300
+ }
301
+ return startSymbol;
302
+ }
286
303
  /**
287
304
  * 指令匹配
288
305
  * @param e alemonjs message
@@ -304,9 +321,13 @@ export async function InstructionMatching(e) {
304
321
  * 上下文
305
322
  */
306
323
  for (const item in CommandApp) {
307
- const { name, APP } = CommandApp[item];
324
+ const { name, APP, character } = CommandApp[item];
308
325
  const AppFnc = getMessage(name);
309
326
  const AppArg = getAppArg(name);
327
+ const _character = getAppProCoinfg('character');
328
+ if (_character.test(e.msg)) {
329
+ e.msg = e.msg.replace(_character, character);
330
+ }
310
331
  try {
311
332
  if (typeof AppFnc == 'function')
312
333
  e = await AppFnc(e);
package/lib/core/ip.js CHANGED
@@ -8,7 +8,6 @@ export async function getIP() {
8
8
  if (myIp)
9
9
  return myIp;
10
10
  return await publicIp({
11
- onlyHttps: true,
12
11
  timeout: 10000
13
12
  }).then(ip => {
14
13
  if (/^(\d{1,3}\.){3}\d{1,3}$/.test(ip)) {
@@ -35,6 +35,10 @@ export class plugin {
35
35
  * 匹配集
36
36
  */
37
37
  rule;
38
+ /**
39
+ * 起始符特性
40
+ */
41
+ character;
38
42
  /**
39
43
  * @deprecated 已废弃,建议使用原生模块 node-schedule
40
44
  */
@@ -50,12 +54,13 @@ export class plugin {
50
54
  * @param rule.doc 指令文档 doc
51
55
  * @param rule.priority 优先级 数字越小优先级越高
52
56
  */
53
- constructor({ name = 'app-name', event = 'MESSAGES', eventType = 'CREATE', priority = 9000, rule = [], task }) {
57
+ constructor({ name = 'app-name', event = 'MESSAGES', eventType = 'CREATE', priority = 9000, character = '/', rule = [], task }) {
54
58
  this.name = name;
55
59
  this.event = event;
56
60
  this.eventType = eventType;
57
61
  this.priority = priority;
58
62
  this.rule = rule;
63
+ this.character = character;
59
64
  this.task = {
60
65
  name: task?.name ?? '',
61
66
  fnc: task?.fnc ?? '',
@@ -203,6 +203,14 @@ export async function defineAlemonConfig(Options) {
203
203
  if (Options?.plugin?.RegexClose) {
204
204
  setAppProCoinfg('closeRegex', Options?.plugin?.RegexClose);
205
205
  }
206
+ /**
207
+ * **************
208
+ * 设置起始符规则
209
+ * *************
210
+ */
211
+ if (Options?.character) {
212
+ setAppProCoinfg('character', Options?.character);
213
+ }
206
214
  /**
207
215
  * ************
208
216
  * 扫描插件
package/lib/koa/config.js CHANGED
@@ -10,6 +10,10 @@ const ServerCfg = {
10
10
  * 端口
11
11
  */
12
12
  port: 6060,
13
+ /**
14
+ * 地址
15
+ */
16
+ ip: 'localhost',
13
17
  /**
14
18
  * 图片随机度
15
19
  */
package/lib/koa/img.js CHANGED
@@ -56,7 +56,11 @@ export async function setLocalImg(img) {
56
56
  const imgSize = getServerConfig('imgSize');
57
57
  const port = getServerConfig('port');
58
58
  const http = getServerConfig('http');
59
- const ip = await getIP();
59
+ let ip = await getIP();
60
+ const ipp = getServerConfig('ip');
61
+ if (ipp != 'localhost') {
62
+ ip = ipp;
63
+ }
60
64
  // 生成文件名
61
65
  const filename = `${Math.floor(Math.random() * imgSize)}.${(await fileTypeFromBuffer(img))?.ext}`;
62
66
  // 文件路径
@@ -128,6 +128,11 @@ export const PUBLIC_GUILD_MESSAGES_KOOK = async (event) => {
128
128
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
129
129
  // 删除所有buffer
130
130
  const content = msg
131
+ .map(item => {
132
+ if (typeof item === 'number')
133
+ return String(item);
134
+ return item;
135
+ })
131
136
  .filter(element => typeof element === 'string')
132
137
  .join('');
133
138
  // 转存
@@ -165,7 +170,9 @@ export const PUBLIC_GUILD_MESSAGES_KOOK = async (event) => {
165
170
  ? msg.join('')
166
171
  : typeof msg === 'string'
167
172
  ? msg
168
- : '';
173
+ : typeof msg === 'number'
174
+ ? `${msg}`
175
+ : '';
169
176
  if (content == '')
170
177
  return false;
171
178
  const match = content.match(/<http>(.*?)<\/http>/);
@@ -48,7 +48,14 @@ export const C2C_MESSAGE_CREATE = async (event) => {
48
48
  */
49
49
  if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
50
50
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
51
- const cont = msg.filter(element => typeof element === 'string').join('');
51
+ const cont = msg
52
+ .map(item => {
53
+ if (typeof item === 'number')
54
+ return String(item);
55
+ return item;
56
+ })
57
+ .filter(element => typeof element === 'string')
58
+ .join('');
52
59
  try {
53
60
  const dimensions = IMGS.imageSize(msg[isBuffer]);
54
61
  const url = await ClientKOA.setLocalImg(msg[isBuffer]);
@@ -65,7 +72,9 @@ export const C2C_MESSAGE_CREATE = async (event) => {
65
72
  ? msg.join('')
66
73
  : typeof msg === 'string'
67
74
  ? msg
68
- : '';
75
+ : typeof msg === 'number'
76
+ ? `${msg}`
77
+ : '';
69
78
  if (content == '')
70
79
  return false;
71
80
  /**
@@ -76,7 +76,14 @@ export const GROUP_AT_MESSAGE_CREATE = async (event) => {
76
76
  }
77
77
  if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
78
78
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
79
- const cont = msg.filter(element => typeof element === 'string').join('');
79
+ const cont = msg
80
+ .map(item => {
81
+ if (typeof item === 'number')
82
+ return String(item);
83
+ return item;
84
+ })
85
+ .filter(element => typeof element === 'string')
86
+ .join('');
80
87
  try {
81
88
  const dimensions = IMGS.imageSize(msg[isBuffer]);
82
89
  const url = await ClientKOA.setLocalImg(msg[isBuffer]);
@@ -93,7 +100,9 @@ export const GROUP_AT_MESSAGE_CREATE = async (event) => {
93
100
  ? msg.join('')
94
101
  : typeof msg === 'string'
95
102
  ? msg
96
- : '';
103
+ : typeof msg === 'number'
104
+ ? `${msg}`
105
+ : '';
97
106
  if (content == '')
98
107
  return false;
99
108
  /**
@@ -74,7 +74,14 @@ async function directMessage(e, event) {
74
74
  // arr && find buffer
75
75
  if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
76
76
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
77
- const cont = msg.filter(element => typeof element === 'string').join('');
77
+ const cont = msg
78
+ .map(item => {
79
+ if (typeof item === 'number')
80
+ return String(item);
81
+ return item;
82
+ })
83
+ .filter(element => typeof element === 'string')
84
+ .join('');
78
85
  try {
79
86
  return await Client.postDirectImage({
80
87
  id: event.msg.guild_id,
@@ -92,7 +99,9 @@ async function directMessage(e, event) {
92
99
  ? msg.join('')
93
100
  : typeof msg === 'string'
94
101
  ? msg
95
- : '';
102
+ : typeof msg === 'number'
103
+ ? `${msg}`
104
+ : '';
96
105
  if (content == '')
97
106
  return false;
98
107
  /**
@@ -83,7 +83,14 @@ export const GUILD_MEMBERS = async (event) => {
83
83
  // arr && find buffer
84
84
  if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
85
85
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
86
- const cont = msg.filter(element => typeof element === 'string').join('');
86
+ const cont = msg
87
+ .map(item => {
88
+ if (typeof item === 'number')
89
+ return String(item);
90
+ return item;
91
+ })
92
+ .filter(element => typeof element === 'string')
93
+ .join('');
87
94
  try {
88
95
  return await Client.postImage({
89
96
  id: ChannelData.id,
@@ -101,7 +108,9 @@ export const GUILD_MEMBERS = async (event) => {
101
108
  ? msg.join('')
102
109
  : typeof msg === 'string'
103
110
  ? msg
104
- : '';
111
+ : typeof msg === 'number'
112
+ ? `${msg}`
113
+ : '';
105
114
  if (content == '')
106
115
  return false;
107
116
  /**
@@ -75,7 +75,14 @@ export const mergeMessages = async (e, event) => {
75
75
  // arr & find buffer
76
76
  if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
77
77
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
78
- const cont = msg.filter(element => typeof element === 'string').join('');
78
+ const cont = msg
79
+ .map(item => {
80
+ if (typeof item === 'number')
81
+ return String(item);
82
+ return item;
83
+ })
84
+ .filter(element => typeof element === 'string')
85
+ .join('');
79
86
  try {
80
87
  return await Client.postImage({
81
88
  id: event.msg.channel_id,
@@ -93,7 +100,9 @@ export const mergeMessages = async (e, event) => {
93
100
  ? msg.join('')
94
101
  : typeof msg === 'string'
95
102
  ? msg
96
- : '';
103
+ : typeof msg === 'number'
104
+ ? `${msg}`
105
+ : '';
97
106
  if (content == '')
98
107
  return false;
99
108
  /**
@@ -39,7 +39,14 @@ export const Private = async (EMessage, msg, select) => {
39
39
  }
40
40
  if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
41
41
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
42
- const cont = msg.filter(element => typeof element === 'string').join('');
42
+ const cont = msg
43
+ .map(item => {
44
+ if (typeof item === 'number')
45
+ return String(item);
46
+ return item;
47
+ })
48
+ .filter(element => typeof element === 'string')
49
+ .join('');
43
50
  try {
44
51
  return await Client.postDirectImage({
45
52
  id: EMessage.guild_id,
@@ -57,7 +64,9 @@ export const Private = async (EMessage, msg, select) => {
57
64
  ? msg.join('')
58
65
  : typeof msg === 'string'
59
66
  ? msg
60
- : '';
67
+ : typeof msg === 'number'
68
+ ? `${msg}`
69
+ : '';
61
70
  if (content == '')
62
71
  return false;
63
72
  /**
@@ -277,7 +277,14 @@ export async function MESSAGES_VILLA(event) {
277
277
  // 找到其中一个buffer
278
278
  const isBuffer = msg.findIndex(item => Buffer.isBuffer(item));
279
279
  // 删除所有buffer
280
- const cont = msg.filter(element => typeof element === 'string').join('');
280
+ const cont = msg
281
+ .map(item => {
282
+ if (typeof item === 'number')
283
+ return String(item);
284
+ return item;
285
+ })
286
+ .filter(element => typeof element === 'string')
287
+ .join('');
281
288
  // 字符解析器
282
289
  const { entities, content } = await Client.stringParsing(cont, villa_id);
283
290
  // 挂载图片
@@ -308,7 +315,9 @@ export async function MESSAGES_VILLA(event) {
308
315
  ? msg.join('')
309
316
  : typeof msg === 'string'
310
317
  ? msg
311
- : '';
318
+ : typeof msg === 'number'
319
+ ? `${msg}`
320
+ : '';
312
321
  if (cont == '')
313
322
  return false;
314
323
  /**
@@ -3,6 +3,7 @@ import Router from 'koa-router';
3
3
  import bodyParser from 'koa-bodyparser';
4
4
  import { setClientConfig } from './config.js';
5
5
  import { getIP } from '../../core/index.js';
6
+ import { getServerConfig } from '../../koa/config.js';
6
7
  /**
7
8
  * tudo
8
9
  * 需要验证登录是否成功
@@ -108,7 +109,11 @@ export function createClient({ bot_id, bot_secret, callback_url = '/api/mys/call
108
109
  await logFnc(port);
109
110
  }
110
111
  // 获取ip4
111
- const ip = await getIP();
112
+ let ip = await getIP();
113
+ const ipp = getServerConfig('ip');
114
+ if (ipp != 'localhost') {
115
+ ip = ipp;
116
+ }
112
117
  if (ip) {
113
118
  console.info('villa open', `http://${ip}:${port ?? 8080}${callback_url ?? '/api/mys/callback'}`);
114
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "DOCS https://alemonjs.com/",
5
5
  "author": "ningmengchongshui",
6
6
  "license": "GPL-2.0",
@@ -31,6 +31,10 @@ interface ApplicationProcessingOpsion {
31
31
  * 事件屏蔽器
32
32
  */
33
33
  event: string[];
34
+ /**
35
+ * 起始符特性
36
+ */
37
+ character: RegExp;
34
38
  }
35
39
  /**
36
40
  * 设置插件解析配置
@@ -19,6 +19,7 @@ export interface PluginInitType {
19
19
  name?: string;
20
20
  dsc?: string;
21
21
  rule?: PluginRuleType[];
22
+ character?: '/' | '#';
22
23
  /**
23
24
  * @deprecated 已废弃,建议使用原生模块 node-schedule
24
25
  */
@@ -82,6 +83,10 @@ export declare class plugin {
82
83
  * 匹配集
83
84
  */
84
85
  rule?: PluginRuleType[];
86
+ /**
87
+ * 起始符特性
88
+ */
89
+ character?: '/' | '#';
85
90
  /**
86
91
  * @deprecated 已废弃,建议使用原生模块 node-schedule
87
92
  */
@@ -97,14 +102,14 @@ export declare class plugin {
97
102
  * @param rule.doc 指令文档 doc
98
103
  * @param rule.priority 优先级 数字越小优先级越高
99
104
  */
100
- constructor({ name, event, eventType, priority, rule, task }: PluginInitType);
105
+ constructor({ name, event, eventType, priority, character, rule, task }: PluginInitType);
101
106
  /**
102
107
  * @param content 内容
103
108
  * @param img 图片buffer | 指定图片名
104
109
  * @param name 指定图片名
105
110
  * @returns 是否处理完成
106
111
  */
107
- reply(content: Buffer | string | (Buffer | string)[], select?: {
112
+ reply(content: Buffer | string | number | (Buffer | number | string)[], select?: {
108
113
  quote?: string;
109
114
  withdraw?: number;
110
115
  }): Promise<any>;
@@ -324,7 +324,7 @@ interface replyController {
324
324
  /**
325
325
  * 消息内容
326
326
  */
327
- content: Buffer | string | (Buffer | string)[],
327
+ content: Buffer | string | number | (Buffer | number | string)[],
328
328
  /**
329
329
  * 选择
330
330
  */
@@ -351,7 +351,7 @@ interface replyController {
351
351
  * @param select.withdraw 撤回消息,默认不撤回
352
352
  * @returns
353
353
  */
354
- replyPrivate?(content: Buffer | string | (Buffer | string)[], select: {
354
+ replyPrivate?(content: Buffer | string | number | (Buffer | number | string)[], select: {
355
355
  quote?: string;
356
356
  withdraw?: number;
357
357
  }): Promise<any>;
@@ -20,6 +20,10 @@ export interface AlemonOptions {
20
20
  * 是否生成json
21
21
  */
22
22
  regex?: boolean;
23
+ /**
24
+ * 自定义起始符规则
25
+ */
26
+ character?: RegExp;
23
27
  /**
24
28
  * 个人应用
25
29
  */
@@ -6,6 +6,10 @@ export interface ServerOptions {
6
6
  * 协议
7
7
  */
8
8
  http?: string;
9
+ /**
10
+ * 地址
11
+ */
12
+ ip?: string;
9
13
  /**
10
14
  * 端口
11
15
  */