Fix targetting multi user
This commit is contained in:
		
							
								
								
									
										66
									
								
								commands/react.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										66
									
								
								commands/react.js
									
									
									
									
										vendored
									
									
								
							| @@ -2,7 +2,7 @@ const { sendCommandResponse } = require('../utils/messageUtils'); | |||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|   name: 'react', |   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) { |   async execute(message, args, deleteTimeout) { | ||||||
|     const { processUserInput } = require('../utils/userUtils'); |     const { processUserInput } = require('../utils/userUtils'); | ||||||
|      |      | ||||||
| @@ -36,22 +36,68 @@ module.exports = { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const targetIds = processUserInput(args[0]); |     // Find where the emojis start | ||||||
|     const emojis = args.slice(1); |     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) { |     if (emojiStartIndex === -1) { | ||||||
|       await sendCommandResponse(message, 'Please provide valid user IDs or @mentions and at least one emoji.', deleteTimeout, false); |       await sendCommandResponse(message, 'Please provide at least one emoji to react with.', deleteTimeout, false); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // 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.targetReactUserIds = targetIds; | ||||||
|     message.client.reactEmojis = emojis; |     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( |     await sendCommandResponse( | ||||||
|       message, |       message, | ||||||
|       `I will now react to messages from the following users: ${targetIds |       confirmationMessage, | ||||||
|         .map(id => `User ID: ${id}`) |  | ||||||
|         .join(', ')} with the following emojis: ${emojis.join(' ')}.`, |  | ||||||
|       deleteTimeout, |       deleteTimeout, | ||||||
|       false |       false | ||||||
|     ); |     ); | ||||||
| @@ -79,7 +125,7 @@ module.exports = { | |||||||
|           const initialDelay = getHumanizedDelay(); |           const initialDelay = getHumanizedDelay(); | ||||||
|           await new Promise(resolve => setTimeout(resolve, initialDelay)); |           await new Promise(resolve => setTimeout(resolve, initialDelay)); | ||||||
|            |            | ||||||
|           for (const emoji of emojis) { |           for (const emoji of processedEmojis) { | ||||||
|             if (Math.random() < 0.05) { |             if (Math.random() < 0.05) { | ||||||
|               console.log(`[REACT] Skipping emoji ${emoji} for more human-like behavior`); |               console.log(`[REACT] Skipping emoji ${emoji} for more human-like behavior`); | ||||||
|               continue; |               continue; | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ const { sendCommandResponse } = require('../utils/messageUtils'); | |||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     name: 'reply', |     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) { |     async execute(message, args, deleteTimeout) { | ||||||
|       const { processUserInput } = require('../utils/userUtils'); |       const { processUserInput } = require('../utils/userUtils'); | ||||||
|        |        | ||||||
| @@ -36,22 +36,52 @@ module.exports = { | |||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|    |    | ||||||
|       const targetIds = processUserInput(args[0]); |       // Find where the message starts (after all user IDs) | ||||||
|       const replyMessage = args.slice(1).join(' '); |       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 (targetIds.length === 0 || !replyMessage) { |       if (messageStartIndex === -1) { | ||||||
|         await sendCommandResponse(message, 'Please provide valid user IDs or @mentions and a message to reply with.', deleteTimeout, false); |         await sendCommandResponse(message, 'Please provide a message to reply with.', deleteTimeout, false); | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |    | ||||||
|  |       // 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; |         return; | ||||||
|       } |       } | ||||||
|    |    | ||||||
|       message.client.targetReplyUserIds = targetIds; |       message.client.targetReplyUserIds = targetIds; | ||||||
|       message.client.replyMessage = replyMessage; |       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( |       await sendCommandResponse( | ||||||
|         message, |         message, | ||||||
|         `I will now reply to messages from the following users: ${targetIds |         confirmationMessage, | ||||||
|           .map(id => `User ID: ${id}`) |  | ||||||
|           .join(', ')} with the message: "${replyMessage}".`, |  | ||||||
|         deleteTimeout, |         deleteTimeout, | ||||||
|         false |         false | ||||||
|       ); |       ); | ||||||
|   | |||||||
| @@ -14,9 +14,15 @@ function extractUserId(input) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function processUserInput(input) { | function processUserInput(input) { | ||||||
|     return input |     // First try to split by commas | ||||||
|         .split(',') |     let parts = input.split(',').map(part => part.trim()).filter(part => part !== ''); | ||||||
|         .map(part => part.trim()) |      | ||||||
|  |     // 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)) |         .map(part => extractUserId(part)) | ||||||
|         .filter(id => id !== null); |         .filter(id => id !== null); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user