From c16e55d56c6a0a3def559601b85298a3d2cd32d6 Mon Sep 17 00:00:00 2001
From: Wizzard <rich@bandaholics.cash>
Date: Thu, 10 Apr 2025 14:52:22 -0400
Subject: [PATCH] allow mentioning users instead of using userids

---
 commands/groupadd.js |  9 +++++++--
 commands/react.js    |  8 +++++---
 commands/reply.js    |  8 +++++---
 utils/userUtils.js   | 27 +++++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 8 deletions(-)
 create mode 100644 utils/userUtils.js

diff --git a/commands/groupadd.js b/commands/groupadd.js
index 9445f26..0654a28 100644
--- a/commands/groupadd.js
+++ b/commands/groupadd.js
@@ -11,6 +11,8 @@ module.exports = {
     name: 'groupadd',
     description: 'Automatically re-adds users to group when they leave. Use multiple IDs for multiple targets.',
     async execute(message, args, deleteTimeout) {
+        const { extractUserId } = require('../utils/userUtils');
+        
         if (message.channel.type !== 'GROUP_DM') {
             message.channel.send('This command only works in group DMs.')
                 .then(msg => setTimeout(() => msg.delete().catch(() => { }), deleteTimeout));
@@ -29,9 +31,12 @@ module.exports = {
             return;
         }
 
-        const validIds = args.filter(id => /^\d{17,19}$/.test(id));
+        const validIds = args
+            .map(arg => extractUserId(arg))
+            .filter(id => id !== null);
+            
         if (validIds.length === 0) {
-            message.channel.send('Please provide at least one valid user ID.')
+            message.channel.send('Please provide at least one valid user ID or @mention.')
                 .then(msg => setTimeout(() => msg.delete().catch(() => { }), deleteTimeout));
             return;
         }
diff --git a/commands/react.js b/commands/react.js
index bc1335f..8ca9678 100644
--- a/commands/react.js
+++ b/commands/react.js
@@ -1,7 +1,9 @@
 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.`,
   async execute(message, args, deleteTimeout) {
+    const { processUserInput } = require('../utils/userUtils');
+    
     if (args.length === 0) {
       if (message.client.targetReactUserIds && message.client.reactEmojis) {
         const statusMsg = await message.channel.send(
@@ -33,11 +35,11 @@ module.exports = {
       return;
     }
 
-    const targetIds = args[0].split(',').map(id => id.trim());
+    const targetIds = processUserInput(args[0]);
     const emojis = args.slice(1);
 
     if (targetIds.length === 0 || emojis.length === 0) {
-      const errorMsg = await message.channel.send('Please provide valid user IDs and at least one emoji.');
+      const errorMsg = await message.channel.send('Please provide valid user IDs or @mentions and at least one emoji.');
       setTimeout(() => errorMsg.delete().catch(console.error), deleteTimeout);
       return;
     }
diff --git a/commands/reply.js b/commands/reply.js
index 6d35360..2b75cb6 100644
--- a/commands/reply.js
+++ b/commands/reply.js
@@ -1,7 +1,9 @@
 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.`,
     async execute(message, args, deleteTimeout) {
+      const { processUserInput } = require('../utils/userUtils');
+      
       if (args.length === 0) {
         if (message.client.targetReplyUserIds && message.client.replyMessage) {
           const statusMsg = await message.channel.send(
@@ -33,11 +35,11 @@ module.exports = {
         return;
       }
   
-      const targetIds = args[0].split(',').map(id => id.trim());
+      const targetIds = processUserInput(args[0]);
       const replyMessage = args.slice(1).join(' ');
   
       if (targetIds.length === 0 || !replyMessage) {
-        const errorMsg = await message.channel.send('Please provide valid user IDs and a message to reply with.');
+        const errorMsg = await message.channel.send('Please provide valid user IDs or @mentions and a message to reply with.');
         setTimeout(() => errorMsg.delete().catch(console.error), deleteTimeout);
         return;
       }
diff --git a/utils/userUtils.js b/utils/userUtils.js
new file mode 100644
index 0000000..0fbc22b
--- /dev/null
+++ b/utils/userUtils.js
@@ -0,0 +1,27 @@
+function extractUserId(input) {
+    if (/^\d{17,19}$/.test(input)) {
+        return input;
+    }
+
+    const mentionRegex = /<@!?(\d{17,19})>/;
+    const match = input.match(mentionRegex);
+
+    if (match && match[1]) {
+        return match[1];
+    }
+
+    return null;
+}
+
+function processUserInput(input) {
+    return input
+        .split(',')
+        .map(part => part.trim())
+        .map(part => extractUserId(part))
+        .filter(id => id !== null);
+}
+
+module.exports = {
+    extractUserId,
+    processUserInput
+}; 
\ No newline at end of file