diff --git a/.gitignore b/.gitignore index cfd538a..9b51d74 100644 --- a/.gitignore +++ b/.gitignore @@ -112,4 +112,7 @@ src/config/Config.json PrivateConfig.json # Ignore dockerfiles -docker-compose.yml \ No newline at end of file +docker-compose.yml + +.vscode/ +node_modules/ \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..95f5a1e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,59 @@ +{ + "name": "sebi-machine", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" + }, + "discord.js": { + "version": "11.3.2", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-11.3.2.tgz", + "integrity": "sha512-Abw9CTMX3Jb47IeRffqx2VNSnXl/OsTdQzhvbw/JnqCyqc2imAocc7pX2HoRmgKd8CgSqsjBFBneusz/E16e6A==", + "requires": { + "long": "^4.0.0", + "prism-media": "^0.0.2", + "snekfetch": "^3.6.4", + "tweetnacl": "^1.0.0", + "ws": "^4.0.0" + } + }, + "long": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", + "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" + }, + "prism-media": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.2.tgz", + "integrity": "sha512-L6yc8P5NVG35ivzvfI7bcTYzqFV+K8gTfX9YaJbmIFfMXTs71RMnAupvTQPTCteGsiOy9QcNLkQyWjAafY/hCQ==" + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "snekfetch": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz", + "integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw==" + }, + "tweetnacl": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz", + "integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins=" + }, + "ws": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz", + "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==", + "requires": { + "async-limiter": "~1.0.0", + "safe-buffer": "~5.1.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..a286aaa --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "sebi-machine", + "version": "1.0.0", + "description": "Dedicated Discord bot for [Sebi's bot tutorial](http://discord.gg/GWdhBSp).", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/dustinpianalto/Sebi-Machine.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/dustinpianalto/Sebi-Machine/issues" + }, + "homepage": "https://github.com/dustinpianalto/Sebi-Machine#readme", + "dependencies": { + "discord.js": "^11.3.2" + } +} diff --git a/src/cogs/sar.js b/src/cogs/sar.js new file mode 100644 index 0000000..4d158cb --- /dev/null +++ b/src/cogs/sar.js @@ -0,0 +1,66 @@ +const Discord = require("discord.js"); + +exports.run = async function(client, message, args) { + + /* + aliases: sar, selfrole, selfroles + + examples: + - S!selfrole get 1 (adds heroku helper role) + - S!sar remove 3 (removes rewrite helper role) + - S!sar list (shows all roles) + */ + + function roleFinder(query) { + return message.guild.roles.find(function(r) { + return r.name.includes(query) + }).id; + } + + const type = args[0]; // can be get, remove or list + + if (type == "list") { + + const embed = new Discord.RichEmbed() + .setTitle("List of Self Assigned Roles") + .setDescription("Usage: `S!sar [ get | remove | list ] [ number ]`") + .addField("1. Heroku Helper", "S!sar get 2", true) + .addField("2. JS Helper", "S!sar get 3", true) + .addField("3. Rewrite Helper", "S!sar get 4", true); + + return message.channel.send({ + embed: embed + }); + + } + + const roles = [roleFinder("Heroku"), roleFinder("JS"), roleFinder("Rewrite")]; + + let choice = args[1]; // can be 1, 2 or 3 + + // if the choice is not 1, 2 or 3 + if (/^[123]$/.test(choice) == false) { + return message.channel.send("Enter a valid role number!"); // returns error message + } else { + choice -= 1; // because array indexing starts from 0. when they choose 1 it should be roles[0] + } + + switch (type) { + + case "get": + message.member.addRole(roles[choice]); + break; + + case "remove": + message.member.removeRole(roles[choice]); + break; + + default: + return; // when it is neither get nor remove + break; + + } + + message.channel.send("Added the role you wanted!"); // confirmation message + +} \ No newline at end of file diff --git a/src/run.js b/src/run.js new file mode 100644 index 0000000..d949397 --- /dev/null +++ b/src/run.js @@ -0,0 +1,47 @@ +const Discord = require("discord.js"); +const client = new Discord.Client(); + +const config = require("./config/Config.json"); +const prefix = config.prefix; + +const aliases = require("./shared_libs/aliases.json"); +const privateConfig = require("./config/PrivateConfig.json"); + +const fs = require("fs"); +const commands = fs.readdirSync("./cogs").filter(function(e) { + return e.endsWith(".js"); +}); + + +client.on("message", function(message) { + + if (message.guild.id != "265828729970753537") { + return; + } + + if (message.content.startsWith(config.prefix) == false) { + return; + } + + const msg = message.content.replace(prefix, ""); + + let command = msg.split(" ")[0]; + const args = msg.split(" ").slice(1); + + command = aliases[command]; + + try { + + if (commands.includes(`${command}.js`)) { + require(`./cogs/${command}.js`).run(client, message, args); + } + + } catch (err) { + + // handling errors + + } + +}); + +client.login(privateConfig["bot-key"]); \ No newline at end of file