Fix targetting multi user
This commit is contained in:
@@ -2,7 +2,7 @@ const { sendCommandResponse } = require('../utils/messageUtils');
|
||||
|
||||
module.exports = {
|
||||
name: 'reply',
|
||||
description: `Automatically reply with a specified message to multiple users' messages, or stop replying.`,
|
||||
description: `Automatically reply with a specified message to multiple users' messages, or stop replying. Usage: .reply [user1,user2,...] [message]`,
|
||||
async execute(message, args, deleteTimeout) {
|
||||
const { processUserInput } = require('../utils/userUtils');
|
||||
|
||||
@@ -36,22 +36,52 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetIds = processUserInput(args[0]);
|
||||
const replyMessage = args.slice(1).join(' ');
|
||||
// Find where the message starts (after all user IDs)
|
||||
let messageStartIndex = -1;
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
// If this argument looks like a message (contains spaces or is longer than a user ID)
|
||||
if (args[i].includes(' ') || args[i].length > 20) {
|
||||
messageStartIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (messageStartIndex === -1) {
|
||||
await sendCommandResponse(message, 'Please provide a message to reply with.', deleteTimeout, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetIds.length === 0 || !replyMessage) {
|
||||
await sendCommandResponse(message, 'Please provide valid user IDs or @mentions and a message to reply with.', deleteTimeout, false);
|
||||
// All arguments before messageStartIndex are user IDs
|
||||
const userInput = args.slice(0, messageStartIndex).join(' ');
|
||||
const replyMessage = args.slice(messageStartIndex).join(' ');
|
||||
|
||||
console.log(`[REPLY] Processing user input: "${userInput}"`);
|
||||
const targetIds = processUserInput(userInput);
|
||||
console.log(`[REPLY] Extracted user IDs: ${targetIds.join(', ')}`);
|
||||
|
||||
if (targetIds.length === 0) {
|
||||
await sendCommandResponse(message, 'Please provide valid user IDs or @mentions. You can use multiple users separated by spaces or commas.', deleteTimeout, false);
|
||||
return;
|
||||
}
|
||||
|
||||
message.client.targetReplyUserIds = targetIds;
|
||||
message.client.replyMessage = replyMessage;
|
||||
|
||||
// Create a more detailed confirmation message with a different format
|
||||
let userListText = '';
|
||||
if (targetIds.length === 1) {
|
||||
userListText = `User ID: ${targetIds[0]}`;
|
||||
} else {
|
||||
userListText = targetIds.map((id, index) => `User ID ${index + 1}: ${id}`).join('\n');
|
||||
}
|
||||
|
||||
const confirmationMessage = `I will now reply to messages from:\n${userListText}\n\nWith the message: "${replyMessage}"`;
|
||||
|
||||
console.log(`[REPLY] Confirmation message: ${confirmationMessage}`);
|
||||
|
||||
await sendCommandResponse(
|
||||
message,
|
||||
`I will now reply to messages from the following users: ${targetIds
|
||||
.map(id => `User ID: ${id}`)
|
||||
.join(', ')} with the message: "${replyMessage}".`,
|
||||
confirmationMessage,
|
||||
deleteTimeout,
|
||||
false
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user