diff options
| author | Alee <alee14498@gmail.com> | 2018-04-20 17:49:37 -0400 |
|---|---|---|
| committer | Alee <alee14498@gmail.com> | 2018-04-20 17:49:37 -0400 |
| commit | c4ef0d5d72dd47b76e39fa91a7552c19c8120ad8 (patch) | |
| tree | 6077983d7e178343f841b3eb5b95b66f70b563bf | |
| parent | 325f2ee581cd96d1d1812e95812bb6ea9f9606bc (diff) | |
| download | Oswald-master.tar.gz Oswald-master.tar.bz2 Oswald-master.zip | |
| -rw-r--r-- | bot.js | 92 | ||||
| -rw-r--r-- | commands/avatarurl.js | 14 | ||||
| -rw-r--r-- | commands/git.js | 14 | ||||
| -rw-r--r-- | commands/help.js | 41 | ||||
| -rw-r--r-- | commands/ping.js | 14 | ||||
| -rw-r--r-- | package-lock.json | 5 | ||||
| -rw-r--r-- | package.json | 3 |
7 files changed, 137 insertions, 46 deletions
@@ -18,12 +18,38 @@ * * *************************************/ const Discord = require('discord.js'); +const fs = require('fs'); const client = new Discord.Client(); const config = require('./config.json'); var prefix = "oswald:"; var version = "1.0.0"; +client.commands = new Discord.Collection(); +client.aliases = new Discord.Collection(); + +fs.readdir('./commands', (err, files) => { + if (err) console.error(err); + console.log(`[!] Attempting to load a total of ${files.length} commands into the memory.`); + files.forEach(file => { + try { + const command = require(`./commands/${file}`); + console.log(`[!] Attempting to load the command "${command.help.name}".`); + client.commands.set(command.help.name, command); + command.conf.aliases.forEach(alias => { + client.aliases.set(alias, command.help.name); + console.log(`[!] Attempting to load "${alias}" as an alias for "${command.help.name}"`); + }); + } + catch (err) { + console.log('[X] An error has occured trying to load a command. Here is the error.'); + console.log(err.stack); + } + }); + console.log('[>] Command Loading complete!'); + console.log('\n'); +}); + client.on('ready', () => { console.log("[SUCCESS] Oswald is now ready! Running version "+ version +"!"); client.user.setStatus('online') @@ -54,35 +80,30 @@ client.on("message", function(message){ if (message.channel.type === "dm") return; if (!message.content.startsWith(prefix)) return; + const args = message.content.slice(prefix.length).trim().split(/ +/g); + const command = args.shift(); + let cmd; - let command = message.content.split(" ")[0]; - command = command.slice(prefix.length); - - let args = message.content.split(" ").slice(1); - - if (command === 'help'){ - var embed = new Discord.RichEmbed() - .setTitle(`Commands for Oswald ` + version + `.`) - .setDescription('Every command you put in this bot must start with `'+ prefix + '`') - .addField('Fun Stuff:', 'attack\nask\nship',true) - .addField('Moderation', 'ban\nkick',true) - .addField('Link:', 'git',true) - .addField('Owner Only:', 'say',true) - .addField('Monitor:', 'ping\nuptime',true) - .addField('Etc:', 'avatarurl', true) - .setFooter("Oswald "+ version +" Copyright 2018. Created by Alee14", "https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048") - .setColor("#7af442") - message.channel.send({embed}); + if (client.commands.has(command)) { + cmd = client.commands.get(command); + } else if (client.aliases.has(command)) { + cmd = client.commands.get(client.aliases.get(command)); + } + if (cmd) { + if (cmd.conf.guildOnly == true) { + if (!message.channel.guild) { + return message.channel.createMessage('This command can only be ran in a guild.'); + } } - - if(command === 'avatarurl'){ - message.reply(message.author.avatarURL); + try { + cmd.run(client, message, args); } - - if(command === 'git'){ - message.channel.send ("Here's the github repo: https://github.com/Alee14/Oswald/"); - } + catch (e) { + console.error(e); + } + } +/* if(command === 'ping'){ message.reply("**PONG!** :ping_pong: " + Math.round(client.ping) + " ms"); @@ -128,18 +149,6 @@ client.on("message", function(message){ commandProcessed = true; } - if(command === 'attack'){ - //This command was ported from AstralMod - if (command.indexOf("@everyone") == -1) { - if (command.indexOf("@here") == -1) { - message.channel.send("<@" + message.author.id + "> :right_facing_fist: " + args); - } else { - message.reply("Nice try, but I ain't going to interrupt everyone who is online at this time. Kinda nice to not be bothered."); - } - } else { - message.reply("Nice try, but I ain't going to interrupt everyone. Kinda nice to not be bothered."); - } - } if(command === 'ask'){ var abaskanswer = [ "Yes.", @@ -190,16 +199,9 @@ commandProcessed = true; message.reply(`**${member.user.tag}** has been kicked for the reason: \n\`\`\`${mreason}.\`\`\`\n`); } - +*/ }); -const clean = text => { - if (typeof(text) === "string") - return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203)); - else - return text; -} - process.on('unhandledRejection', function(err, p) { console.log("[ERROR | UNCAUGHT PROMISE] " + err.stack); }); diff --git a/commands/avatarurl.js b/commands/avatarurl.js new file mode 100644 index 0000000..fce4e00 --- /dev/null +++ b/commands/avatarurl.js @@ -0,0 +1,14 @@ +module.exports.run = async (client, message) => { + message.reply(message.author.avatarURL); +}; + +exports.conf = { + aliases: [], + guildOnly: false, +}; +exports.help = { + name: 'avatarurl', + description: 'Displays your avatar.', + usage: 'avatarurl', + category: '- General Commands', +}; diff --git a/commands/git.js b/commands/git.js new file mode 100644 index 0000000..8f9f18a --- /dev/null +++ b/commands/git.js @@ -0,0 +1,14 @@ +module.exports.run = async (client, message) => { + message.channel.send ("Here's the github repo: https://github.com/Alee14/Oswald/"); +}; + +exports.conf = { + aliases: [], + guildOnly: false, +}; +exports.help = { + name: 'git', + description: 'Shows the repo of Oswald.', + usage: 'git', + category: '- General Commands', +};
\ No newline at end of file diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..bc9c385 --- /dev/null +++ b/commands/help.js @@ -0,0 +1,41 @@ +const Discord = require('discord.js'); +const fs = require('fs'); +module.exports.run = async (client, message) => { + const categories = []; + const commands = Array.from(client.commands.keys()); + + commands.forEach(function(x) { + if (!categories.includes(client.commands.get(x).help.category)) { + categories.push(client.commands.get(x).help.category); + } + }); + + const embed = new Discord.RichEmbed() + .setAuthor(`Oswald Help and on ${client.guilds.size} servers`, client.avatarURL) + .setDescription('Every command you input into AleeBot is `oswald:`') + .setColor('#1fd619') + .setFooter('Alee14 Copyright 2018, Licensed with GPL-3.0'); + + categories.forEach(function(x) { + let cat = ''; + commands.forEach(function(command) { + if (client.commands.get(command).help.category == x) { + cat = cat + command + '\n'; + } + }); + embed.addField(x, cat, true); + }); + + await message.channel.send({ embed }); +}; + +exports.conf = { + aliases: ['h'], + guildOnly: false, +}; +exports.help = { + name: 'help', + description: 'Displays all the commands or a page with information for 1 command.', + usage: 'help (command:command-name)', + category: '- General Commands', +}; diff --git a/commands/ping.js b/commands/ping.js new file mode 100644 index 0000000..5ad82fd --- /dev/null +++ b/commands/ping.js @@ -0,0 +1,14 @@ +module.exports.run = async (client, message) => { + message.reply('**PONG!** :ping_pong: ' + Math.round(client.ping) + ' ms'); +}; + +exports.conf = { + aliases: [], + guildOnly: false, +}; +exports.help = { + name: 'ping', + description: 'Displays the ping of the bot.', + usage: 'ping', + category: '- General Commands', +}; diff --git a/package-lock.json b/package-lock.json index 0742b95..c21f717 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,11 @@ "ws": "4.1.0" } }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, "long": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", diff --git a/package.json b/package.json index ecf4b9b..84be904 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "author": "", "license": "GPL-3.0", "dependencies": { - "discord.js": "^11.3.2" + "discord.js": "^11.3.2", + "fs": "0.0.1-security" } } |
