Update react.js

This commit is contained in:
Wizzard 2024-09-08 12:56:52 -04:00
parent 90287d8f2c
commit af1be5486c
1 changed files with 19 additions and 11 deletions

30
commands/react.js vendored
View File

@ -1,11 +1,17 @@
module.exports = { module.exports = {
name: 'react', name: 'react',
description: 'Automatically react with specified emojis to a users messages, or stop reacting.', description: `Automatically react with specified emojis to multiple users messages, or stop reacting.\n
Usage:
.react <userID1,userID2,...> <emoji1> <emoji2> ... - React to messages from multiple users with specified emojis.
Example: \`.react 12345,67890 :smile: :thumbsup:\`
.react stop - Stop reacting to users' messages.`,
async execute(message, args, deleteTimeout) { async execute(message, args, deleteTimeout) {
if (args.length === 0) { if (args.length === 0) {
if (message.client.targetReactUserId && message.client.reactEmojis) { if (message.client.targetReactUserIds && message.client.reactEmojis) {
const statusMsg = await message.channel.send( const statusMsg = await message.channel.send(
`Currently reacting to <@${message.client.targetReactUserId}> with the following emojis: ${message.client.reactEmojis.join(' ')}.` `Currently reacting to messages from the following users: ${message.client.targetReactUserIds
.map(id => `<@${id}>`)
.join(', ')} with the following emojis: ${message.client.reactEmojis.join(' ')}.`
); );
setTimeout(() => statusMsg.delete().catch(console.error), deleteTimeout); setTimeout(() => statusMsg.delete().catch(console.error), deleteTimeout);
} else { } else {
@ -19,7 +25,7 @@ module.exports = {
if (message.client.reactListener) { if (message.client.reactListener) {
message.client.off('messageCreate', message.client.reactListener); message.client.off('messageCreate', message.client.reactListener);
message.client.reactListener = null; message.client.reactListener = null;
message.client.targetReactUserId = null; message.client.targetReactUserIds = null;
message.client.reactEmojis = null; message.client.reactEmojis = null;
const stopMsg = await message.channel.send('Stopped reacting to messages.'); const stopMsg = await message.channel.send('Stopped reacting to messages.');
@ -31,20 +37,22 @@ module.exports = {
return; return;
} }
const targetId = args[0]; const targetIds = args[0].split(',').map(id => id.trim());
const emojis = args.slice(1); const emojis = args.slice(1);
if (!targetId || emojis.length === 0) { if (targetIds.length === 0 || emojis.length === 0) {
const errorMsg = await message.channel.send('Please provide a valid user ID and at least one emoji.'); const errorMsg = await message.channel.send('Please provide valid user IDs and at least one emoji.');
setTimeout(() => errorMsg.delete().catch(console.error), deleteTimeout); setTimeout(() => errorMsg.delete().catch(console.error), deleteTimeout);
return; return;
} }
message.client.targetReactUserId = targetId; message.client.targetReactUserIds = targetIds;
message.client.reactEmojis = emojis; message.client.reactEmojis = emojis;
const confirmationMsg = await message.channel.send( const confirmationMsg = await message.channel.send(
`I will now react to messages from <@${targetId}> with the following emojis: ${emojis.join(' ')}.` `I will now react to messages from the following users: ${targetIds
.map(id => `<@${id}>`)
.join(', ')} with the following emojis: ${emojis.join(' ')}.`
); );
setTimeout(() => confirmationMsg.delete().catch(console.error), deleteTimeout); setTimeout(() => confirmationMsg.delete().catch(console.error), deleteTimeout);
@ -55,7 +63,7 @@ module.exports = {
const getRandomDelay = () => Math.floor(Math.random() * (5000 - 2000 + 1)) + 2000; const getRandomDelay = () => Math.floor(Math.random() * (5000 - 2000 + 1)) + 2000;
message.client.reactListener = async (msg) => { message.client.reactListener = async (msg) => {
if (msg.author.id === targetId) { if (message.client.targetReactUserIds.includes(msg.author.id)) {
for (const emoji of emojis) { for (const emoji of emojis) {
try { try {
const delay = getRandomDelay(); const delay = getRandomDelay();
@ -70,4 +78,4 @@ module.exports = {
message.client.on('messageCreate', message.client.reactListener); message.client.on('messageCreate', message.client.reactListener);
}, },
}; };