Move custom command files into own directory
This commit is contained in:
parent
e6bf4045ed
commit
4e41a035ed
9 changed files with 8 additions and 8 deletions
25
util/custom_commands/addCustomCommand.js
Normal file
25
util/custom_commands/addCustomCommand.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const fs = require('fs');
|
||||
module.exports = function(customName, customMessage, author){
|
||||
let sendText;
|
||||
const customPath = './data/customCommands.json';
|
||||
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
|
||||
let isExists = false;
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
sendText = "This custom command already exists";
|
||||
isExists = true;
|
||||
}
|
||||
});
|
||||
if (!isExists) {
|
||||
let newCustomCommand = {
|
||||
"customName": customName, "customMessage": customMessage, "author": author
|
||||
}
|
||||
customCommands.push(newCustomCommand)
|
||||
sendText = `New custom command with the name "${customName}" added`
|
||||
}
|
||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||
return sendText;
|
||||
}
|
23
util/custom_commands/customReplaceWithVariables.js
Normal file
23
util/custom_commands/customReplaceWithVariables.js
Normal 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
|
||||
}
|
23
util/custom_commands/deleteCustomCommand.js
Normal file
23
util/custom_commands/deleteCustomCommand.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const fs = require('fs')
|
||||
module.exports = function(customName, author, owners){
|
||||
const customPath = './data/customCommands.json';
|
||||
let sendText = "This custom command does not exist.";
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
let index = 0;
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
if(customCommand.author === author || owners.indexOf(author) != -1 ){
|
||||
customCommands.splice(index, 1)
|
||||
sendText = `The custom command "${customName}" has been deleted.`
|
||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||
}else {
|
||||
sendText = "You do not own this custom command.\nOnly the one who created the custom command can delete it."
|
||||
}
|
||||
}
|
||||
index++
|
||||
});
|
||||
|
||||
|
||||
return sendText;
|
||||
}
|
20
util/custom_commands/editCustomCommand.js
Normal file
20
util/custom_commands/editCustomCommand.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const fs = require('fs')
|
||||
module.exports = function(customName, author, newCustomMessage){
|
||||
const customPath = './data/customCommands.json';
|
||||
let sendText = "This custom command does not exist.";
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
if(customCommand.author === author){
|
||||
customCommand.customMessage = newCustomMessage;
|
||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||
sendText = `${customName} has been updated.`;
|
||||
}else {
|
||||
sendText = "You do not own this custom command.\nOnly the one who created the custom command can edit it."
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return sendText;
|
||||
}
|
13
util/custom_commands/getAllCustomCommands.js
Normal file
13
util/custom_commands/getAllCustomCommands.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const fs = require('fs');
|
||||
module.exports = function(){
|
||||
const customPath = './data/customCommands.json';
|
||||
let list = "";
|
||||
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
customCommands.forEach(function (customCommand) {
|
||||
list = list + customCommand.customName+"\n";
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
15
util/custom_commands/getOwnerOfCustomCommand.js
Normal file
15
util/custom_commands/getOwnerOfCustomCommand.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const fs = require('fs');
|
||||
module.exports = function(customName){
|
||||
let author = false;
|
||||
const customPath = './data/customCommands.json';
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
author = customCommand.author;
|
||||
}
|
||||
});
|
||||
|
||||
return author;
|
||||
|
||||
}
|
33
util/custom_commands/renameCustomCommand.js
Normal file
33
util/custom_commands/renameCustomCommand.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const fs = require('fs')
|
||||
module.exports = function(customName, newCustomName, author){
|
||||
const customPath = './data/customCommands.json';
|
||||
let sendText = "This custom command does not exist.";
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
let alreadyExists = false;
|
||||
let commandExists = false;
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if(customCommand.customName === customName){
|
||||
commandExists = true;
|
||||
}
|
||||
if (customCommand.customName === newCustomName) {
|
||||
alreadyExists = true;
|
||||
sendText = "Can't rename this custom command. A custom command with that name already exists.";
|
||||
}
|
||||
});
|
||||
if (!alreadyExists && commandExists){
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
if(customCommand.author === author){
|
||||
customCommand.customName = newCustomName;
|
||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||
sendText = `${customName} has been renamed to ${newCustomName}.`;
|
||||
}else {
|
||||
sendText = "You do not own this custom command.\nOnly the one who created the custom command can rename it."
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return sendText;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue