halbot 1995.1.6 → 1995.1.7
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/package.json +1 -1
- package/pipeline/010_broca.mjs +30 -31
- package/pipeline/020_cmd.mjs +9 -0
- package/pipeline/080_history.mjs +0 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "halbot",
|
|
3
3
|
"description": "Just another AI powered Telegram bot, which is simple design, easy to use, extendable and fun.",
|
|
4
|
-
"version": "1995.1.
|
|
4
|
+
"version": "1995.1.7",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/halbot",
|
|
7
7
|
"type": "module",
|
package/pipeline/010_broca.mjs
CHANGED
|
@@ -50,20 +50,19 @@ const resp = async (ctx, text, md, extra) => {
|
|
|
50
50
|
// }
|
|
51
51
|
let resp;
|
|
52
52
|
if (md) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
resp = await utilitas.ignoreErrFunc(async (
|
|
54
|
+
) => await (extra?.reply_parameters?.message_id
|
|
55
|
+
? ctx.replyWithMarkdown(text, { parse_mode, ...extra })
|
|
56
|
+
: ctx.sendMessage(text, { parse_mode, ...extra })), hal.logOptions);
|
|
57
|
+
}
|
|
58
|
+
if (!resp) {
|
|
59
|
+
await ctx.timeout();
|
|
60
|
+
resp = await utilitas.ignoreErrFunc(
|
|
61
|
+
async () => await (extra?.reply_parameters?.message_id
|
|
62
|
+
? ctx.reply(text, extra) : ctx.sendMessage(text, extra)
|
|
63
|
+
), hal.logOptions
|
|
64
|
+
);
|
|
61
65
|
}
|
|
62
|
-
resp || (resp = await utilitas.ignoreErrFunc(
|
|
63
|
-
async () => await (extra?.reply_parameters?.message_id
|
|
64
|
-
? ctx.reply(text, extra) : ctx.sendMessage(text, extra)
|
|
65
|
-
), hal.logOptions
|
|
66
|
-
));
|
|
67
66
|
resp && ctx._.done.push(resp);
|
|
68
67
|
return resp;
|
|
69
68
|
};
|
|
@@ -77,19 +76,18 @@ const replyWith = async (ctx, func, src, options) => ctx._.done.push(
|
|
|
77
76
|
const edit = async (ctx, lastMsgId, text, md, extra) => {
|
|
78
77
|
let resp;
|
|
79
78
|
if (md) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
resp = await utilitas.ignoreErrFunc(async (
|
|
80
|
+
) => await ctx.telegram.editMessageText(
|
|
81
|
+
ctx._.chatId, lastMsgId, '', text, { parse_mode, ...extra }
|
|
82
|
+
), hal.logOptions);
|
|
83
|
+
}
|
|
84
|
+
if (!resp) {
|
|
85
|
+
await ctx.timeout();
|
|
86
|
+
resp = await utilitas.ignoreErrFunc(async (
|
|
87
|
+
) => await ctx.telegram.editMessageText(
|
|
88
|
+
ctx._.chatId, lastMsgId, '', text, extra
|
|
89
|
+
), hal.logOptions);
|
|
88
90
|
}
|
|
89
|
-
resp || (resp = await utilitas.ignoreErrFunc(async (
|
|
90
|
-
) => await ctx.telegram.editMessageText(
|
|
91
|
-
ctx._.chatId, lastMsgId, '', text, extra
|
|
92
|
-
), hal.logOptions));
|
|
93
91
|
resp && ctx._.done.push(resp);
|
|
94
92
|
return resp;
|
|
95
93
|
};
|
|
@@ -148,14 +146,15 @@ const ctxExt = ctx => {
|
|
|
148
146
|
};
|
|
149
147
|
ctx.err = async (m, opts) => {
|
|
150
148
|
log(m);
|
|
151
|
-
return await ctx.ok(
|
|
149
|
+
return await ctx.ok(`${bot.EMOJI_WARNING} ${m?.message || m} `, opts);
|
|
152
150
|
};
|
|
153
|
-
ctx.shouldReply = async text => {
|
|
151
|
+
ctx.shouldReply = async (text, options) => {
|
|
154
152
|
const should = utilitas.insensitiveHas(hal._?.chatType, ctx._.chatType)
|
|
155
153
|
|| ctx._.session?.config?.chatty;
|
|
156
154
|
text = utilitas.isSet(text, true) ? (text || '') : '';
|
|
157
155
|
if (!should || !text) { return should; }
|
|
158
|
-
return await
|
|
156
|
+
return await (options?.error
|
|
157
|
+
? ctx.err(text, options) : ctx.ok(text, options));
|
|
159
158
|
};
|
|
160
159
|
ctx.finish = () => ctx._.done.unshift(null);
|
|
161
160
|
ctx.complete = async (options) => await ctx.ok(hal.CHECK, options);
|
|
@@ -241,10 +240,10 @@ const action = async (ctx, next) => {
|
|
|
241
240
|
await sessionSet(ctx._.chatId, ctx._.session);
|
|
242
241
|
// fallback response and log
|
|
243
242
|
if (ctx._.done.length) { return; }
|
|
244
|
-
const errStr =
|
|
245
|
-
? `Command not found: /${ctx._.cmd.cmd}` : 'No suitable response.'
|
|
243
|
+
const errStr = ctx._.cmd?.cmd
|
|
244
|
+
? `Command not found: /${ctx._.cmd.cmd}` : 'No suitable response.';
|
|
246
245
|
log(`INFO: ${errStr}`);
|
|
247
|
-
await ctx.shouldReply(errStr);
|
|
246
|
+
await ctx.shouldReply(errStr, { error: true });
|
|
248
247
|
};
|
|
249
248
|
|
|
250
249
|
export const { _NEED, name, run, priority, func } = {
|
package/pipeline/020_cmd.mjs
CHANGED
|
@@ -68,6 +68,15 @@ const action = async (ctx, next) => {
|
|
|
68
68
|
case 'clearkb':
|
|
69
69
|
return await ctx.complete({ keyboards: [] });
|
|
70
70
|
}
|
|
71
|
+
// update commands
|
|
72
|
+
await utilitas.ignoreErrFunc(async () =>
|
|
73
|
+
await hal._.bot.telegram.setMyCommands(hal._.cmds.sort((x, y) =>
|
|
74
|
+
(ctx._.session?.cmds?.[y.command.toLowerCase()]?.touchedAt || 0)
|
|
75
|
+
- (ctx._.session?.cmds?.[x.command.toLowerCase()]?.touchedAt || 0)
|
|
76
|
+
).slice(0, hal.COMMAND_LIMIT), {
|
|
77
|
+
scope: { type: 'chat', chat_id: ctx._.chatId },
|
|
78
|
+
}), hal.logOptions
|
|
79
|
+
);
|
|
71
80
|
// next middleware
|
|
72
81
|
await next();
|
|
73
82
|
};
|
package/pipeline/080_history.mjs
CHANGED
|
@@ -35,17 +35,6 @@ const memorize = async (ctx) => {
|
|
|
35
35
|
}
|
|
36
36
|
await hal._.storage?.client?.upsert?.(hal.table, event, { skipEcho: true });
|
|
37
37
|
}, hal.logOptions);
|
|
38
|
-
// TODO: 調整,如果命令執行過,應該更新菜單 !?
|
|
39
|
-
await utilitas.ignoreErrFunc(async () => await hal._.bot.telegram.setMyCommands([
|
|
40
|
-
...hal._.cmds, ...Object.keys(ctx._.message.prompts || {}).map(
|
|
41
|
-
command => hal.newCommand(command, ctx._.message.prompts[command])
|
|
42
|
-
)
|
|
43
|
-
].sort((x, y) =>
|
|
44
|
-
(ctx._.message?.cmds?.[y.command.toLowerCase()]?.touchedAt || 0)
|
|
45
|
-
- (ctx._.message?.cmds?.[x.command.toLowerCase()]?.touchedAt || 0)
|
|
46
|
-
).slice(0, hal.COMMAND_LIMIT), {
|
|
47
|
-
scope: { type: 'chat', chat_id: ctx._.chatId },
|
|
48
|
-
}), hal.logOptions);
|
|
49
38
|
};
|
|
50
39
|
|
|
51
40
|
const ctxExt = ctx => {
|
|
@@ -82,7 +71,6 @@ const action = async (ctx, next) => {
|
|
|
82
71
|
});
|
|
83
72
|
await ctx.timeout();
|
|
84
73
|
}
|
|
85
|
-
// TODO: NEED MORE DEBUG
|
|
86
74
|
result.length === hal.SEARCH_LIMIT && await ctx.resp(
|
|
87
75
|
'___', true, ctx.getExtra({
|
|
88
76
|
buttons: [{
|