diff --git a/data/config.json b/data/config.json index 479d43f..2c87ff6 100755 --- a/data/config.json +++ b/data/config.json @@ -5,5 +5,10 @@ "treeHeight": 0, "validCommands": [], "rankMessageId": "", - "rankings": [] + "rankings": [], + "devTeamIds": [ + "481933290912350209", + "269249959973355520" + ], + "ownerId": "481933290912350209" } \ No newline at end of file diff --git a/dot-commands/_template b/dot-commands/_template index 7b8f500..9286626 100644 --- a/dot-commands/_template +++ b/dot-commands/_template @@ -4,7 +4,15 @@ module.exports = { name: "", description: "", usage: "", - execute(message, commandData) { - // Code here... + permission: "devTeam", // "devTeam" or "owner" + async execute(message, commandData) { + if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) { + try { + // Code Here + } catch (err) { + console.error(err); + await message.reply(fn.builders.errorEmbed("There was an error running the command.")); + } + } } } \ No newline at end of file diff --git a/dot-commands/message.js b/dot-commands/message.js index a45b19b..f9a2722 100644 --- a/dot-commands/message.js +++ b/dot-commands/message.js @@ -4,37 +4,46 @@ module.exports = { name: "message", description: "Send a message to a server owner or server", usage: ".message ", + permission: "owner", async execute(message, commandData) { - args = commandData.args.split(" "); - if (message.client.guildInfos.has(args[0])) { - let guildInfo = message.client.guildInfos.get(args[0]); - const guild = await message.client.guilds.fetch(args[0]).catch(async e => { - await message.reply("I was unable to fetch the guild."); - console.error(`Error fetching guild to send message: ${e}`); - }); - const guildOwner = await message.client.users.fetch(guild.ownerId).catch(async e => { - await message.reply("I was unable to fetch the guild owner."); - console.error(`Error fetching guild owner to send message: ${e}`); - }); - await guildOwner.createDM().then(async dm => { - await dm.send(args.join(" ")).catch(async e => { - await message.reply("I was unable to send the DM."); - console.error(`Error sending DM message: ${e}`); - }); - }).catch(async e => { - await message.reply("I was unable to create the DM."); - console.error(`Error creating DM to send message: ${e}`); - const channel = await guild.channels.fetch(guildInfo.reminderChannelId).catch(async e => { - await message.reply("I was unable to fetch the channel."); - console.error(`Error fetching channel to send message: ${e}`); - }); - await channel.send(args.join(" ")).catch(async e => { - await message.reply("I was unable to send the message."); - console.error(`Error sending message: ${e}`); - }); - }); - } else { - throw "Guild doesn't exist in database!"; + if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) { + try { + // Code Here + args = commandData.args.split(" "); + if (message.client.guildInfos.has(args[0])) { + let guildInfo = message.client.guildInfos.get(args[0]); + const guild = await message.client.guilds.fetch(args[0]).catch(async e => { + await message.reply("I was unable to fetch the guild."); + console.error(`Error fetching guild to send message: ${e}`); + }); + const guildOwner = await message.client.users.fetch(guild.ownerId).catch(async e => { + await message.reply("I was unable to fetch the guild owner."); + console.error(`Error fetching guild owner to send message: ${e}`); + }); + await guildOwner.createDM().then(async dm => { + await dm.send(args.join(" ")).catch(async e => { + await message.reply("I was unable to send the DM."); + console.error(`Error sending DM message: ${e}`); + }); + }).catch(async e => { + await message.reply("I was unable to create the DM."); + console.error(`Error creating DM to send message: ${e}`); + const channel = await guild.channels.fetch(guildInfo.reminderChannelId).catch(async e => { + await message.reply("I was unable to fetch the channel."); + console.error(`Error fetching channel to send message: ${e}`); + }); + await channel.send(args.join(" ")).catch(async e => { + await message.reply("I was unable to send the message."); + console.error(`Error sending message: ${e}`); + }); + }); + } else { + throw "Guild doesn't exist in database!"; + } + } catch (err) { + console.error(err); + await message.reply(fn.builders.errorEmbed("There was an error running the command.")); + } } } } \ No newline at end of file diff --git a/dot-commands/ping.js b/dot-commands/ping.js index d18ae1c..cefb190 100644 --- a/dot-commands/ping.js +++ b/dot-commands/ping.js @@ -4,8 +4,15 @@ module.exports = { name: "ping", description: "pong", usage: "ping pong", + permission: "devTeam", async execute(message, commandData) { - // Code here... - await message.reply("Pong!"); + if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) { + try { + await message.reply("Pong!"); + } catch (err) { + console.error(err); + await message.reply(fn.builders.errorEmbed("There was an error running the command.")); + } + } } } \ No newline at end of file diff --git a/dot-commands/servers.js b/dot-commands/servers.js index 3143e9b..64eeb1c 100644 --- a/dot-commands/servers.js +++ b/dot-commands/servers.js @@ -4,14 +4,19 @@ module.exports = { name: "servers", description: "Get a list of servers the bot is in", usage: ".servers", + permission: "owner", async execute(message, commandData) { - let servers = []; - const count = JSON.stringify(message.client.guilds.cache.size); - servers.push("I'm currently in " + count + " servers."); - const guilds = await message.client.guilds.cache; - // await guilds.each(g => { - // servers.push(g.name + "," + g.ownerId); - // }); - await message.reply(servers.join("\n")); + if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) { + try { + let servers = []; + const count = JSON.stringify(message.client.guilds.cache.size); + servers.push("I'm currently in " + count + " servers."); + const guilds = await message.client.guilds.cache; + await message.reply(servers.join("\n")); + } catch (err) { + console.error(err); + await message.reply(fn.builders.errorEmbed("There was an error running the command.")); + } + } } } \ No newline at end of file diff --git a/dot-commands/setupview.js b/dot-commands/setupview.js new file mode 100644 index 0000000..fd38a45 --- /dev/null +++ b/dot-commands/setupview.js @@ -0,0 +1,24 @@ +const fn = require('../modules/functions.js'); + +module.exports = { + name: "setupview", + description: "", + usage: "", + permission: "devTeam", + async execute(message, commandData) { + // Code here... + if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) { + try { + if (message.client.guildInfos.has(message.guildId)) { + let guildInfo = message.client.guildInfos.get(message.guildId); + await message.reply(fn.builders.embed(guildInfo.generateSetupInfo())); + } else { + await message.reply(fn.builders.errorEmbed("Guild doesn't exist in database!")); + } + } catch (err) { + console.error(err); + await message.reply(fn.builders.errorEmbed("There was an error running the command.")); + } + } + } +} \ No newline at end of file diff --git a/main.js b/main.js index 9be859f..274803d 100755 --- a/main.js +++ b/main.js @@ -111,7 +111,7 @@ client.on('messageCreate', async message => { const commandData = fn.dotCommands.getCommandData(message); // if (isDev) console.log(commandData); - if (commandData.isValid && commandData.isCommand && (message.author.id == process.env.ownerId)) { + if (commandData.isValid && commandData.isCommand) { try { client.dotCommands.get(commandData.command).execute(message, commandData); } diff --git a/modules/functions.js b/modules/functions.js index a37a508..93b9e9d 100755 --- a/modules/functions.js +++ b/modules/functions.js @@ -247,9 +247,9 @@ const functions = { } commandData.isCommand = true; // Get the first part of the message, everything leading up to the final period - commandData.args = message.content.slice(0,finalPeriod).toLowerCase(); + commandData.args = message.content.slice(0, finalPeriod).toLowerCase(); // Get the last part of the message, everything after the final period - commandData.command = message.content.slice(finalPeriod).replace('.','').toLowerCase(); + commandData.command = message.content.slice(finalPeriod).replace('.', '').toLowerCase(); commandData.author = `${message.author.username}#${message.author.discriminator}`; return this.checkCommand(commandData); }, @@ -265,6 +265,19 @@ const functions = { console.error('Somehow a non-command made it to checkCommands()'); } return commandData; + }, + checkPermissions(type, userId) { + if (type === "devTeam") { + const { devTeamIds } = config; + let matchFound = false; + for (let i = 0; i < devTeamIds.length; i++) { + if (userId === devTeamIds[i]) matchFound = true; + } + return matchFound; + } else if (type === "owner") { + return config.ownerId === userId; + } + } }, rankings: { @@ -762,7 +775,7 @@ const functions = { errorFlag = true; status = strings.error.noTakeRole; }); - if(!errorFlag) status = strings.error.yesTakeRole; + if (!errorFlag) status = strings.error.yesTakeRole; } else { await functions.roles.giveRole(interaction.member, role).catch(e => { errorFlag = true; @@ -824,7 +837,7 @@ const functions = { // Make sure guildInfo is what we expect, the watch channel isnt blank, and notifications are enabled if (guildInfo instanceof GuildInfo && guildInfo.watchChannelId != "" && guildInfo.notificationsEnabled) { // Fetch the Guild - const guild = await client.guilds.fetch(guildInfo.guildId).catch(e => {throw "Attempted to fetch guild I'm no longer in."}); + const guild = await client.guilds.fetch(guildInfo.guildId).catch(e => { throw "Attempted to fetch guild I'm no longer in." }); // Fetch the Channel const channel = await guild.channels.fetch(guildInfo.watchChannelId); // Create the filter function