From c452bb020a34bcfab5649e8831c29b2fb51d702f Mon Sep 17 00:00:00 2001 From: Sepp J Morris Date: Mon, 12 Oct 2020 18:36:01 +0200 Subject: [PATCH] added examples and fixed the reload tool - Update examples.js, commandloader.js, and 8 more files... --- zoizbot/Legacy Commands/examples.js | 2 +- zoizbot/commandloader.js | 8 ++++---- zoizbot/commands/fun/reloadfun.js | 20 +++++++++++++++++++ zoizbot/commands/general/reloadgeneral.js | 20 +++++++++++++++++++ zoizbot/commands/moderation/ban.js | 18 +++++++++++++++++ zoizbot/commands/moderation/embeddedkick.js | 18 +++++++++++++++++ zoizbot/commands/moderation/kick.js | 5 +++-- .../commands/moderation/reloadmoderation.js | 20 +++++++++++++++++++ zoizbot/commands/reload.js | 9 +++++++++ zoizbot/zoizbot.njsproj | 9 +++++++++ 10 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 zoizbot/commands/fun/reloadfun.js create mode 100644 zoizbot/commands/general/reloadgeneral.js create mode 100644 zoizbot/commands/moderation/ban.js create mode 100644 zoizbot/commands/moderation/embeddedkick.js create mode 100644 zoizbot/commands/moderation/reloadmoderation.js diff --git a/zoizbot/Legacy Commands/examples.js b/zoizbot/Legacy Commands/examples.js index 68d8f6f..e0a425e 100644 --- a/zoizbot/Legacy Commands/examples.js +++ b/zoizbot/Legacy Commands/examples.js @@ -1,6 +1,6 @@ /* - * This is for your reference. this is how we dit it first + * This is for your reference. this is how we did it first * check commit 459446526602d35af9cec596b552cddeeac4c992 * * we now use a "handler" and keep it organised with command files diff --git a/zoizbot/commandloader.js b/zoizbot/commandloader.js index d54fe3f..257b65e 100644 --- a/zoizbot/commandloader.js +++ b/zoizbot/commandloader.js @@ -7,8 +7,8 @@ fs.readdir (`./commands/`, (err, files) => { let commandName = file.split(".")[0]; console.log(` attempting to load command: ${commandName}`); // adding everything to the collection zoizbot.commands.set(commandName, props); - loaded++; // beginners trick to check if all the folder-commands where loaded // i really dont know what im doing here hahahaha }); + loaded++; // beginners trick to check if all the folder-commands where loaded // i really dont know what im doing here hahahaha //edit2 i made it even worse :( if (loaded == 4) { // this is the funniest shit i have ever done. pure for asthetics. please change this to a different way console.log(" ") console.log(` all commands loaded!`); @@ -24,8 +24,8 @@ fs.readdir (`./commands/fun/`, (err, files) => { let commandName = file.split(".")[0]; console.log(` attempting to load command: ${commandName}`); zoizbot.commands.set(commandName, props); - loaded++; }); + loaded++; if (loaded == 4) { console.log(" ") console.log(` all commands loaded!`); @@ -41,8 +41,8 @@ fs.readdir(`./commands/general/`, (err, files) => { let commandName = file.split(".")[0]; console.log(` attempting to load command: ${commandName}`); zoizbot.commands.set(commandName, props); - loaded++; }); + loaded++; if (loaded == 4) { console.log(" ") console.log(` all commands loaded!`); @@ -58,8 +58,8 @@ fs.readdir(`./commands/moderation/`, (err, files) => { //copy paste for differe let commandName = file.split(".")[0]; console.log(` attempting to load command: ${commandName}`); zoizbot.commands.set(commandName, props); - loaded++; }); + loaded++; if (loaded == 4) { console.log(" ") console.log(` all commands loaded!`); diff --git a/zoizbot/commands/fun/reloadfun.js b/zoizbot/commands/fun/reloadfun.js new file mode 100644 index 0000000..e5b9c6e --- /dev/null +++ b/zoizbot/commands/fun/reloadfun.js @@ -0,0 +1,20 @@ +/* + * a command that reloads the command you have edited to memory + * so you dont have to reboot the bot + * good for testing, not so much for production + * ive added the permission test, to make sure not everybody spams reload + */ +exports.run = (zoizbot, message, args) => { + if (!message.member.hasPermission("ADMINISTRATOR")) + return message.reply("Sorry, you don't have permissions to use this!"); + if (!args || args.length < 1) return message.reply("Please provide the command name to reload."); + const commandName = args[0]; + if (!zoizbot.commands.has(commandName)) { + return message.reply("That command does not exist"); + } + delete require.cache[require.resolve(`./${commandName}.js`)]; + zoizbot.commands.delete(commandName); + const props = require(`./${commandName}.js`); + zoizbot.commands.set(commandName, props); + message.reply(`The command ${commandName} has been reloaded`); +}; \ No newline at end of file diff --git a/zoizbot/commands/general/reloadgeneral.js b/zoizbot/commands/general/reloadgeneral.js new file mode 100644 index 0000000..e5b9c6e --- /dev/null +++ b/zoizbot/commands/general/reloadgeneral.js @@ -0,0 +1,20 @@ +/* + * a command that reloads the command you have edited to memory + * so you dont have to reboot the bot + * good for testing, not so much for production + * ive added the permission test, to make sure not everybody spams reload + */ +exports.run = (zoizbot, message, args) => { + if (!message.member.hasPermission("ADMINISTRATOR")) + return message.reply("Sorry, you don't have permissions to use this!"); + if (!args || args.length < 1) return message.reply("Please provide the command name to reload."); + const commandName = args[0]; + if (!zoizbot.commands.has(commandName)) { + return message.reply("That command does not exist"); + } + delete require.cache[require.resolve(`./${commandName}.js`)]; + zoizbot.commands.delete(commandName); + const props = require(`./${commandName}.js`); + zoizbot.commands.set(commandName, props); + message.reply(`The command ${commandName} has been reloaded`); +}; \ No newline at end of file diff --git a/zoizbot/commands/moderation/ban.js b/zoizbot/commands/moderation/ban.js new file mode 100644 index 0000000..5347331 --- /dev/null +++ b/zoizbot/commands/moderation/ban.js @@ -0,0 +1,18 @@ +exports.run = async (zoizbot, message, args) => { + if (!message.member.hasPermission("BAN_MEMBERS")) + return message.reply("Sorry, you don't have permissions to use this!") + + let member = message.guild.member(message.mentions.users.first()) || message.mentions.members.first(args[0]) + + if (!member) + return message.reply("Please mention a valid member of this server") + if (message.member.hasPermission("BAN_MEMBERS")) + return message.reply("I cannot ban this user! Invalid Permissions") + let banReason = args.join(" ").slice(22); + if (!banReason) { + banReason = "No reason provided" + } + + member.ban({ reason: banReason }) + return message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${banReason}`) +} \ No newline at end of file diff --git a/zoizbot/commands/moderation/embeddedkick.js b/zoizbot/commands/moderation/embeddedkick.js new file mode 100644 index 0000000..bf9d7ae --- /dev/null +++ b/zoizbot/commands/moderation/embeddedkick.js @@ -0,0 +1,18 @@ +exports.run = async (zoizbot, message, args) => { + if (!message.member.hasPermission("KICK_MEMBERS")) + return message.reply("Sorry, you don't have permissions to use this!"); + + let member = message.guild.member(message.mentions.users.first()) || message.mentions.members.first(args[0]) + if (!member) + return message.reply("Please mention a valid member of this server"); + if (!member.kickable) + return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?"); + + let KickReason = args.slice(1).join(' '); + if (!KickReason) KickReason = "No reason provided"; + + + await member.kick(KickReason) + .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`)); // now an adios moment + message.reply({ embed: { "title": "Kicked", "color": 15746887, "fields": [{ "name": "Information", "value": `${member.user.tag} has been kicked by ${message.author.tag}.\nReason: ${KickReason}` }] } }); // sebastiaan created this one, he likes the embedded stuff +} \ No newline at end of file diff --git a/zoizbot/commands/moderation/kick.js b/zoizbot/commands/moderation/kick.js index 33b2531..ddf4e2d 100644 --- a/zoizbot/commands/moderation/kick.js +++ b/zoizbot/commands/moderation/kick.js @@ -8,11 +8,12 @@ exports.run = async (zoizbot, message, args) => { if (!member.kickable) return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?"); - let KickReason = args.slice(1).join(' '); // slicing the arguments + let KickReason = args.slice(1).join(' '); // joining the sliced the arguments if (!KickReason) KickReason = "No reason provided"; await member.kick(KickReason) .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`)); // now an adios moment - message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${KickReason}`); + + message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${KickReason}`); } \ No newline at end of file diff --git a/zoizbot/commands/moderation/reloadmoderation.js b/zoizbot/commands/moderation/reloadmoderation.js new file mode 100644 index 0000000..e5b9c6e --- /dev/null +++ b/zoizbot/commands/moderation/reloadmoderation.js @@ -0,0 +1,20 @@ +/* + * a command that reloads the command you have edited to memory + * so you dont have to reboot the bot + * good for testing, not so much for production + * ive added the permission test, to make sure not everybody spams reload + */ +exports.run = (zoizbot, message, args) => { + if (!message.member.hasPermission("ADMINISTRATOR")) + return message.reply("Sorry, you don't have permissions to use this!"); + if (!args || args.length < 1) return message.reply("Please provide the command name to reload."); + const commandName = args[0]; + if (!zoizbot.commands.has(commandName)) { + return message.reply("That command does not exist"); + } + delete require.cache[require.resolve(`./${commandName}.js`)]; + zoizbot.commands.delete(commandName); + const props = require(`./${commandName}.js`); + zoizbot.commands.set(commandName, props); + message.reply(`The command ${commandName} has been reloaded`); +}; \ No newline at end of file diff --git a/zoizbot/commands/reload.js b/zoizbot/commands/reload.js index e5b9c6e..28bf596 100644 --- a/zoizbot/commands/reload.js +++ b/zoizbot/commands/reload.js @@ -5,6 +5,14 @@ * ive added the permission test, to make sure not everybody spams reload */ exports.run = (zoizbot, message, args) => { + const config = require("../conf.json"); + message.channel.send({ embed: { "title": "Reload Tool", "color": 15746887, "fields": [{ "name": "Reload command file Syntax", "value": ` \n${config.prefix}reloadmoderation "command"\n${config.prefix}reloadgeneral "command" \n${config.prefix}reloadfun "command"` }] } }); + + + /* + * uncomment if you have commandfiles in de /commands folder + * i did it the easy way. so should you haha + * if (!message.member.hasPermission("ADMINISTRATOR")) return message.reply("Sorry, you don't have permissions to use this!"); if (!args || args.length < 1) return message.reply("Please provide the command name to reload."); @@ -17,4 +25,5 @@ exports.run = (zoizbot, message, args) => { const props = require(`./${commandName}.js`); zoizbot.commands.set(commandName, props); message.reply(`The command ${commandName} has been reloaded`); + */ }; \ No newline at end of file diff --git a/zoizbot/zoizbot.njsproj b/zoizbot/zoizbot.njsproj index c6aa610..b6c56e4 100644 --- a/zoizbot/zoizbot.njsproj +++ b/zoizbot/zoizbot.njsproj @@ -45,15 +45,24 @@ Code + Code Code + + + Code + + + Code + Code + Code