Add custom variables to custom message feature

This commit is contained in:
SileNce5k 2021-07-04 12:48:06 +02:00
parent 67f674c92b
commit 9bb9effaf7
No known key found for this signature in database
GPG key ID: C507260E7F2583AD
3 changed files with 30 additions and 2 deletions

View file

@ -10,7 +10,8 @@ module.exports = {
moreHelp: ["<prefix>custom add - Add new custom commands",
"<prefix>custom remove - Delete your custom commands.",
"<prefix>custom owner - check owner of custom command",
"<prefix>custom list - list all custom commands"
"<prefix>custom list - list all custom commands",
"<prefix>custom variables - list all variables you can use"
],
execute({message, args, client}) {
const customPath = './data/customCommands.json';
@ -53,6 +54,9 @@ module.exports = {
sendText = embed
}else sendText = "NO CUSTOM COMMANDS"
break;
case "variables":
sendText = "The variables you can use are:\n<prefix>\n<globalPrefix>\n<username>\n<nickname>\n<user_id>\n<discriminator>\n<guild_name>\n<guild_id>"
break;
default:
sendText = "Argument not recognized."
break;

View file

@ -27,7 +27,8 @@ module.exports = function(client, owners, message, globalPrefix){
let customCommands = JSON.parse(json)
customCommands.forEach(function (customCommand) {
if (customCommand.customName === commandName) {
message.channel.send(customCommand.customMessage)
let customMessage = customReplaceWithVariables(customCommand.customMessage, message, prefix, globalPrefix)
message.channel.send(customMessage)
}
});
}

View file

@ -0,0 +1,23 @@
const getNickname = require('./getNickname')
module.exports = function(customMessage, message, prefix, globalPrefix){
let user = message.guild.members.cache.get(message.author.id);
let nickname = getNickname(user, message.guild)
let username = user.user.username
let userID = user.user.id
let discriminator = user.user.discriminator
let guildName = message.guild.name
let guildID = message.guild.id
let variables = ["<prefix>", "<globalPrefix>", "<username>", "<nickname>", "<user_id>", "<discriminator>", "<guild_name>", "<guild_id>"]
let replacer = [prefix, globalPrefix, username, nickname, userID, discriminator, guildName, guildID]
for (let i = 0; i < variables.length; i++){
const regex = new RegExp(variables[i], 'g')
customMessage = customMessage.replace(regex, replacer[i])
}
return customMessage
}