From e3576b17b1c511e63aad2f0ceae77c746e890bef Mon Sep 17 00:00:00 2001 From: ItzEmerald Date: Tue, 14 Jul 2020 19:17:40 +0100 Subject: [PATCH] Updated --- commands/addUser.js | 21 +++++++++------- commands/announce.js | 9 ++++--- commands/botSay.js | 50 +++++++++++++++++++++++++++++++++++++ commands/close.js | 5 ++-- commands/help.js | 38 +++++++++++++++++----------- commands/links.js | 1 + commands/newticket.js | 3 ++- commands/ping.js | 1 + commands/removeUser.js | 23 +++++++++-------- commands/suggest.js | 5 ++-- package-lock.json | 6 ++--- storage/SupportTickets.json | 2 +- storage/TicketID.json | 2 +- supportbot-config.yml | 28 +++++++++++++++++++-- 14 files changed, 145 insertions(+), 49 deletions(-) create mode 100644 commands/botSay.js diff --git a/commands/addUser.js b/commands/addUser.js index d5f249c..e9e8d19 100644 --- a/commands/addUser.js +++ b/commands/addUser.js @@ -9,22 +9,25 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.AddUser, + description: supportbot.AddUserDesc, execute(message, args) { console.log(`\u001b[32m`, `[${supportbot.Bot_Name}]:`, `\u001b[32m`, `${message.author.tag} has executed ${supportbot.Prefix}${supportbot.AddUser}!`); - let SupportStaff = message.guild.roles.cache.find(staffRole => staffRole.name === supportbot.Staff); + let SupportStaff = message.guild.roles.cache.find(staffRole => staffRole.name === supportbot.Staff, supportbot.Admin); const NoPerms = new Discord.MessageEmbed() .setTitle("Invalid Permissions!") - .setDescription(`:warning: **Err!** You do not have the correct permissions to use this command.\n\nRole Required: \`${supportbot.SupportStaff}\``) - .setColor(supportbot.WarningColour) - message.channel.send({ embed: NoPerms }); + .setDescription(`${supportbot.IncorrectPerms}\n\nRole Required: \`${SupportStaff.name}\``) + .setColor(supportbot.ErrorColour) + + if (!message.member.roles.cache.has(SupportStaff.id)) + return message.channel.send({ embed: NoPerms }); if (!message.channel.name.startsWith( `${supportbot.TicketChannel}-` )) { const Exists = new Discord.MessageEmbed() - .setTitle("Incorrect Channel") - .setDescription(`:warning: You cannot execute this command here. This command is used when closing a ticket.`) + .setTitle("No Ticket Found!") + .setDescription(`${supportbot.NoValidTicket}`) .setColor(supportbot.WarningColour); message.channel.send({ embed: Exists }); @@ -34,8 +37,8 @@ module.exports = { let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[0])); const UserNotExist = new Discord.MessageEmbed() .setTitle("User Not Found!") - .setDescription(`:x: **Error!** This user doesn't exist, Are they in this server?\n\nTry Again:\`${supportbot.Prefix}${supportbot.AddUser} \``) - .setColor(supportbot.ErrorColor) + .setDescription(`${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${supportbot.AddUser} \``) + .setColor(supportbot.ErrorColour) if (!rUser) return message.channel.send({ embed: UserNotExist }); @@ -48,7 +51,7 @@ module.exports = { const Complete = new Discord.MessageEmbed() .setTitle("User Added!") - .setDescription(`👍 ${rUser} has been added to this ticket`) + .setDescription(supportbot.AddedUser.replace(/%user%/g, rUser.id)) .setTimestamp() .setColor(supportbot.EmbedColour) message.channel.send({ embed: Complete }); diff --git a/commands/announce.js b/commands/announce.js index 3d57469..50205ce 100644 --- a/commands/announce.js +++ b/commands/announce.js @@ -10,6 +10,7 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.AnnounceCommand, + description: supportbot.AnnounceDesc, execute(message, args) { @@ -17,7 +18,7 @@ module.exports = { const errornochannel = new Discord.MessageEmbed() .setTitle("Invalid Channel") - .setDescription(`:x: **Error!** Channel not Found, This command cannot be executed proberbly as their is no channel within this server.\nThis is configurable via **supportbot-config.yml**\n\nChannel Required: \`${supportbot.AnnouncementChannel}`) + .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.AnnouncementChannel}`) .setColor(supportbot.ErrorColour); if(!locateChannel) return message.channel.send({ embed: errornochannel }); @@ -26,9 +27,11 @@ module.exports = { const NoPerms = new Discord.MessageEmbed() .setTitle("Invalid Permissions!") - .setDescription(`:warning: **Err!** You do not have the correct permissions to use this command.\n\nRole Required: \`${supportbot.serverAdmins}\``) + .setDescription(`${supportbot.IncorrectPerms}\n\nRole Required: \`${serverAdmins.name}\``) .setColor(supportbot.WarningColour) - message.channel.send({ embed: NoPerms }); + + if (!message.member.roles.cache.has(serverAdmins.id)) + return message.channel.send({ embed: NoPerms }); const embed = new Discord.MessageEmbed() diff --git a/commands/botSay.js b/commands/botSay.js new file mode 100644 index 0000000..c90df2c --- /dev/null +++ b/commands/botSay.js @@ -0,0 +1,50 @@ +// SupportBot 6.0, Created by Emerald Services +// Say Command + +const Discord = require("discord.js"); +const fs = require("fs"); + +const yaml = require('js-yaml'); +const { execute } = require("./help"); +const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')); + +module.exports = { + name: supportbot.BotSay, + description: supportbot.BotSayDesc, + + execute(message, args) { + + let SupportStaff = message.guild.roles.cache.find(adminRole => adminRole.name === supportbot.Staff); + + const NoPerms = new Discord.MessageEmbed() + .setTitle("Invalid Permissions!") + .setDescription(`${supportbot.IncorrectPerms}\n\nRole Required: \`${SupportStaff.name}\``) + .setColor(supportbot.WarningColour) + + if (!message.member.roles.cache.has(SupportStaff.id)) + return message.channel.send({ embed: NoPerms }); + + + const embed = new Discord.MessageEmbed() + .setDescription(`> **What would you like me to say!**`) + .setColor(supportbot.EmbedColour) + message.channel.send({ embed: embed }); + + let announcement = [] + message.channel.awaitMessages(response => response.content.length > 2, { + max: 1, + time: 500000, + errors: ['time'], + }).then((collected) => { + announcement.push(collected.map(r => r.content)); + + const AnnouncementEmbed = new Discord.MessageEmbed() + .setDescription(announcement) + .setColor(supportbot.EmbedColour) + + message.channel.send({ embed: AnnouncementEmbed }) + }) + + } + +}; \ No newline at end of file diff --git a/commands/close.js b/commands/close.js index 5fa9c2f..d45fae6 100644 --- a/commands/close.js +++ b/commands/close.js @@ -10,14 +10,15 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.CloseTicket, + description: supportbot.CloseTicketDesc, execute(message, args) { console.log(`\u001b[32m`, `[${supportbot.Bot_Name}]:`, `\u001b[32m`, `${message.author.tag} has executed ${supportbot.Prefix}${supportbot.CloseTicket}!`); if (!message.channel.name.startsWith( `${supportbot.TicketChannel}-` )) { const Exists = new Discord.MessageEmbed() - .setTitle("Incorrect Channel") - .setDescription(`:warning: You cannot execute this command here. This command is used when closing a ticket.`) + .setTitle("No Ticket Found!") + .setDescription(`${supportbot.NoValidTicket}`) .setColor(supportbot.WarningColour); message.channel.send({ embed: Exists }); diff --git a/commands/help.js b/commands/help.js index 7cac1a5..0a029e0 100644 --- a/commands/help.js +++ b/commands/help.js @@ -9,26 +9,24 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.HelpCommand, + description: supportbot.HelpDesc, execute(message, args) { let generalCommands = ""; - generalCommands += `**${supportbot.Prefix}${supportbot.HelpCommand}** Lists all the bot commands\n`; - generalCommands += `**${supportbot.Prefix}${supportbot.LinksCommand}** Get some important links\n`; - generalCommands += `**${supportbot.Prefix}${supportbot.SuggestCommand}** Create a new suggestion\n`; - generalCommands += `**${supportbot.Prefix}${supportbot.PingCommand}** Check bot's latency\n`; + generalCommands += `**${supportbot.Prefix}${supportbot.HelpCommand}** ${supportbot.HelpDesc}\n`; + generalCommands += `**${supportbot.Prefix}${supportbot.LinksCommand}** ${supportbot.LinkDesc}\n`; + generalCommands += `**${supportbot.Prefix}${supportbot.SuggestCommand}** ${supportbot.SuggestionDesc}\n`; + generalCommands += `**${supportbot.Prefix}${supportbot.PingCommand}** ${supportbot.PingDesc}\n`; let supportCommands = ""; - supportCommands += `**${supportbot.Prefix}${supportbot.NewTicket} [reason]** Create a support ticket\n` - supportCommands += `**${supportbot.Prefix}${supportbot.CloseTicket} [reason]** Close your support ticket\n` + supportCommands += `**${supportbot.Prefix}${supportbot.NewTicket} [reason]** ${supportbot.NewTicketDesc}\n` + supportCommands += `**${supportbot.Prefix}${supportbot.CloseTicket} [reason]** ${supportbot.CloseTicketDesc}\n` let staffCommands = ""; - staffCommands += `**${supportbot.Prefix}${supportbot.RenameTicket} ** Rename a valid support ticket\n` - staffCommands += `**${supportbot.Prefix}${supportbot.AddUser} ** Add a user to a valid support ticket\n` - staffCommands += `**${supportbot.Prefix}${supportbot.RemoveUser} ** Remove a user from a valid support ticket\n` - - let adminCommands = ""; - adminCommands += `**${supportbot.Prefix}${supportbot.AnnounceCommand}** Create a new server announcement\n` - adminCommands += `**${supportbot.Prefix}${supportbot.SayCommand}** Send a message as the bot\n` + staffCommands += `**${supportbot.Prefix}${supportbot.AddUser} ** ${supportbot.AddUserDesc}\n` + staffCommands += `**${supportbot.Prefix}${supportbot.RemoveUser} ** ${supportbot.RemoveUserDesc}\n` + staffCommands += `**${supportbot.Prefix}${supportbot.BotSayCommand}** ${supportbot.BotSayDesc}\n` + staffCommands += `**${supportbot.Prefix}${supportbot.AnnounceCommand}** ${supportbot.AnnounceDesc}\n` const HelpCommandEmbed = new Discord.MessageEmbed() .setTitle(supportbot.Bot_Name) @@ -37,13 +35,23 @@ module.exports = { .addFields( { name: '🖥️ General Commands', value: `${generalCommands}\n`, inline: false }, { name: '🎫 Support Commands', value: `${supportCommands}\n`, inline: false }, - { name: '🔑 Staff Commands', value: `${staffCommands}\n`, inline: false }, - { name: '🔐 Admin Commands', value: `${adminCommands}`, inline: false }, ) .setColor(supportbot.EmbedColour) .setFooter(supportbot.EmbedFooter, message.author.displayAvatarURL()); + if (message.member.roles.cache.some(role => role.name === supportbot.Staff, supportbot.Admin)) { + HelpCommandEmbed.addFields( + { name: '🔑 Staff Commands', value: `${staffCommands}\n`, inline: false }, + ) + } + + if (message.member.roles.cache.some(role => role.name === supportbot.Admin)) { + HelpCommandEmbed.addFields( + { name: '🔑 Staff Commands', value: `${staffCommands}\n`, inline: false }, + ) + } + message.channel.send({ embed: HelpCommandEmbed }); } }; \ No newline at end of file diff --git a/commands/links.js b/commands/links.js index f17a9c9..4282cad 100644 --- a/commands/links.js +++ b/commands/links.js @@ -10,6 +10,7 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.LinksCommand, + description: supportbot.LinksDesc, execute(message, args) { diff --git a/commands/newticket.js b/commands/newticket.js index 3995ba3..7d8514f 100644 --- a/commands/newticket.js +++ b/commands/newticket.js @@ -11,6 +11,7 @@ const reacted = []; module.exports = { name: supportbot.NewTicket, + description: supportbot.NewTicketDesc, execute(message, args) { console.log(`\u001b[32m`, `[${supportbot.Bot_Name}]:`, `\u001b[32m`, `${message.author.tag} has executed ${supportbot.Prefix}${supportbot.NewTicket}!`); @@ -24,7 +25,7 @@ module.exports = { // Ticket Exists const TicketExists = new Discord.MessageEmbed() .setTitle("Ticket Exists!") - .setDescription(":no_entry_sign: This ticket cannot be opened, It already exists!") + .setDescription(`${supportbot.TicketExists}`) .setColor(supportbot.WarningColour) if (message.guild.channels.cache.find(SupportTicket => SupportTicket.name === `${supportbot.TicketChannel}-${ticketNumberID}`)) diff --git a/commands/ping.js b/commands/ping.js index 5a6548e..e69206c 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -9,6 +9,7 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.PingCommand, + description: supportbot.PingDesc, execute(message, args) { let ping = Date.now() - message.createdTimestamp + " ms"; diff --git a/commands/removeUser.js b/commands/removeUser.js index 7fee71b..5b14b0f 100644 --- a/commands/removeUser.js +++ b/commands/removeUser.js @@ -9,21 +9,24 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.RemoveUser, + description: supportbot.RemoveUserDesc, execute(message, args) { console.log(`\u001b[32m`, `[${supportbot.Bot_Name}]:`, `\u001b[32m`, `${message.author.tag} has executed ${supportbot.Prefix}${supportbot.RemoveUser}!`); - let staffGroup = message.guild.roles.cache.find(staffRole => staffRole.name === supportbot.Staff); - const NoPerms = new Discord.MessageEmbed() - .setTitle("Invalid Permissions!") - .setDescription(":warning: **Err!** You do not have the correct permissions to use this command.") - .setColor(supportbot.WarningColour) - message.channel.send({ embed: NoPerms }); + let SupportStaff = message.guild.roles.cache.find(staffRole => staffRole.name === supportbot.Staff); + const NoPerms = new Discord.MessageEmbed() + .setTitle("Invalid Permissions!") + .setDescription(`${supportbot.IncorrectPerms}\n\nRole Required: \`${SupportStaff.name}\``) + .setColor(supportbot.ErrorColour) + + if (!message.member.roles.cache.has(SupportStaff.id)) + return message.channel.send({ embed: NoPerms }); if (!message.channel.name.startsWith( `${supportbot.TicketChannel}-` )) { const Exists = new Discord.MessageEmbed() - .setTitle("Incorrect Channel") - .setDescription(`:warning: You cannot execute this command here. This command is used when closing a ticket.`) + .setTitle("No Ticket Found!") + .setDescription(`${supportbot.NoValidTicket}`) .setColor(supportbot.WarningColour); message.channel.send({ embed: Exists }); @@ -33,7 +36,7 @@ module.exports = { let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[0])); const UserNotExist = new Discord.MessageEmbed() .setTitle("User Not Found!") - .setDescription(`:x: **Error!** This user doesn't exist, Are they in this server?\n\nTry Again:\`${supportbot.Prefix}${supportbot.RemoveUser} \``) + .setDescription(`${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${supportbot.RemoveUser} \``) .setColor(supportbot.ErrorColor) if (!rUser) return message.channel.send({ embed: UserNotExist }); @@ -47,7 +50,7 @@ module.exports = { const Complete = new Discord.MessageEmbed() .setTitle("User Removed!") - .setDescription(`👍 ${rUser} has been removed from this ticket`) + .setDescription(supportbot.RemovedUser.replace(/%user%/g, rUser.id)) .setTimestamp() .setColor(supportbot.EmbedColour) message.channel.send({ embed: Complete }); diff --git a/commands/suggest.js b/commands/suggest.js index 64aadb0..7ffd398 100644 --- a/commands/suggest.js +++ b/commands/suggest.js @@ -9,13 +9,14 @@ const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')) module.exports = { name: supportbot.SuggestCommand, + description: supportbot.SuggestionDesc, execute(message, args) { let locateChannel = message.guild.channels.cache.find(SuggestionChannel => SuggestionChannel.name === supportbot.SuggestionChannel); const errornochannel = new Discord.MessageEmbed() - .setTitle("SupportBot Error!") - .setDescription(`:x: **Error!** Channel not Found, This command cannot be executed proberbly as their is no channel within this server.\nThis is configurable via **supportbot-config.yml**\n\nChannel Required: \`${supportbot.SuggestionChannel}\`\n\nError Code: \`SB-03\``) + .setTitle("Invalid Channel") + .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.SuggestionChannel}\``) .setColor(supportbot.ErrorColour); if(!locateChannel) return message.channel.send({ embed: errornochannel }); diff --git a/package-lock.json b/package-lock.json index 7540c76..76dde51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -126,9 +126,9 @@ "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" }, "ws": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", - "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==" + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz", + "integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==" } } } diff --git a/storage/SupportTickets.json b/storage/SupportTickets.json index 0bc4123..7635a24 100644 --- a/storage/SupportTickets.json +++ b/storage/SupportTickets.json @@ -1,4 +1,4 @@ { - "ticket": "ticket-0058", + "ticket": "ticket-0061", "id":419821884431925260 } \ No newline at end of file diff --git a/storage/TicketID.json b/storage/TicketID.json index 9f38e34..0ece568 100644 --- a/storage/TicketID.json +++ b/storage/TicketID.json @@ -1,5 +1,5 @@ { "716992597377286145": { - "id": 59 + "id": 62 } } \ No newline at end of file diff --git a/supportbot-config.yml b/supportbot-config.yml index e1f7c46..239e0c9 100644 --- a/supportbot-config.yml +++ b/supportbot-config.yml @@ -11,7 +11,7 @@ # General Bot Configuration -Token: "TOKEN" +Token: "NjcyMTU5MjQyNjg5NzA4MDUz.XwnBpg.6eCCVRv4m-aVPJuppHWNxpxpRs0" Prefix: "!!" Bot_Name: "SupportBot DEV" @@ -56,6 +56,9 @@ NoTicketSubject: "No Reason Provided!" TicketCreatedAlert: ":ticket: Your support ticket has been created: <#%ticketid%>" TranscriptTitle: "Ticket Transcript" +AddedUser: "👍 <@%user%> has been added to this ticket" +RemovedUser: "👍 <@%user%> has been removed from this ticket" + ClosingTicket: ":warning: You have requested to close your support ticket." ClosingConfirmation_Word: "confirm" CloseConfirmation: "true" @@ -155,8 +158,29 @@ RenameTicket: "rename" # Staff Command Configuration -SayCommand: "say" +BotSay: "say" # Admin Command Configuration AnnounceCommand: "announce" + +# Commmand Descriptions + +NewTicketDesc: "Create a new support ticket" +AnnounceDesc: "Create a server announcement" +CloseTicketDesc: "Close your support ticket" +LinksDesc: "View some important links" +PingDesc: "Get the bot's latency" +HelpDesc: "Get a list of all the commands" +RemoveUserDesc: "Remove a user from a support ticket" +AddUserDesc: "Add a user to a support ticket" +SuggestionDesc: "Create a server suggestion" +BotSayDesc: "Say something with the bot" + +# Error / Warining Messages + +IncorrectPerms: ":x: **Err!** You do not have the correct permissions to use this command." +InvalidChannel: ":x: **Err!** Channel not found. Please create it!" +UserNotFound: ":x: **Err!** This user doesn't exist, Are they in this server?" +NoValidTicket: ":warning: You cannot execute this command here. This command is used when closing a ticket." +TicketExists: ":warning: This ticket cannot be opened, It already exists!" \ No newline at end of file