diff --git a/zoizbot/app.js b/zoizbot/app.js
index 36c3aff..4e2541d 100644
--- a/zoizbot/app.js
+++ b/zoizbot/app.js
@@ -5,30 +5,38 @@ const zoizbot = new Discord.Client(); // discord client is now made zoizbot. wat
var fs = require('fs');
+zoizbot.commands = new Discord.Collection();
+
+console.log("==============================================");
console.log(`starting zoizbot...`);
+eval(fs.readFileSync('./bootscreen.js') + ''); // please delete this, using readFileSync 1 time was bad enough. But I didnt want ascii art in my main file ;)
console.log(`loading configuration file...`)
const config = require("./conf.json"); // de conf ophalen die we net gemaakt hadden / picking up the config file we made
-console.log(`Ready!`) //normally if you would make it properly you would catch any errors when loading the config
+console.log(`configuration loaded!`) // should make an catch error to debug conf file but whatever
+console.log("==============================================");
+console.log(`loading the commandhandler...`)
-zoizbot.on("ready", () => {
- console.log(`Zoizbot has started, and is serving ${zoizbot.users.cache.size} users, in ${zoizbot.guilds.cache.size} guilds.`); // you can display anything you want here, all the functions are available in de documentation from discord.js
+eval(fs.readFileSync('./commandhandler.js') + '');
- zoizbot.user.setActivity(`Ask me something with >`); // change this to whatever you want. check out https://discord.js.org/#/docs/main/12.3.1/general/welcome
+console.log(`commandhandler loaded!`)
+console.log("==============================================");
+console.log(`loading command-files...`)
+
+fs.readdir(`./commands/`, (err, files) => {
+ if (err) return console.error(err);
+ files.forEach(file => {
+ if (!file.endsWith(".js")) return; // only load js files. no garbage collection
+ let props = require(`./commands/${file}`); // get the command name from the file.js
+ let commandName = file.split(".")[0];
+ console.log(`attempting to load command ${commandName}`); // adding everything to the collection
+ zoizbot.commands.set(commandName, props);
+ });
+ console.log(`all commands loaded!`);
+ console.log("==============================================");
});
-zoizbot.on("guildJoin", guild => {
- console.log(`I have joined ${guild.name}, I will be serving ${guild.memberCount} members!`); // Join server message in the console
- message.channel.send(`Hello ${guild.name} thank you for having me!`);
-});
-
-zoizbot.on("guildLeave", guild => {
- console.log(`Adios! i will be leaving: ${guild.name} It was fun while it lasted!`);
-});
-
-
-eval(fs.readFileSync('./commands/examples.js') + ''); //dirty but working trick to keep app main clean...
zoizbot.login(config.token); //reading the "token" from the const config = conf.json btw the one you see is invalid now
diff --git a/zoizbot/bootscreen.js b/zoizbot/bootscreen.js
new file mode 100644
index 0000000..62bbfe4
--- /dev/null
+++ b/zoizbot/bootscreen.js
@@ -0,0 +1,15 @@
+// bad practice please remove this file and the fileReadSync function
+console.log("==============================================");
+console.log(" ,--, ");
+console.log(" ,----, ,---. ,--.'| ,----, ");
+console.log(" .' .`| ' ,'\ | |, .' .`| ");
+console.log(" .' .' .' / / |`--'_ .' .' .' ");
+console.log(",---, ' ./ . ; ,. :,' ,'| ,---, ' ./ ");
+console.log("; | .' / ' | |: :' | | ; | .' / ");
+console.log("`---' / ;--,' | .; :| | : `---' / ;--, ");
+console.log(" / / / .`|| : |' : |__ / / / .`| ");
+console.log("./__; .' \ \ / | | '.'|./__; .' ");
+console.log("; | .' `----' ; : ;; | .' ");
+console.log("`---' | , / `---' ");
+console.log(" ---`-' ");
+console.log("==============================================");
diff --git a/zoizbot/commandhandler.js b/zoizbot/commandhandler.js
new file mode 100644
index 0000000..8127546
--- /dev/null
+++ b/zoizbot/commandhandler.js
@@ -0,0 +1,25 @@
+zoizbot.on("ready", () => {
+ zoizbot.user.setActivity(config.activity); // change this to whatever you want (in conf.json).
+ console.log(`Zoizbot has started, and is serving ${zoizbot.users.cache.size} users, in ${zoizbot.guilds.cache.size} guilds.`); // you can display anything you want here, all the functions are available in de documentation from discord.js
+ console.log("==================LISTENING===================");
+});
+
+zoizbot.on("guildJoin", guild => {
+ console.log(`I have joined ${guild.name}, I will be serving ${guild.memberCount} members!`); // Join server message in the console
+ message.channel.send(`Hello ${guild.name} thank you for having me!`);
+});
+
+zoizbot.on("guildLeave", guild => {
+ console.log(`Adios! i will be leaving: ${guild.name}, it was fun while it lasted!`); //letting you know he be headin out
+});
+
+zoizbot.on("message", async message => {
+ if (message.author.bot) return; //ignore bots
+ if (message.content.indexOf(config.prefix) !== 0) return; // dont waste time listening to non prefix commands
+ const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
+ const command = args.shift().toLowerCase(); // slice and dice && lowercase
+ const cmd = zoizbot.commands.get(command);
+ if (!cmd) return; //if the command doesnt exist gracefully return
+
+ cmd.run(zoizbot, message, args); // and fire!
+});
\ No newline at end of file
diff --git a/zoizbot/commands/examples.js b/zoizbot/commands/examples.js
deleted file mode 100644
index 8f38e8a..0000000
--- a/zoizbot/commands/examples.js
+++ /dev/null
@@ -1,78 +0,0 @@
-
-zoizbot.on("message", async message => {
-
- if (message.author.bot) return; // dont listen to other bots
- if (!message.content.startsWith(config.prefix)) return; // dont waste time listening to non prefix messages
-
- const args = message.content.slice(config.prefix.length).trim().split(/ +/g); // cut the arguments away from the command.
- const command = args.shift().toLowerCase();
-
-
- //ping pong, example from documentation
- if (command === "ping") {
- const m = await message.channel.send("Ping?");
- m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(zoizbot.ws.ping)}ms`);
- }
-
- //simple kick command
- if (command === "kick") {
- //if (!message.member.roles.cache.some(r => ["Administrator", "Moderator"].includes(r.name))) checks the roles for permissions
- 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(' '); // slicing 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}`);
-
- }
-
- //simple ban command
-
- if (command === "ban") {
- 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 (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}`)
- }
-
- //simple purge example command
-
- if (command === "purge") {
- const deleteCount = parseInt(args[0], 10);
-
- if (!deleteCount || deleteCount < 2 || deleteCount > 100)
- return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");
-
- const fetched = await message.channel.messages.fetch({ limit: deleteCount });
- message.channel.bulkDelete(fetched)
- .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
- }
-
- else return
-});
-
-
-
-
diff --git a/zoizbot/commands/hello.js b/zoizbot/commands/hello.js
new file mode 100644
index 0000000..e401544
--- /dev/null
+++ b/zoizbot/commands/hello.js
@@ -0,0 +1,12 @@
+/*
+ * Message example. When you >hello it will say hello to you
+ * Added the reply so you dont have to get the member declaration but let the "discord.js" handle it
+ * Check out readme for more information
+ * catching errors is indeed the preferred way of debugging your commands. Nodejs is terrible in debugging
+ * make sure you use a decent IDE
+ *
+ */
+exports.run = (zoizbot, message, args) => {
+ message.channel.send("Hello!").catch(console.error);
+ message.reply("Thank you for waking me up, i nearly fell asleep :)");
+}
\ No newline at end of file
diff --git a/zoizbot/commands/ping.js b/zoizbot/commands/ping.js
new file mode 100644
index 0000000..5701efd
--- /dev/null
+++ b/zoizbot/commands/ping.js
@@ -0,0 +1,6 @@
+// ping pong example from the documentation with async await
+// make all the calculations you want and change the message
+exports.run = async(zoizbot, message, args) => {
+ const m = await message.channel.send("Ping?");
+ m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(zoizbot.ws.ping)}ms`);
+}
\ No newline at end of file
diff --git a/zoizbot/zoizbot.njsproj b/zoizbot/zoizbot.njsproj
index 1b05c06..6c184bb 100644
--- a/zoizbot/zoizbot.njsproj
+++ b/zoizbot/zoizbot.njsproj
@@ -36,14 +36,25 @@
Code
-
+
Code
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+