From 31e4750ba6f8c9840e9580c6f19b7ca9c9aab164 Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Sun, 19 Jul 2020 11:56:03 +0200 Subject: [PATCH 01/10] some folder cleaning and bug fix --- index.js | 66 ++++++++++++------- package.json | 3 + .../database}/abstractInstance.js | 0 {database => src/database}/bot.js | 0 {database => src/database}/user.js | 0 database.js => src/utils/database.js | 52 ++------------- src/utils/utils.js | 15 +++++ 7 files changed, 63 insertions(+), 73 deletions(-) rename {database => src/database}/abstractInstance.js (100%) rename {database => src/database}/bot.js (100%) rename {database => src/database}/user.js (100%) rename database.js => src/utils/database.js (54%) create mode 100644 src/utils/utils.js diff --git a/index.js b/index.js index 4f02c42..551ca8d 100644 --- a/index.js +++ b/index.js @@ -2,43 +2,59 @@ const Discord = require("discord.js") const client = new Discord.Client() + const utils = require("./src/utils/utils") + client.on("message", async msg => { - if (msg.author.bot) { + if (msg.author.bot || msg.guild === undefined) { return } - global.database.userInstance.get(msg.author.id).then(async user => { - let prom = 1 - if(!user) { - prom = global.database.userInstance.create(msg.author) - user = {messageCount: 0} - } - await prom - - global.database.userInstance.update(msg.author, {messageCount: user.messageCount + 1}) + await new Promise(resolve => { + global.database.userInstance.get(msg.author.id).then(async user => { + if(!user) { + await global.database.userInstance.create(msg.author) + } + resolve() + }) }) msg.content = msg.content.trim() - if (msg.content.startsWith("<@!727636604692332616>") || msg.content.startsWith("<@727636604692332616>")) { - if (msg.author.id !== "439790095122300928" && msg.author.id !== "367078598399492107") { - return - } - - global.database.userInstance.gets().then(users => { - msg.channel.send( - users.map(user => ({user: msg.guild.members.resolve(user.discordId), messageCount: user.messageCount})) - .map(user => `${user.user.user.username}: ${user.messageCount}`) - .join`\n` - ) - }) - } + if (msg.content.startsWith(`<@!${utils.ids.bot}>`) || msg.content.startsWith(`<@${utils.ids.bot}>`)) { + const split = msg.content.split(" ") + if (split.length === 1) { + return msg.channel.send(`You need to specify a command, there is no list available yet, please ask jonatjano for help`) + // return msg.channel.send(`You need to specify a command, type "<@${utils.ids.bot}> help" to see the command list`) + } + let command + try { + command = require(`./src/commands/${split[1]}`) + } catch (ex) { + console.log(ex) + return msg.channel.send(`Sorry, the command \`${split[1]}\` doesn't exists`) + } + + let depth = 2 + while(depth < split.length && typeof command[split[depth]] === "function") { + command = command[split[depth++]] + } + + if (typeof command.hasPermission === "undefined" || command.hasPermission(msg)) { + return command(msg, ...split.slice(depth)) + } else { + return msg.channel.send("You don't have required the roles to use this command") + } + } else { + global.database.userInstance.get(msg.author.id).then(user => { + global.database.userInstance.update(msg.author, {messageCount: user.messageCount + 1}) + }) + } }) await client.login("NzI3NjM2NjA0NjkyMzMyNjE2.XvuubQ.O14MrObhsIPFphHmhsEjoGdDXZ8").then(() => {console.log("bot connected")}) global.client = client - global.guild = client.guilds.resolve("725032845206224968") + global.guild = client.guilds.resolve(utils.ids.guild) - global.database = require("./database") + global.database = require("./src/utils/database") global.database.init() })() diff --git a/package.json b/package.json index a882a08..b947d12 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "1.0.0", "main": "index.js", "license": "MIT", + "scripts": { + "start": "node index.js" + }, "dependencies": { "discord.js": "^12.2.0", "sqlite-async": "^1.1.0" diff --git a/database/abstractInstance.js b/src/database/abstractInstance.js similarity index 100% rename from database/abstractInstance.js rename to src/database/abstractInstance.js diff --git a/database/bot.js b/src/database/bot.js similarity index 100% rename from database/bot.js rename to src/database/bot.js diff --git a/database/user.js b/src/database/user.js similarity index 100% rename from database/user.js rename to src/database/user.js diff --git a/database.js b/src/utils/database.js similarity index 54% rename from database.js rename to src/utils/database.js index 8fc09cf..061caa8 100644 --- a/database.js +++ b/src/utils/database.js @@ -1,7 +1,7 @@ const fs = require("fs") -const DEFAULT_DB_FILE = __dirname + "/db.db" +const DEFAULT_DB_FILE = __dirname + "/../../db.db" const sqlite3 = require('sqlite-async') -const BotInstance = require("./database/bot") +const BotInstance = require("../database/bot") class Database { async init(dbFile = DEFAULT_DB_FILE) { @@ -27,10 +27,10 @@ class Database { } }) - const updates = fs.readdirSync(__dirname + "/database/") + const updates = fs.readdirSync(__dirname + "/../database/") .filter(filename => filename !== "abstractInstance.js" && filename !== "bot.js" && filename.endsWith(".js")) .map(filename => filename.substr(0, filename.length - 3)) - .map(filenameNoExt => ({filenameNoExt, instanceClass: require(__dirname + "/database/" + filenameNoExt)})) + .map(filenameNoExt => ({filenameNoExt, instanceClass: require(__dirname + "/../database/" + filenameNoExt)})) .map(InstanceInfos => { const Instance = new InstanceInfos.instanceClass(this.db) this[InstanceInfos.filenameNoExt + "Instance"] = Instance @@ -60,50 +60,6 @@ class Database { console.log("No database update required") } }) - - /* - this.db.get("SELECT version FROM Bot", async (err, row) => { - if (!err) { - const {version} = row - let newVersion = version - - Object.entries(this.botInstance.updates).forEach(entry => { - if (+entry[0] > version) { - entry[1]() - newVersion = Math.max(newVersion, +entry[0]) - } - }) - */ - /* - const updates = fs.readdirSync(__dirname + "/../database/") - .filter(filename => filename !== "abstractInstance.js" && filename !== "bot.js" && filename.endsWith(".js")) - .map(filename => filename.substr(0, filename.length - 3)) - .map(filenameNoExt => ({filenameNoExt, instanceClass: require(__dirname + "/../database/" + filenameNoExt)})) - .map(InstanceInfos => { - const Instance = new InstanceInfos.instanceClass(this.db) - this[InstanceInfos.filenameNoExt + "Instance"] = Instance - return Instance - }) - .map(instance => instance.updates) - */ - - // console.log(updates) - // do upgrade for all file in ./database - // set newVersion to max found - /* - if (newVersion !== version) { - this.db.run("UPDATE bot set version = ?", newVersion, error => { - if (!error) { - console.log("Successfully updated database") - } - }) - } else { - console.log("No database update required") - } - } else { - } - }) - */ } } diff --git a/src/utils/utils.js b/src/utils/utils.js new file mode 100644 index 0000000..913aed7 --- /dev/null +++ b/src/utils/utils.js @@ -0,0 +1,15 @@ +const utils = {} + +utils.ids = { + guild: "725032845206224968", + bot: "727636604692332616", + roles: { + moderator: "726886455447781538", + gameDirector: "726140729398657136", + teamLead: "726140349680058439" + } +} + + + +module.exports = utils -- GitLab From d80c7433a49c5def6474f3bcf8d02059e2d74575 Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Wed, 22 Jul 2020 21:39:14 +0200 Subject: [PATCH 02/10] some perm things --- index.js | 1 - src/commands/poll.js | 12 ++++++++++++ src/commands/stats.js | 17 +++++++++++++++++ src/utils/utils.js | 11 +++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/commands/poll.js create mode 100644 src/commands/stats.js diff --git a/index.js b/index.js index 551ca8d..8de1da3 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,6 @@ try { command = require(`./src/commands/${split[1]}`) } catch (ex) { - console.log(ex) return msg.channel.send(`Sorry, the command \`${split[1]}\` doesn't exists`) } diff --git a/src/commands/poll.js b/src/commands/poll.js new file mode 100644 index 0000000..599bc67 --- /dev/null +++ b/src/commands/poll.js @@ -0,0 +1,12 @@ +const {commonPerm} = require("../utils/utils") + +function func(msg, args) { + msg.channel.send("Hello, poll !") +} +func.hasPermission = commonPerm.teamLeadUp + +func.create = (msg, args) => { + +} + +module.exports = func diff --git a/src/commands/stats.js b/src/commands/stats.js new file mode 100644 index 0000000..480d002 --- /dev/null +++ b/src/commands/stats.js @@ -0,0 +1,17 @@ +function func(msg) { + // return msg.channel.send("This command is temporaly disabled") + global.database.userInstance.gets().then(users => { + msg.channel.send( + users.map(user => ({user: msg.guild.members.resolve(user.discordId), messageCount: user.messageCount})) + .filter(user => user.user) + .map(user => `${user.user.user.username}: ${user.messageCount}`) + .join`\n` + ) + }) +} + +func.ping = (msg) => { + msg.channel.send("pong") +} + +module.exports = func diff --git a/src/utils/utils.js b/src/utils/utils.js index 913aed7..1454bf1 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,5 +1,9 @@ const utils = {} +utils.discordLimits = { + reactionPerMessage: 20 +} + utils.ids = { guild: "725032845206224968", bot: "727636604692332616", @@ -10,6 +14,13 @@ utils.ids = { } } +utils.commonPerm = { + moderator: msg => msg.member.roles.cache.find(role => role.id === utils.ids.roles.moderator), + gameDirector: msg => msg.member.roles.cache.find(role => role.id === utils.ids.roles.gameDirector), + teamLead: msg => msg.member.roles.cache.find(role => role.id === utils.ids.roles.teamLead) +} +utils.commonPerm.gameDirectorUp = msg => utils.commonPerm.gameDirector(msg) || utils.commonPerm.moderator(msg) +utils.commonPerm.teamLeadUp = msg => utils.commonPerm.teamLead(msg) || utils.commonPerm.gameDirectorUp(msg) module.exports = utils -- GitLab From 0d784ca14364bdb7575404cb83729752dd3d678c Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Wed, 22 Jul 2020 22:15:16 +0200 Subject: [PATCH 03/10] successfully moved to eris --- index.js | 66 ++++++--------------------- package.json | 2 +- src/commands/poll.js | 16 ++----- src/commands/stats.js | 17 ------- yarn.lock | 103 +++++++----------------------------------- 5 files changed, 38 insertions(+), 166 deletions(-) delete mode 100644 src/commands/stats.js diff --git a/index.js b/index.js index 8de1da3..6b62018 100644 --- a/index.js +++ b/index.js @@ -1,59 +1,23 @@ ;(async function() { - const Discord = require("discord.js") - const client = new Discord.Client() + const fs = require("fs") + const Eris = require("eris") + const {ids: {guild: skateboardServerId}} = require("./src/utils/utils") - const utils = require("./src/utils/utils") - - client.on("message", async msg => { - if (msg.author.bot || msg.guild === undefined) { - return - } - - await new Promise(resolve => { - global.database.userInstance.get(msg.author.id).then(async user => { - if(!user) { - await global.database.userInstance.create(msg.author) - } - resolve() - }) - }) - - msg.content = msg.content.trim() - if (msg.content.startsWith(`<@!${utils.ids.bot}>`) || msg.content.startsWith(`<@${utils.ids.bot}>`)) { - const split = msg.content.split(" ") - if (split.length === 1) { - return msg.channel.send(`You need to specify a command, there is no list available yet, please ask jonatjano for help`) - // return msg.channel.send(`You need to specify a command, type "<@${utils.ids.bot}> help" to see the command list`) - } - let command - try { - command = require(`./src/commands/${split[1]}`) - } catch (ex) { - return msg.channel.send(`Sorry, the command \`${split[1]}\` doesn't exists`) - } - - let depth = 2 - while(depth < split.length && typeof command[split[depth]] === "function") { - command = command[split[depth++]] - } - - if (typeof command.hasPermission === "undefined" || command.hasPermission(msg)) { - return command(msg, ...split.slice(depth)) - } else { - return msg.channel.send("You don't have required the roles to use this command") - } - } else { - global.database.userInstance.get(msg.author.id).then(user => { - global.database.userInstance.update(msg.author, {messageCount: user.messageCount + 1}) - }) - } + const bot = new Eris.CommandClient("NzI3NjM2NjA0NjkyMzMyNjE2.XvuubQ.O14MrObhsIPFphHmhsEjoGdDXZ8", {}, { + description: "Skateboard Project admin helper", + owner: "Skateboard Project" }) - await client.login("NzI3NjM2NjA0NjkyMzMyNjE2.XvuubQ.O14MrObhsIPFphHmhsEjoGdDXZ8").then(() => {console.log("bot connected")}) + fs.readdirSync(__dirname + "/src/commands/") + .filter(filename => filename.endsWith(".js")) + .map(filename => filename.substr(0, filename.length - 3)) + .map(filenameNoExt => require(__dirname + "/src/commands/" + filenameNoExt)) + .forEach(file => file(bot)) - global.client = client - global.guild = client.guilds.resolve(utils.ids.guild) + bot.on("ready", () => console.log("Bot connected")) global.database = require("./src/utils/database") - global.database.init() + await global.database.init() + + bot.connect() })() diff --git a/package.json b/package.json index b947d12..7333314 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "node index.js" }, "dependencies": { - "discord.js": "^12.2.0", + "eris": "^0.13.3", "sqlite-async": "^1.1.0" } } diff --git a/src/commands/poll.js b/src/commands/poll.js index 599bc67..c73a10a 100644 --- a/src/commands/poll.js +++ b/src/commands/poll.js @@ -1,12 +1,6 @@ -const {commonPerm} = require("../utils/utils") - -function func(msg, args) { - msg.channel.send("Hello, poll !") +module.exports = bot => { + bot.registerCommand("poll", "POLLS !!!", { + description: "Manage polls", + fullDescription: "This command can be used to manage polls." + }); } -func.hasPermission = commonPerm.teamLeadUp - -func.create = (msg, args) => { - -} - -module.exports = func diff --git a/src/commands/stats.js b/src/commands/stats.js deleted file mode 100644 index 480d002..0000000 --- a/src/commands/stats.js +++ /dev/null @@ -1,17 +0,0 @@ -function func(msg) { - // return msg.channel.send("This command is temporaly disabled") - global.database.userInstance.gets().then(users => { - msg.channel.send( - users.map(user => ({user: msg.guild.members.resolve(user.discordId), messageCount: user.messageCount})) - .filter(user => user.user) - .map(user => `${user.user.user.username}: ${user.messageCount}`) - .join`\n` - ) - }) -} - -func.ping = (msg) => { - msg.channel.send("pong") -} - -module.exports = func diff --git a/yarn.lock b/yarn.lock index 66ce0b5..b7ab698 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,32 +2,11 @@ # yarn lockfile v1 -"@discordjs/collection@^0.1.5": - version "0.1.5" - resolved "https://registry.yarnpkg.com/@discordjs/collection/-/collection-0.1.5.tgz#1781c620b4c88d619bd0373a1548e5a6025e3d3a" - integrity sha512-CU1q0UXQUpFNzNB7gufgoisDHP7n+T3tkqTsp3MNUkVJ5+hS3BCvME8uCXAUFlz+6T2FbTCu75A+yQ7HMKqRKw== - -"@discordjs/form-data@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@discordjs/form-data/-/form-data-3.0.1.tgz#5c9e6be992e2e57d0dfa0e39979a850225fb4697" - integrity sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg== - dependencies: - asynckit "^0.4.0" - combined-stream "^1.0.8" - mime-types "^2.1.12" - abbrev@1: version "1.1.1" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== -abort-controller@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" - integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== - dependencies: - event-target-shim "^5.0.0" - ansi-regex@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" @@ -51,11 +30,6 @@ are-we-there-yet@~1.1.2: delegates "^1.0.0" readable-stream "^2.0.6" -asynckit@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" - integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= - balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -79,13 +53,6 @@ code-point-at@^1.0.0: resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= -combined-stream@^1.0.8: - version "1.0.8" - resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" - integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== - dependencies: - delayed-stream "~1.0.0" - concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -113,11 +80,6 @@ deep-extend@^0.6.0: resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== -delayed-stream@~1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" - integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= - delegates@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" @@ -128,24 +90,15 @@ detect-libc@^1.0.2: resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= -discord.js@^12.2.0: - version "12.2.0" - resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.2.0.tgz#31018732e42a495c92655055192221eab2ad11a9" - integrity sha512-Ueb/0SOsxXyqwvwFYFe0msMrGqH1OMqpp2Dpbplnlr4MzcRrFWwsBM9gKNZXPVBHWUKiQkwU8AihXBXIvTTSvg== - dependencies: - "@discordjs/collection" "^0.1.5" - "@discordjs/form-data" "^3.0.1" - abort-controller "^3.0.0" - node-fetch "^2.6.0" - prism-media "^1.2.0" - setimmediate "^1.0.5" - tweetnacl "^1.0.3" +eris@^0.13.3: + version "0.13.3" + resolved "https://registry.yarnpkg.com/eris/-/eris-0.13.3.tgz#22abb71f9ce0d453200b537cad457dc39c7b302b" + integrity sha512-WBtLyknOWZpYZL9yPhez0oKUWvYpunSg43hGxawwjwSf3gFXmbEPYrT8KlmZXtpJnX16eQ7mzIq+MgSh3LarEg== + dependencies: ws "^7.2.1" - -event-target-shim@^5.0.0: - version "5.0.1" - resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" - integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== + optionalDependencies: + opusscript "^0.0.7" + tweetnacl "^1.0.1" fs-minipass@^1.2.5: version "1.2.7" @@ -239,18 +192,6 @@ isarray@~1.0.0: resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= -mime-db@1.44.0: - version "1.44.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92" - integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg== - -mime-types@^2.1.12: - version "2.1.27" - resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f" - integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w== - dependencies: - mime-db "1.44.0" - minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -304,11 +245,6 @@ needle@^2.2.1: iconv-lite "^0.4.4" sax "^1.2.4" -node-fetch@^2.6.0: - version "2.6.0" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" - integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA== - node-pre-gyp@^0.11.0: version "0.11.0" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.11.0.tgz#db1f33215272f692cd38f03238e3e9b47c5dd054" @@ -381,6 +317,11 @@ once@^1.3.0: dependencies: wrappy "1" +opusscript@^0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/opusscript/-/opusscript-0.0.7.tgz#7dd7ec55b302d26bf588e6fc3feb090b8c7da856" + integrity sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg== + os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" @@ -404,11 +345,6 @@ path-is-absolute@^1.0.0: resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= -prism-media@^1.2.0: - version "1.2.2" - resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-1.2.2.tgz#4f1c841f248b67d325a24b4e6b1a491b8f50a24f" - integrity sha512-I+nkWY212lJ500jLe4tN9tWO7nRiBAVdMv76P9kffZjYhw20raMlW1HSSvS+MLXC9MmbNZCazMrAr+5jEEgTuw== - process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" @@ -474,11 +410,6 @@ set-blocking@~2.0.0: resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= -setimmediate@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" - integrity sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU= - signal-exit@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" @@ -555,7 +486,7 @@ tar@^4: safe-buffer "^5.1.2" yallist "^3.0.3" -tweetnacl@^1.0.3: +tweetnacl@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== @@ -578,9 +509,9 @@ wrappy@1: integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= ws@^7.2.1: - version "7.3.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.0.tgz#4b2f7f219b3d3737bc1a2fbf145d825b94d38ffd" - integrity sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w== + version "7.3.1" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8" + integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== yallist@^3.0.0, yallist@^3.0.3: version "3.1.1" -- GitLab From 493b05eeef2410c90256a0f172683decbeeddda9 Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Thu, 23 Jul 2020 13:32:40 +0200 Subject: [PATCH 04/10] created `channel` and `channel info` commands --- src/commands/channel.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/commands/channel.js diff --git a/src/commands/channel.js b/src/commands/channel.js new file mode 100644 index 0000000..5e1775e --- /dev/null +++ b/src/commands/channel.js @@ -0,0 +1,38 @@ +const channelInfos = msg => { + return { + embed: { + title: "Channel infos", + type: "rich", + fields: [ + {name: "channel name", value: msg.channel.name, inline: true}, + {name: "mention", value: msg.channel.mention, inline: true}, + {name: "topic", value: msg.channel.topic && msg.channel.topic.length ? msg.channel.topic : "no topic set", inline: false}, + {name: "is nsfw", value: msg.channel.nsfw, inline: true}, + { + name: "type", + value: (()=>{ + switch(msg.channel.type) { + case 0: return "Text channel" + default: return msg.channel.type + } + })(), + inline: true + } + ] + } + } +} + +module.exports = bot => { + const channelCommand = bot.registerCommand("channel", channelInfos, { + description: "Manage channels", + fullDescription: "This command can be used to manage channels.", + deleteCommand: true + }); + channelCommand.registerSubcommand("info", channelInfos, { + aliases: ['infos'], + description: "Give info for current channel", + fullDescription: "This command gives information about the current channel.", + deleteCommand: true + }) +} -- GitLab From f08fce8d509639db8ae24db32d55545c82666db8 Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Fri, 24 Jul 2020 14:21:55 +0200 Subject: [PATCH 05/10] can now create a new channel --- index.js | 1 - src/commands/channel.js | 44 ++++++++++++++++++++++++++++++++++++++--- src/utils/utils.js | 3 +++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6b62018..7add2e2 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ ;(async function() { const fs = require("fs") const Eris = require("eris") - const {ids: {guild: skateboardServerId}} = require("./src/utils/utils") const bot = new Eris.CommandClient("NzI3NjM2NjA0NjkyMzMyNjE2.XvuubQ.O14MrObhsIPFphHmhsEjoGdDXZ8", {}, { description: "Skateboard Project admin helper", diff --git a/src/commands/channel.js b/src/commands/channel.js index 5e1775e..3c27210 100644 --- a/src/commands/channel.js +++ b/src/commands/channel.js @@ -1,3 +1,5 @@ +const utils = require("../utils/utils") + const channelInfos = msg => { return { embed: { @@ -7,32 +9,68 @@ const channelInfos = msg => { {name: "channel name", value: msg.channel.name, inline: true}, {name: "mention", value: msg.channel.mention, inline: true}, {name: "topic", value: msg.channel.topic && msg.channel.topic.length ? msg.channel.topic : "no topic set", inline: false}, - {name: "is nsfw", value: msg.channel.nsfw, inline: true}, { name: "type", value: (()=>{ switch(msg.channel.type) { case 0: return "Text channel" + case 2: return "Voice channel" + case 4: return "Category channel" default: return msg.channel.type } })(), inline: true - } + }, + {name: "is nsfw", value: msg.channel.nsfw, inline: true} ] } } } +const createChannel = (bot, msg, args) => { + if (args.length === 0) { + return "You need to specify a channel name." + } + + const category = utils.getChannel(bot, msg.channel.parentID) + if (category.channels.filter(channel => channel.type === 0).length >= 5) { + return "You can't have more than 5 text channel in a category." + } + + utils.getGuild(bot).createChannel(args.join` `, 0, { + parentID: msg.channel.parentID + }) + .then(() => msg.addReaction("✅")) + .catch(e => { + msg.channel.createMessage(`An error happened, please contact <@${utils.ids.botDev}>: +${e.stack}`) + }) +} + +const deleteChannel = (bot, msg, args) => { + return "WIP" +} + module.exports = bot => { const channelCommand = bot.registerCommand("channel", channelInfos, { description: "Manage channels", fullDescription: "This command can be used to manage channels.", deleteCommand: true - }); + }) channelCommand.registerSubcommand("info", channelInfos, { aliases: ['infos'], description: "Give info for current channel", fullDescription: "This command gives information about the current channel.", deleteCommand: true }) + channelCommand.registerSubcommand("create", (msg, args) => createChannel(bot, msg, args), { + aliases: ['new'], + description: "Create a new channel", + fullDescription: "This command allows leaders to create a new channel in the current category." + }) + channelCommand.registerSubcommand("delete", (msg, args) => deleteChannel(bot, msg, args), { + aliases: ['new'], + description: "Delete current channel ", + fullDescription: "This command allows leader to delete the current channel.\n⚠️️️️️️️️️ this is not reversible ⚠️️️️️️️️️" + }) } diff --git a/src/utils/utils.js b/src/utils/utils.js index 1454bf1..d5392c5 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -7,6 +7,7 @@ utils.discordLimits = { utils.ids = { guild: "725032845206224968", bot: "727636604692332616", + botDev: "439790095122300928", roles: { moderator: "726886455447781538", gameDirector: "726140729398657136", @@ -22,5 +23,7 @@ utils.commonPerm = { utils.commonPerm.gameDirectorUp = msg => utils.commonPerm.gameDirector(msg) || utils.commonPerm.moderator(msg) utils.commonPerm.teamLeadUp = msg => utils.commonPerm.teamLead(msg) || utils.commonPerm.gameDirectorUp(msg) +utils.getGuild = bot => bot.guilds.find(guild => guild.id === utils.ids.guild) +utils.getChannel = (bot, channelId) => utils.getGuild(bot).channels.find(channel => channel.id === channelId) module.exports = utils -- GitLab From 99b79c9dde536ff3caee731b9213547810a16a15 Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Mon, 27 Jul 2020 13:58:07 +0200 Subject: [PATCH 06/10] can now config a name and description of channels --- src/commands/channel.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/commands/channel.js b/src/commands/channel.js index 3c27210..2c86735 100644 --- a/src/commands/channel.js +++ b/src/commands/channel.js @@ -49,6 +49,29 @@ ${e.stack}`) const deleteChannel = (bot, msg, args) => { return "WIP" + /* + Please enter the confirmation number to continue 3437 + */ +} + +const configCommands = { + name: async (bot, msg, args) => { + await msg.channel.edit({name: args.join` `}) + return "Success" + }, + topic: async (bot, msg, args) => { + await msg.channel.edit({topic: args.join` `}) + return "Success" + }, + visibility: async (bot, msg, args) => { + return "WIP" + }, + default: () => { + return getConfigChannelOptionsString() + } +} +function getConfigChannelOptionsString() { + return "Config name is not valid, please use one of `" + Object.getOwnPropertyNames(configCommands).join("`, `") + "`" } module.exports = bot => { @@ -58,19 +81,26 @@ module.exports = bot => { deleteCommand: true }) channelCommand.registerSubcommand("info", channelInfos, { - aliases: ['infos'], + aliases: ["infos", "i"], description: "Give info for current channel", fullDescription: "This command gives information about the current channel.", deleteCommand: true }) channelCommand.registerSubcommand("create", (msg, args) => createChannel(bot, msg, args), { - aliases: ['new'], + aliases: ["new", "mk"], description: "Create a new channel", fullDescription: "This command allows leaders to create a new channel in the current category." }) channelCommand.registerSubcommand("delete", (msg, args) => deleteChannel(bot, msg, args), { - aliases: ['new'], + aliases: ["rm", "remove"], description: "Delete current channel ", fullDescription: "This command allows leader to delete the current channel.\n⚠️️️️️️️️️ this is not reversible ⚠️️️️️️️️️" }) + const configCommand = channelCommand.registerSubcommand("config", (msg, args) => configCommands.default(), { + description: "Configure current channel", + fullDescription: "This command allows leader to configure the current channel.️️️️️️️️️" + }) + configCommand.registerSubcommand("name", (msg, args) => configCommands.name(bot, msg, args)) + configCommand.registerSubcommand("topic", (msg, args) => configCommands.topic(bot, msg, args), {aliases: ["desc", "description"]}) + configCommand.registerSubcommand("visibility", (msg, args) => configCommands.visibility(bot, msg, args), {aliases: ["vis"]}) } -- GitLab From 2884f4df98b05d179fb6a01aba45826604af429a Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Fri, 31 Jul 2020 14:19:09 +0200 Subject: [PATCH 07/10] added dbVersion Command --- src/commands/bot.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/commands/bot.js diff --git a/src/commands/bot.js b/src/commands/bot.js new file mode 100644 index 0000000..1b6f32b --- /dev/null +++ b/src/commands/bot.js @@ -0,0 +1,14 @@ +module.exports = bot => { + bot.registerCommand("dbVersion", + async msg => await global.database.botInstance.get().then(row => row.version), + { + description: "Get db version", + fullDescription: "Get the database version.", + requirements: { + custom: msg => { + return msg.channel.permissionsOf(msg.member.id).has("administrator") + } + } + } + ) +} -- GitLab From f3659631ecfa55d4273708d208b05f468ff5a88f Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Fri, 31 Jul 2020 14:19:30 +0200 Subject: [PATCH 08/10] new db linking categories with roles --- src/database/categoryRole.js | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/database/categoryRole.js diff --git a/src/database/categoryRole.js b/src/database/categoryRole.js new file mode 100644 index 0000000..bd40d19 --- /dev/null +++ b/src/database/categoryRole.js @@ -0,0 +1,49 @@ +const AbstractInstance = require("./abstractInstance") + +class Instance extends AbstractInstance { + constructor(db) { + super(db) + this.updates = { + 2: () => this.db.run(` +create table if not exists categoryRole ( + categoryId text not null, + roleId text not null, + + primary key(categoryId, roleId) +) + `), + 3: async () => { + await this.create("728334680306352190", "727116447989497866") + } + } + } + + gets() { + return this.db.all("select * from categoryRole") + } + + getsByCategory(categoryId) { + return this.db.all(`select * from categoryRole where categoryId = ?`, categoryId) + } + + getsByRole(roleId) { + return this.db.all(`select * from categoryRole where roleId = ?`, roleId) + } + + get(categoryId, roleId) { + return this.db.get(`select * from categoryRole where categoryId = ? and roleId = ?`, roleId) + } + + create(categoryId, roleId) { + if(!categoryId || !roleId) { + throw new Error("one param is undefined") + } + return this.db.run(`insert into categoryRole(categoryId, roleId) values (?, ?)`, categoryId, roleId) + } + + delete(categoryId, roleId) { + return this.db.run(`delete from categoryRole where categoryId = ? and roleId = ?`, categoryId, roleId) + } +} + +module.exports = Instance -- GitLab From d5c1e7731411cf10f8eae870c84d624e15025430 Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Fri, 31 Jul 2020 14:20:09 +0200 Subject: [PATCH 09/10] added permission requirement to leader commands --- src/commands/channel.js | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/commands/channel.js b/src/commands/channel.js index 2c86735..400b49c 100644 --- a/src/commands/channel.js +++ b/src/commands/channel.js @@ -1,3 +1,5 @@ +const {Constants: Permission} = require("eris") + const utils = require("../utils/utils") const channelInfos = msg => { @@ -40,7 +42,7 @@ const createChannel = (bot, msg, args) => { utils.getGuild(bot).createChannel(args.join` `, 0, { parentID: msg.channel.parentID }) - .then(() => msg.addReaction("✅")) + .then(channel => msg.channel.createMessage(`Success ${channel.mention}`)) .catch(e => { msg.channel.createMessage(`An error happened, please contact <@${utils.ids.botDev}>: ${e.stack}`) @@ -89,16 +91,46 @@ module.exports = bot => { channelCommand.registerSubcommand("create", (msg, args) => createChannel(bot, msg, args), { aliases: ["new", "mk"], description: "Create a new channel", - fullDescription: "This command allows leaders to create a new channel in the current category." + fullDescription: "This command allows leaders to create a new channel in the current category.", + requirements: { + custom: + async msg => await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) + .then(res => res + .map(el => el.roleId) + .filter(el => msg.member.roles.includes(el)) + .length !== 0 + ) || + msg.channel.permissionsOf(msg.member.id).has("administrator") + } }) channelCommand.registerSubcommand("delete", (msg, args) => deleteChannel(bot, msg, args), { aliases: ["rm", "remove"], description: "Delete current channel ", - fullDescription: "This command allows leader to delete the current channel.\n⚠️️️️️️️️️ this is not reversible ⚠️️️️️️️️️" + fullDescription: "This command allows leader to delete the current channel.\n⚠️️️️️️️️️ this is not reversible ⚠️️️️️️️️️", + requirements: { + custom: + async msg => await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) + .then(res => res + .map(el => el.roleId) + .filter(el => msg.member.roles.includes(el)) + .length !== 0 + ) || + msg.channel.permissionsOf(msg.member.id).has("administrator") + } }) const configCommand = channelCommand.registerSubcommand("config", (msg, args) => configCommands.default(), { description: "Configure current channel", - fullDescription: "This command allows leader to configure the current channel.️️️️️️️️️" + fullDescription: "This command allows leader to configure the current channel.️️️️️️️️️", + requirements: { + custom: + async msg => await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) + .then(res => res + .map(el => el.roleId) + .filter(el => msg.member.roles.includes(el)) + .length !== 0 + ) || + msg.channel.permissionsOf(msg.member.id).has("administrator") + } }) configCommand.registerSubcommand("name", (msg, args) => configCommands.name(bot, msg, args)) configCommand.registerSubcommand("topic", (msg, args) => configCommands.topic(bot, msg, args), {aliases: ["desc", "description"]}) -- GitLab From 3d8636b55e529b1c72dd55db2e0269f180b62267 Mon Sep 17 00:00:00 2001 From: Jonathan Selle Date: Fri, 31 Jul 2020 18:25:22 +0200 Subject: [PATCH 10/10] permission are goods --- src/commands/channel.js | 54 ++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/commands/channel.js b/src/commands/channel.js index 400b49c..1e12faf 100644 --- a/src/commands/channel.js +++ b/src/commands/channel.js @@ -79,14 +79,12 @@ function getConfigChannelOptionsString() { module.exports = bot => { const channelCommand = bot.registerCommand("channel", channelInfos, { description: "Manage channels", - fullDescription: "This command can be used to manage channels.", - deleteCommand: true + fullDescription: "This command can be used to manage channels." }) channelCommand.registerSubcommand("info", channelInfos, { aliases: ["infos", "i"], description: "Give info for current channel", - fullDescription: "This command gives information about the current channel.", - deleteCommand: true + fullDescription: "This command gives information about the current channel." }) channelCommand.registerSubcommand("create", (msg, args) => createChannel(bot, msg, args), { aliases: ["new", "mk"], @@ -94,12 +92,16 @@ module.exports = bot => { fullDescription: "This command allows leaders to create a new channel in the current category.", requirements: { custom: - async msg => await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) - .then(res => res - .map(el => el.roleId) - .filter(el => msg.member.roles.includes(el)) - .length !== 0 - ) || + async msg => + ( + msg.member.roles.includes(utils.ids.roles.teamLead) && + await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) + .then(res => res + .map(el => el.roleId) + .filter(el => msg.member.roles.includes(el)) + .length !== 0 + ) + ) || msg.channel.permissionsOf(msg.member.id).has("administrator") } }) @@ -109,12 +111,16 @@ module.exports = bot => { fullDescription: "This command allows leader to delete the current channel.\n⚠️️️️️️️️️ this is not reversible ⚠️️️️️️️️️", requirements: { custom: - async msg => await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) - .then(res => res - .map(el => el.roleId) - .filter(el => msg.member.roles.includes(el)) - .length !== 0 - ) || + async msg => + ( + msg.member.roles.includes(utils.ids.roles.teamLead) && + await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) + .then(res => res + .map(el => el.roleId) + .filter(el => msg.member.roles.includes(el)) + .length !== 0 + ) + ) || msg.channel.permissionsOf(msg.member.id).has("administrator") } }) @@ -123,12 +129,16 @@ module.exports = bot => { fullDescription: "This command allows leader to configure the current channel.️️️️️️️️️", requirements: { custom: - async msg => await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) - .then(res => res - .map(el => el.roleId) - .filter(el => msg.member.roles.includes(el)) - .length !== 0 - ) || + async msg => + ( + msg.member.roles.includes(utils.ids.roles.teamLead) && + await global.database.categoryRoleInstance.getsByCategory(msg.channel.parentID) + .then(res => res + .map(el => el.roleId) + .filter(el => msg.member.roles.includes(el)) + .length !== 0 + ) + ) || msg.channel.permissionsOf(msg.member.id).has("administrator") } }) -- GitLab