@link-assistant/hive-mind 1.43.0 → 1.44.0
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/lino.lib.mjs +42 -0
- package/src/telegram-accept-invitations.lib.mjs +8 -6
- package/src/telegram-bot.mjs +61 -59
- package/src/telegram-merge-command.lib.mjs +11 -6
- package/src/telegram-solve-queue-command.lib.mjs +8 -7
- package/src/telegram-top-command.lib.mjs +10 -5
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/lino.lib.mjs
CHANGED
|
@@ -96,6 +96,48 @@ export class LinksNotationManager {
|
|
|
96
96
|
return [];
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
parseLinks(input) {
|
|
100
|
+
if (!input) return [];
|
|
101
|
+
|
|
102
|
+
const parsed = this.parser.parse(input);
|
|
103
|
+
if (!parsed || parsed.length === 0) return [];
|
|
104
|
+
|
|
105
|
+
const link = parsed[0];
|
|
106
|
+
const pairs = [];
|
|
107
|
+
|
|
108
|
+
if (link.values && link.values.length > 0) {
|
|
109
|
+
const flatNumbers = [];
|
|
110
|
+
|
|
111
|
+
for (const value of link.values) {
|
|
112
|
+
if (value.id === null && value.values && value.values.length >= 2) {
|
|
113
|
+
const source = parseInt(value.values[0]?.id || value.values[0], 10);
|
|
114
|
+
const target = parseInt(value.values[1]?.id || value.values[1], 10);
|
|
115
|
+
if (!isNaN(source) && !isNaN(target)) {
|
|
116
|
+
pairs.push({ source, target });
|
|
117
|
+
}
|
|
118
|
+
} else if (value.id) {
|
|
119
|
+
const num = parseInt(value.id, 10);
|
|
120
|
+
if (!isNaN(num)) {
|
|
121
|
+
flatNumbers.push(num);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < flatNumbers.length - 1; i += 2) {
|
|
127
|
+
pairs.push({ source: flatNumbers[i], target: flatNumbers[i + 1] });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return pairs;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
formatLinks(pairs) {
|
|
135
|
+
if (!pairs || pairs.length === 0) return '()';
|
|
136
|
+
|
|
137
|
+
const formattedValues = pairs.map(pair => ` ${pair.source} ${pair.target}`).join('\n');
|
|
138
|
+
return `(\n${formattedValues}\n)`;
|
|
139
|
+
}
|
|
140
|
+
|
|
99
141
|
format(values) {
|
|
100
142
|
if (!values || values.length === 0) return '()';
|
|
101
143
|
|
|
@@ -116,10 +116,12 @@ function buildProgressMessage(state) {
|
|
|
116
116
|
* @param {Function} options.isForwardedOrReply - Function to check if message is forwarded/reply
|
|
117
117
|
* @param {Function} options.isGroupChat - Function to check if chat is a group
|
|
118
118
|
* @param {Function} options.isChatAuthorized - Function to check if chat is authorized
|
|
119
|
+
* @param {Function} [options.isTopicAuthorized] - Function to check if topic is authorized (issue #1100)
|
|
120
|
+
* @param {Function} [options.buildAuthErrorMessage] - Function to build authorization error message
|
|
119
121
|
* @param {Function} options.addBreadcrumb - Function to add breadcrumbs for monitoring
|
|
120
122
|
*/
|
|
121
123
|
export function registerAcceptInvitesCommand(bot, options) {
|
|
122
|
-
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized, addBreadcrumb } = options;
|
|
124
|
+
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized, isTopicAuthorized, buildAuthErrorMessage, addBreadcrumb } = options;
|
|
123
125
|
|
|
124
126
|
bot.command(/^accept[_-]?invites$/i, async ctx => {
|
|
125
127
|
VERBOSE && console.log('[VERBOSE] /accept_invites command received');
|
|
@@ -134,11 +136,11 @@ export function registerAcceptInvitesCommand(bot, options) {
|
|
|
134
136
|
return await ctx.reply('❌ The /accept_invites command only works in group chats. Please add this bot to a group and make it an admin.', {
|
|
135
137
|
reply_to_message_id: ctx.message.message_id,
|
|
136
138
|
});
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
const authorize = isTopicAuthorized || (ctx => isChatAuthorized(ctx.chat.id));
|
|
140
|
+
if (!authorize(ctx)) {
|
|
141
|
+
const errMsg = buildAuthErrorMessage ? buildAuthErrorMessage(ctx) : `❌ This chat (ID: ${ctx.chat.id}) is not authorized.`;
|
|
142
|
+
return await ctx.reply(errMsg, { reply_to_message_id: ctx.message.message_id });
|
|
143
|
+
}
|
|
142
144
|
|
|
143
145
|
const fetchingMessage = await ctx.reply('🔄 Fetching pending GitHub invitations\\.\\.\\.', {
|
|
144
146
|
reply_to_message_id: ctx.message.message_id,
|
package/src/telegram-bot.mjs
CHANGED
|
@@ -78,6 +78,12 @@ const config = yargs(hideBin(process.argv))
|
|
|
78
78
|
alias: 'allowed-chats',
|
|
79
79
|
default: getenv('TELEGRAM_ALLOWED_CHATS', ''),
|
|
80
80
|
})
|
|
81
|
+
.option('allowedTopics', {
|
|
82
|
+
type: 'string',
|
|
83
|
+
description: 'Allowed topic IDs in Links Notation format "chatId topicId" pairs',
|
|
84
|
+
alias: 'allowed-topics',
|
|
85
|
+
default: getenv('TELEGRAM_ALLOWED_TOPICS', ''),
|
|
86
|
+
})
|
|
81
87
|
.option('solveOverrides', {
|
|
82
88
|
type: 'string',
|
|
83
89
|
description: 'Override options for /solve command in lino notation, e.g., "(\n --auto-continue\n --attach-logs\n)"',
|
|
@@ -154,6 +160,10 @@ if (!BOT_TOKEN) {
|
|
|
154
160
|
const resolvedAllowedChats = config.allowedChats || getenv('TELEGRAM_ALLOWED_CHATS', '');
|
|
155
161
|
const allowedChats = resolvedAllowedChats ? lino.parseNumericIds(resolvedAllowedChats) : null;
|
|
156
162
|
|
|
163
|
+
// Parse allowed topics (chatId:topicId pairs in Links Notation)
|
|
164
|
+
const resolvedAllowedTopics = config.allowedTopics || getenv('TELEGRAM_ALLOWED_TOPICS', '');
|
|
165
|
+
const allowedTopics = resolvedAllowedTopics ? lino.parseLinks(resolvedAllowedTopics) : null;
|
|
166
|
+
|
|
157
167
|
// Parse override options
|
|
158
168
|
const resolvedSolveOverrides = config.solveOverrides || getenv('TELEGRAM_SOLVE_OVERRIDES', '');
|
|
159
169
|
const solveOverrides = resolvedSolveOverrides
|
|
@@ -277,6 +287,9 @@ if (config.dryRun) {
|
|
|
277
287
|
} else {
|
|
278
288
|
console.log(' Allowed chats: All (no restrictions)');
|
|
279
289
|
}
|
|
290
|
+
if (allowedTopics && allowedTopics.length > 0) {
|
|
291
|
+
console.log(' Allowed topics:', lino.formatLinks(allowedTopics));
|
|
292
|
+
}
|
|
280
293
|
console.log(' Commands enabled:', { solve: solveEnabled, hive: hiveEnabled });
|
|
281
294
|
if (solveOverrides.length > 0) {
|
|
282
295
|
console.log(' Solve overrides:', lino.format(solveOverrides));
|
|
@@ -319,6 +332,22 @@ function isChatAuthorized(chatId) {
|
|
|
319
332
|
return _isChatAuthorized(chatId, allowedChats);
|
|
320
333
|
}
|
|
321
334
|
|
|
335
|
+
// Topic-level authorization (issue #1100): chat-level auth overrides topic-level
|
|
336
|
+
function isTopicAuthorized(ctx) {
|
|
337
|
+
if (isChatAuthorized(ctx.chat?.id)) return true;
|
|
338
|
+
if (!allowedTopics || allowedTopics.length === 0) return false;
|
|
339
|
+
const chatId = ctx.chat?.id;
|
|
340
|
+
const topicId = ctx.message?.message_thread_id;
|
|
341
|
+
return allowedTopics.some(pair => pair.source === chatId && pair.target === topicId);
|
|
342
|
+
}
|
|
343
|
+
function buildAuthErrorMessage(ctx) {
|
|
344
|
+
const chatId = ctx.chat?.id;
|
|
345
|
+
const topicId = ctx.message?.message_thread_id;
|
|
346
|
+
let msg = `❌ This chat (ID: ${chatId})`;
|
|
347
|
+
if (topicId) msg += ` and topic (ID: ${topicId})`;
|
|
348
|
+
return msg + ' is not authorized.\n\nUse /help to see your chat and topic IDs.';
|
|
349
|
+
}
|
|
350
|
+
|
|
322
351
|
function isOldMessage(ctx) {
|
|
323
352
|
return _isOldMessage(ctx, BOT_START_TIME, { verbose: VERBOSE });
|
|
324
353
|
}
|
|
@@ -621,7 +650,7 @@ bot.command('help', async ctx => {
|
|
|
621
650
|
const chatId = ctx.chat.id;
|
|
622
651
|
const chatType = ctx.chat.type;
|
|
623
652
|
const chatTitle = ctx.chat.title || 'Private Chat';
|
|
624
|
-
|
|
653
|
+
const topicId = ctx.message?.message_thread_id; // Forum topic ID (issue #1100)
|
|
625
654
|
let message = '🤖 *SwarmMindBot Help*\n\n';
|
|
626
655
|
|
|
627
656
|
// Show stopped status if chat is stopped (issue #1081)
|
|
@@ -638,6 +667,7 @@ bot.command('help', async ctx => {
|
|
|
638
667
|
|
|
639
668
|
message += '📋 *Diagnostic Information:*\n';
|
|
640
669
|
message += `• Chat ID: \`${chatId}\`\n`;
|
|
670
|
+
if (topicId) message += `• Topic ID: \`${topicId}\`\n`;
|
|
641
671
|
message += `• Chat Type: ${chatType}\n`;
|
|
642
672
|
message += `• Chat Title: ${chatTitle}\n\n`;
|
|
643
673
|
message += '📝 *Available Commands:*\n\n';
|
|
@@ -685,9 +715,10 @@ bot.command('help', async ctx => {
|
|
|
685
715
|
message += '• `--verbose` or `-v` - Verbose output | `--attach-logs` - Attach logs to PR\n';
|
|
686
716
|
message += '\n💡 *Tip:* Many more options available. See full documentation for complete list.\n';
|
|
687
717
|
|
|
688
|
-
if (allowedChats) {
|
|
689
|
-
|
|
690
|
-
message +=
|
|
718
|
+
if (allowedChats || allowedTopics) {
|
|
719
|
+
const authorized = isTopicAuthorized(ctx);
|
|
720
|
+
message += `\n🔒 *Restricted Mode:* Authorized: ${authorized ? '✅ Yes' : '❌ No'}`;
|
|
721
|
+
if (!authorized && topicId) message += `\n💡 To allow this topic: \`TELEGRAM_ALLOWED_TOPICS="(${chatId} ${topicId})"\``;
|
|
691
722
|
}
|
|
692
723
|
|
|
693
724
|
message += '\n\n🔧 *Troubleshooting:*\n';
|
|
@@ -728,10 +759,11 @@ bot.command('limits', async ctx => {
|
|
|
728
759
|
return;
|
|
729
760
|
}
|
|
730
761
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
762
|
+
if (!isTopicAuthorized(ctx)) {
|
|
763
|
+
if (VERBOSE) {
|
|
764
|
+
console.log('[VERBOSE] /limits ignored: not authorized');
|
|
765
|
+
}
|
|
766
|
+
await ctx.reply(buildAuthErrorMessage(ctx), { reply_to_message_id: ctx.message.message_id });
|
|
735
767
|
return;
|
|
736
768
|
}
|
|
737
769
|
|
|
@@ -768,8 +800,7 @@ bot.command('version', async ctx => {
|
|
|
768
800
|
});
|
|
769
801
|
if (isOldMessage(ctx) || isForwardedOrReply(ctx)) return;
|
|
770
802
|
if (!_isGroupChat(ctx)) return await ctx.reply('❌ The /version command only works in group chats. Please add this bot to a group and make it an admin.', { reply_to_message_id: ctx.message.message_id });
|
|
771
|
-
|
|
772
|
-
if (!isChatAuthorized(chatId)) return await ctx.reply(`❌ This chat (ID: ${chatId}) is not authorized to use this bot. Please contact the bot administrator.`, { reply_to_message_id: ctx.message.message_id });
|
|
803
|
+
if (!isTopicAuthorized(ctx)) return await ctx.reply(buildAuthErrorMessage(ctx), { reply_to_message_id: ctx.message.message_id });
|
|
773
804
|
const fetchingMessage = await ctx.reply('🔄 Gathering version information...', {
|
|
774
805
|
reply_to_message_id: ctx.message.message_id,
|
|
775
806
|
});
|
|
@@ -778,48 +809,18 @@ bot.command('version', async ctx => {
|
|
|
778
809
|
await ctx.telegram.editMessageText(fetchingMessage.chat.id, fetchingMessage.message_id, undefined, '🤖 *Version Information*\n\n' + formatVersionMessage(result.versions), { parse_mode: 'Markdown' });
|
|
779
810
|
});
|
|
780
811
|
|
|
781
|
-
// Register
|
|
782
|
-
// This keeps telegram-bot.mjs under the 1500 line limit
|
|
812
|
+
// Register external command modules (keeps telegram-bot.mjs under line limit)
|
|
783
813
|
const { registerAcceptInvitesCommand } = await import('./telegram-accept-invitations.lib.mjs');
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
isOldMessage,
|
|
787
|
-
isForwardedOrReply,
|
|
788
|
-
isGroupChat: _isGroupChat,
|
|
789
|
-
isChatAuthorized,
|
|
790
|
-
addBreadcrumb,
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
// Register /merge command from separate module (experimental, see issue #1143)
|
|
814
|
+
const sharedCommandOpts = { VERBOSE, isOldMessage, isForwardedOrReply, isGroupChat: _isGroupChat, isChatAuthorized, isTopicAuthorized, buildAuthErrorMessage, addBreadcrumb, isChatStopped, getStoppedChatRejectMessage };
|
|
815
|
+
registerAcceptInvitesCommand(bot, sharedCommandOpts);
|
|
794
816
|
const { registerMergeCommand } = await import('./telegram-merge-command.lib.mjs');
|
|
795
|
-
registerMergeCommand(bot,
|
|
796
|
-
VERBOSE,
|
|
797
|
-
isOldMessage,
|
|
798
|
-
isForwardedOrReply,
|
|
799
|
-
isGroupChat: _isGroupChat,
|
|
800
|
-
isChatAuthorized,
|
|
801
|
-
addBreadcrumb,
|
|
802
|
-
isChatStopped,
|
|
803
|
-
getStoppedChatRejectMessage,
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
// Register /solve_queue command from separate module (issue #1232)
|
|
817
|
+
registerMergeCommand(bot, sharedCommandOpts);
|
|
807
818
|
const { registerSolveQueueCommand } = await import('./telegram-solve-queue-command.lib.mjs');
|
|
808
|
-
const { handleSolveQueueCommand } = registerSolveQueueCommand(bot, {
|
|
809
|
-
VERBOSE,
|
|
810
|
-
isOldMessage,
|
|
811
|
-
isForwardedOrReply,
|
|
812
|
-
isGroupChat: _isGroupChat,
|
|
813
|
-
isChatAuthorized,
|
|
814
|
-
addBreadcrumb,
|
|
815
|
-
getSolveQueue,
|
|
816
|
-
});
|
|
819
|
+
const { handleSolveQueueCommand } = registerSolveQueueCommand(bot, { ...sharedCommandOpts, getSolveQueue });
|
|
817
820
|
|
|
818
821
|
// Named handler for /solve command - extracted for reuse by text-based fallback (issue #1207)
|
|
819
822
|
async function handleSolveCommand(ctx) {
|
|
820
|
-
|
|
821
|
-
console.log('[VERBOSE] /solve command received');
|
|
822
|
-
}
|
|
823
|
+
VERBOSE && console.log('[VERBOSE] /solve command received');
|
|
823
824
|
|
|
824
825
|
// Add breadcrumb for error tracking
|
|
825
826
|
await addBreadcrumb({
|
|
@@ -871,16 +872,16 @@ async function handleSolveCommand(ctx) {
|
|
|
871
872
|
return;
|
|
872
873
|
}
|
|
873
874
|
|
|
874
|
-
|
|
875
|
-
if (!isChatAuthorized(chatId)) {
|
|
875
|
+
if (!isTopicAuthorized(ctx)) {
|
|
876
876
|
if (VERBOSE) {
|
|
877
|
-
console.log('[VERBOSE] /solve ignored:
|
|
877
|
+
console.log('[VERBOSE] /solve ignored: not authorized');
|
|
878
878
|
}
|
|
879
|
-
await ctx.reply(
|
|
879
|
+
await ctx.reply(buildAuthErrorMessage(ctx), { reply_to_message_id: ctx.message.message_id });
|
|
880
880
|
return;
|
|
881
881
|
}
|
|
882
882
|
|
|
883
883
|
// Check if chat is stopped (issue #1081) - reject with same style as queue rejected mode
|
|
884
|
+
const chatId = ctx.chat.id;
|
|
884
885
|
if (isChatStopped(chatId)) {
|
|
885
886
|
VERBOSE && console.log('[VERBOSE] /solve rejected: chat is stopped');
|
|
886
887
|
await safeReply(ctx, getStoppedChatRejectMessage(chatId, 'Solve'), { reply_to_message_id: ctx.message.message_id });
|
|
@@ -1017,7 +1018,7 @@ async function handleSolveCommand(ctx) {
|
|
|
1017
1018
|
const existingItem = solveQueue.findByUrl(normalizedUrl);
|
|
1018
1019
|
if (existingItem) {
|
|
1019
1020
|
const statusText = existingItem.status === 'starting' || existingItem.status === 'started' ? 'being processed' : 'already in the queue';
|
|
1020
|
-
await safeReply(ctx, `❌ This URL is ${statusText}.\n\nURL: ${escapeMarkdown(normalizedUrl)}\nStatus: ${existingItem.status}\n\n💡 Use /
|
|
1021
|
+
await safeReply(ctx, `❌ This URL is ${statusText}.\n\nURL: ${escapeMarkdown(normalizedUrl)}\nStatus: ${existingItem.status}\n\n💡 Use /solve_queue to check the queue status.`, { reply_to_message_id: ctx.message.message_id });
|
|
1021
1022
|
return;
|
|
1022
1023
|
}
|
|
1023
1024
|
|
|
@@ -1099,16 +1100,16 @@ async function handleHiveCommand(ctx) {
|
|
|
1099
1100
|
return;
|
|
1100
1101
|
}
|
|
1101
1102
|
|
|
1102
|
-
|
|
1103
|
-
if (!isChatAuthorized(chatId)) {
|
|
1103
|
+
if (!isTopicAuthorized(ctx)) {
|
|
1104
1104
|
if (VERBOSE) {
|
|
1105
|
-
console.log('[VERBOSE] /hive ignored:
|
|
1105
|
+
console.log('[VERBOSE] /hive ignored: not authorized');
|
|
1106
1106
|
}
|
|
1107
|
-
await ctx.reply(
|
|
1107
|
+
await ctx.reply(buildAuthErrorMessage(ctx), { reply_to_message_id: ctx.message.message_id });
|
|
1108
1108
|
return;
|
|
1109
1109
|
}
|
|
1110
1110
|
|
|
1111
1111
|
// Check if chat is stopped (issue #1081) - reject with same style as queue rejected mode
|
|
1112
|
+
const chatId = ctx.chat.id;
|
|
1112
1113
|
if (isChatStopped(chatId)) {
|
|
1113
1114
|
VERBOSE && console.log('[VERBOSE] /hive rejected: chat is stopped');
|
|
1114
1115
|
await safeReply(ctx, getStoppedChatRejectMessage(chatId, 'Hive'), { reply_to_message_id: ctx.message.message_id });
|
|
@@ -1201,12 +1202,10 @@ async function handleHiveCommand(ctx) {
|
|
|
1201
1202
|
|
|
1202
1203
|
bot.command(/^hive$/i, handleHiveCommand);
|
|
1203
1204
|
|
|
1204
|
-
// Register commands from separate modules (keeps telegram-bot.mjs under line limit)
|
|
1205
1205
|
const { registerTopCommand } = await import('./telegram-top-command.lib.mjs');
|
|
1206
1206
|
const { registerStartStopCommands } = await import('./telegram-start-stop-command.lib.mjs');
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
registerStartStopCommands(bot, commandOptions); // issue #1081
|
|
1207
|
+
registerTopCommand(bot, sharedCommandOpts);
|
|
1208
|
+
registerStartStopCommands(bot, sharedCommandOpts);
|
|
1210
1209
|
|
|
1211
1210
|
// Add message listener for verbose debugging
|
|
1212
1211
|
if (VERBOSE) {
|
|
@@ -1389,6 +1388,9 @@ if (allowedChats && allowedChats.length > 0) {
|
|
|
1389
1388
|
} else {
|
|
1390
1389
|
console.log('Allowed chats: All (no restrictions)');
|
|
1391
1390
|
}
|
|
1391
|
+
if (allowedTopics && allowedTopics.length > 0) {
|
|
1392
|
+
console.log('Allowed topics (lino):', lino.formatLinks(allowedTopics));
|
|
1393
|
+
}
|
|
1392
1394
|
console.log('Commands enabled:', { solve: solveEnabled, hive: hiveEnabled });
|
|
1393
1395
|
if (solveOverrides.length > 0) console.log('Solve overrides (lino):', lino.format(solveOverrides));
|
|
1394
1396
|
if (hiveOverrides.length > 0) console.log('Hive overrides (lino):', lino.format(hiveOverrides));
|
|
@@ -130,10 +130,14 @@ function formatUserError(error, verbose) {
|
|
|
130
130
|
* @param {Function} options.isForwardedOrReply - Function to check if message is forwarded/reply
|
|
131
131
|
* @param {Function} options.isGroupChat - Function to check if chat is a group
|
|
132
132
|
* @param {Function} options.isChatAuthorized - Function to check if chat is authorized
|
|
133
|
+
* @param {Function} [options.isTopicAuthorized] - Function to check if topic is authorized (issue #1100)
|
|
134
|
+
* @param {Function} [options.buildAuthErrorMessage] - Function to build authorization error message
|
|
133
135
|
* @param {Function} options.addBreadcrumb - Function to add breadcrumbs for monitoring
|
|
136
|
+
* @param {Function} [options.isChatStopped] - Function to check if chat is stopped (issue #1081)
|
|
137
|
+
* @param {Function} [options.getStoppedChatRejectMessage] - Function to get stopped chat rejection message
|
|
134
138
|
*/
|
|
135
139
|
export function registerMergeCommand(bot, options) {
|
|
136
|
-
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized, addBreadcrumb, isChatStopped, getStoppedChatRejectMessage } = options;
|
|
140
|
+
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized, isTopicAuthorized, buildAuthErrorMessage, addBreadcrumb, isChatStopped, getStoppedChatRejectMessage } = options;
|
|
137
141
|
|
|
138
142
|
bot.command(/^merge$/i, async ctx => {
|
|
139
143
|
VERBOSE && console.log('[VERBOSE] /merge command received');
|
|
@@ -154,13 +158,14 @@ export function registerMergeCommand(bot, options) {
|
|
|
154
158
|
});
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
161
|
+
const authorize = isTopicAuthorized || (ctx => isChatAuthorized(ctx.chat.id));
|
|
162
|
+
if (!authorize(ctx)) {
|
|
163
|
+
const errMsg = buildAuthErrorMessage ? buildAuthErrorMessage(ctx) : `This chat (ID: ${ctx.chat.id}) is not authorized.`;
|
|
164
|
+
return await ctx.reply(errMsg, { reply_to_message_id: ctx.message.message_id });
|
|
162
165
|
}
|
|
163
166
|
|
|
167
|
+
const chatId = ctx.chat.id;
|
|
168
|
+
|
|
164
169
|
// Check if chat is stopped (issue #1081) - reject with same style as queue rejected mode
|
|
165
170
|
if (isChatStopped && isChatStopped(chatId)) {
|
|
166
171
|
VERBOSE && console.log('[VERBOSE] /merge rejected: chat is stopped');
|
|
@@ -22,12 +22,14 @@
|
|
|
22
22
|
* @param {Function} options.isForwardedOrReply - Function to check if message is forwarded/reply
|
|
23
23
|
* @param {Function} options.isGroupChat - Function to check if chat is a group
|
|
24
24
|
* @param {Function} options.isChatAuthorized - Function to check if chat is authorized
|
|
25
|
+
* @param {Function} [options.isTopicAuthorized] - Function to check if topic is authorized (issue #1100)
|
|
26
|
+
* @param {Function} [options.buildAuthErrorMessage] - Function to build authorization error message
|
|
25
27
|
* @param {Function} options.addBreadcrumb - Function to add breadcrumbs for monitoring
|
|
26
28
|
* @param {Function} options.getSolveQueue - Function to get the solve queue instance
|
|
27
29
|
* @returns {{ handleSolveQueueCommand: Function }} The command handler for use in text fallback
|
|
28
30
|
*/
|
|
29
31
|
export function registerSolveQueueCommand(bot, options) {
|
|
30
|
-
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized, addBreadcrumb, getSolveQueue } = options;
|
|
32
|
+
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized, isTopicAuthorized, buildAuthErrorMessage, addBreadcrumb, getSolveQueue } = options;
|
|
31
33
|
|
|
32
34
|
async function handleSolveQueueCommand(ctx) {
|
|
33
35
|
VERBOSE && console.log('[VERBOSE] /solve_queue command received');
|
|
@@ -59,12 +61,11 @@ export function registerSolveQueueCommand(bot, options) {
|
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
VERBOSE && console.log('[VERBOSE] /solve_queue ignored:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
64
|
+
const authorize = isTopicAuthorized || (ctx => isChatAuthorized(ctx.chat.id));
|
|
65
|
+
if (!authorize(ctx)) {
|
|
66
|
+
VERBOSE && console.log('[VERBOSE] /solve_queue ignored: not authorized');
|
|
67
|
+
const errMsg = buildAuthErrorMessage ? buildAuthErrorMessage(ctx) : `❌ This chat (ID: ${ctx.chat.id}) is not authorized.`;
|
|
68
|
+
await ctx.reply(errMsg, { reply_to_message_id: ctx.message.message_id });
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -51,9 +51,11 @@ async function captureTopOutput(chatId) {
|
|
|
51
51
|
* @param {Function} options.isForwardedOrReply - Function to check if message is forwarded/reply
|
|
52
52
|
* @param {Function} options.isGroupChat - Function to check if chat is a group
|
|
53
53
|
* @param {Function} options.isChatAuthorized - Function to check if chat is authorized
|
|
54
|
+
* @param {Function} [options.isTopicAuthorized] - Function to check if topic is authorized (issue #1100)
|
|
55
|
+
* @param {Function} [options.buildAuthErrorMessage] - Function to build authorization error message
|
|
54
56
|
*/
|
|
55
57
|
export function registerTopCommand(bot, options) {
|
|
56
|
-
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized } = options;
|
|
58
|
+
const { VERBOSE = false, isOldMessage, isForwardedOrReply, isGroupChat, isChatAuthorized, isTopicAuthorized, buildAuthErrorMessage } = options;
|
|
57
59
|
|
|
58
60
|
// /top command - show system top output in an auto-updating message (EXPERIMENTAL)
|
|
59
61
|
// Only accessible by chat owner
|
|
@@ -89,17 +91,20 @@ export function registerTopCommand(bot, options) {
|
|
|
89
91
|
return;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
94
|
+
const authorize = isTopicAuthorized || (ctx => isChatAuthorized(ctx.chat.id));
|
|
95
|
+
if (!authorize(ctx)) {
|
|
94
96
|
if (VERBOSE) {
|
|
95
|
-
console.log('[VERBOSE] /top ignored:
|
|
97
|
+
console.log('[VERBOSE] /top ignored: not authorized');
|
|
96
98
|
}
|
|
97
|
-
|
|
99
|
+
const errMsg = buildAuthErrorMessage ? buildAuthErrorMessage(ctx) : `❌ This chat (ID: ${ctx.chat.id}) is not authorized.`;
|
|
100
|
+
await ctx.reply(errMsg, {
|
|
98
101
|
reply_to_message_id: ctx.message.message_id,
|
|
99
102
|
});
|
|
100
103
|
return;
|
|
101
104
|
}
|
|
102
105
|
|
|
106
|
+
const chatId = ctx.chat.id;
|
|
107
|
+
|
|
103
108
|
// Check if user is chat owner
|
|
104
109
|
try {
|
|
105
110
|
const chatMember = await ctx.telegram.getChatMember(chatId, ctx.from.id);
|