allow mentioning users instead of using userids
This commit is contained in:
parent
38147c46a2
commit
c16e55d56c
@ -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;
|
||||
}
|
||||
|
8
commands/react.js
vendored
8
commands/react.js
vendored
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
27
utils/userUtils.js
Normal file
27
utils/userUtils.js
Normal file
@ -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
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user