Fix targetting multi user
This commit is contained in:
parent
5f750b0666
commit
73149b8d6d
68
commands/react.js
vendored
68
commands/react.js
vendored
@ -2,7 +2,7 @@ const { sendCommandResponse } = require('../utils/messageUtils');
|
||||
|
||||
module.exports = {
|
||||
name: 'react',
|
||||
description: `Automatically react with specified emojis to multiple users' messages, or stop reacting.`,
|
||||
description: `Automatically react with specified emojis to multiple users' messages, or stop reacting. Usage: .react [user1,user2,...] [emoji1] [emoji2] ...`,
|
||||
async execute(message, args, deleteTimeout) {
|
||||
const { processUserInput } = require('../utils/userUtils');
|
||||
|
||||
@ -36,22 +36,68 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetIds = processUserInput(args[0]);
|
||||
const emojis = args.slice(1);
|
||||
// Find where the emojis start
|
||||
let emojiStartIndex = -1;
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
// Check if this argument looks like an emoji (contains : or is a single character)
|
||||
if (args[i].includes(':') || args[i].length <= 2) {
|
||||
emojiStartIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetIds.length === 0 || emojis.length === 0) {
|
||||
await sendCommandResponse(message, 'Please provide valid user IDs or @mentions and at least one emoji.', deleteTimeout, false);
|
||||
if (emojiStartIndex === -1) {
|
||||
await sendCommandResponse(message, 'Please provide at least one emoji to react with.', deleteTimeout, false);
|
||||
return;
|
||||
}
|
||||
|
||||
message.client.targetReactUserIds = targetIds;
|
||||
message.client.reactEmojis = emojis;
|
||||
// All arguments before emojiStartIndex are user IDs
|
||||
const userInput = args.slice(0, emojiStartIndex).join(' ');
|
||||
const emojis = args.slice(emojiStartIndex);
|
||||
|
||||
console.log(`[REACT] Processing user input: "${userInput}"`);
|
||||
const targetIds = processUserInput(userInput);
|
||||
console.log(`[REACT] 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;
|
||||
}
|
||||
|
||||
// Process emojis to handle custom emojis
|
||||
const processedEmojis = emojis.map(emoji => {
|
||||
// Check if it's a custom emoji (format: :name:)
|
||||
const customEmojiMatch = emoji.match(/^:([a-zA-Z0-9_]+):$/);
|
||||
if (customEmojiMatch) {
|
||||
// For custom emojis, we need to find the emoji ID from the guild
|
||||
const emojiName = customEmojiMatch[1];
|
||||
const customEmoji = message.guild?.emojis.cache.find(e => e.name === emojiName);
|
||||
if (customEmoji) {
|
||||
return customEmoji.id;
|
||||
}
|
||||
}
|
||||
// For standard emojis, just return as is
|
||||
return emoji;
|
||||
});
|
||||
|
||||
message.client.targetReactUserIds = targetIds;
|
||||
message.client.reactEmojis = processedEmojis;
|
||||
|
||||
// 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 react to messages from:\n${userListText}\n\nWith the following emojis: ${emojis.join(' ')}`;
|
||||
|
||||
console.log(`[REACT] Confirmation message: ${confirmationMessage}`);
|
||||
|
||||
await sendCommandResponse(
|
||||
message,
|
||||
`I will now react to messages from the following users: ${targetIds
|
||||
.map(id => `User ID: ${id}`)
|
||||
.join(', ')} with the following emojis: ${emojis.join(' ')}.`,
|
||||
confirmationMessage,
|
||||
deleteTimeout,
|
||||
false
|
||||
);
|
||||
@ -79,7 +125,7 @@ module.exports = {
|
||||
const initialDelay = getHumanizedDelay();
|
||||
await new Promise(resolve => setTimeout(resolve, initialDelay));
|
||||
|
||||
for (const emoji of emojis) {
|
||||
for (const emoji of processedEmojis) {
|
||||
if (Math.random() < 0.05) {
|
||||
console.log(`[REACT] Skipping emoji ${emoji} for more human-like behavior`);
|
||||
continue;
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -14,9 +14,15 @@ function extractUserId(input) {
|
||||
}
|
||||
|
||||
function processUserInput(input) {
|
||||
return input
|
||||
.split(',')
|
||||
.map(part => part.trim())
|
||||
// First try to split by commas
|
||||
let parts = input.split(',').map(part => part.trim()).filter(part => part !== '');
|
||||
|
||||
// If we only have one part, try splitting by spaces
|
||||
if (parts.length === 1) {
|
||||
parts = input.split(/\s+/).filter(part => part !== '');
|
||||
}
|
||||
|
||||
return parts
|
||||
.map(part => extractUserId(part))
|
||||
.filter(id => id !== null);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user