From 9ef0c3d04ed9336ddc243b61fa3ac89d1f81cc5b Mon Sep 17 00:00:00 2001 From: Eartharoid Date: Sun, 5 May 2019 20:19:29 +0100 Subject: [PATCH] update Finish up commands and update package.json --- commands/add.js | 58 +++++++++++++++++++++++++++++++++++++++++++--- commands/close.js | 4 ++-- commands/help.js | 7 +++--- commands/ping.js | 1 - commands/remove.js | 58 ++++++++++++++++++++++++++++++++++++++++++---- package.json | 5 ++-- 6 files changed, 116 insertions(+), 17 deletions(-) diff --git a/commands/add.js b/commands/add.js index c99fff7..b14698a 100644 --- a/commands/add.js +++ b/commands/add.js @@ -7,16 +7,68 @@ module.exports = { usage: '<@member>', aliases: ['adduser'], example: 'add @exampleUser', - args: false, + args: true, cooldown: config.cooldown, guildOnly: true, execute(message, args) { const client = message.client; // command starts here message.delete(); + if(!message.channel.name.startsWith('ticket-')) { + if(config.useEmbeds) { + const notTicket = new Discord.RichEmbed() + .setColor("#E74C3C") + .setDescription(`:x: **This command can only be used within a ticket channel**`) + return message.channel.send(notTicket); + } else { + return message.channel.send(`:x: **This command can only be used within a ticket channel**`) + } + } - - + let user = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0])); + if(!user) { + if(config.useEmbeds) { + const err1 = new Discord.RichEmbed() + .setColor("#E74C3C") + .setDescription(`:x: **Unknown user.** Please mention a valid user.`) + return message.channel.send(err1); + } else { + return message.channel.send(`:x: **Unknown user.** Please mention a valid user.`); + } + } + try { + message.channel.overwritePermissions(user, { + SEND_MESSAGES: true, + READ_MESSAGES: true, + ATTACH_FILES: true + }); + if(config.useEmbeds) { + const added = new Discord.RichEmbed() + .setColor(config.colour) + .setDescription(`${user} has been added.`) + message.channel.send(added); + } else { + message.channel.send(`${user} has been added.`); + } + // log + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setTitle("User Added") + .setColor(config.colour) + .addField("Username", user, true) + .addField("Added by", message.author, true) + .addField("Channel", message.channel, true) + .setFooter(`DiscordTickets`) + .setTimestamp(); + client.channels.get(config.logChannel).send({embed}) + } else { + client.channels.get(config.logChannel).send(`User added to a ticket by **${message.author.tag} (${message.author.id})**`); + } + log.info(`${message.author.tag} added a user to a ticket (#${message.channel})`) + } catch(error) { + log.error(error); + } // command ends here }, diff --git a/commands/close.js b/commands/close.js index 1e5348b..24a58fe 100644 --- a/commands/close.js +++ b/commands/close.js @@ -14,7 +14,7 @@ module.exports = { const client = message.client; // command starts here message.delete(); - if(!message.channel.name.startsWith('ticket-')) { // // !message.channel.name.length() == 15 && + if(!message.channel.name.startsWith('ticket-')) { // // !message.channel.name.length() == 15 && if(config.useEmbeds) { const notTicket = new Discord.RichEmbed() .setColor("#E74C3C") @@ -43,7 +43,7 @@ module.exports = { log.info(`${message.author.tag} closed a ticket (#${message.channel.name})`) } catch(error) { - console.error(leeks.colours.red(error)); + log.error(leeks.colours.red(error)); } } diff --git a/commands/help.js b/commands/help.js index 8b4c41b..f726c99 100644 --- a/commands/help.js +++ b/commands/help.js @@ -63,15 +63,14 @@ module.exports = { } const cmd = new Discord.RichEmbed() - .setTitle("Commands") .setColor(config.colour) .addField(`Command`,`\`${command.name}\``, true) .setFooter(`DiscordTickets by Eartharoid`); if (command.aliases) cmd.addField("Aliases", `\`${command.aliases.join(', ')}\``, true); - if (command.description) cmd.addField("Description", `\`${command.description}\``, true); - if (command.usage) cmd.addField("Usage", `\`${config.prefix}${command.name} ${command.usage}\``, true) - if (command.example) cmd.addField("Example", `\`${config.prefix}${command.example}\``, true); + if (command.description) cmd.addField("Description", `\`${command.description}\``, false); + if (command.usage) cmd.addField("Usage", `\`${config.prefix}${command.name} ${command.usage}\``, false) + if (command.example) cmd.addField("Example", `\`${config.prefix}${command.example}\``, false); message.channel.send(cmd) } diff --git a/commands/ping.js b/commands/ping.js index 2c10483..bb1470c 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -19,7 +19,6 @@ module.exports = { .setColor(config.colour) .setTimestamp() .addField("API Latency", `${Math.round(message.client.ping)}ms`, true) - .setFooter(`DiscordTickets by Eartharoid`); message.channel.send({embed}) diff --git a/commands/remove.js b/commands/remove.js index 987bab8..6040790 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -7,17 +7,67 @@ module.exports = { usage: '<@member>', aliases: ['kick'], example: 'remove @exampleUser', - args: false, + args: true, cooldown: config.cooldown, guildOnly: true, execute(message, args) { const client = message.client; // command starts here message.delete(); + if(!message.channel.name.startsWith('ticket-')) { + if(config.useEmbeds) { + const notTicket = new Discord.RichEmbed() + .setColor("#E74C3C") + .setDescription(`:x: **This command can only be used within a ticket channel**`) + return message.channel.send(notTicket); + } else { + return message.channel.send(`:x: **This command can only be used within a ticket channel**`) + } + } - - - + let user = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0])); + if(!user) { + if(config.useEmbeds) { + const err1 = new Discord.RichEmbed() + .setColor("#E74C3C") + .setDescription(`:x: **Unknown user.** Please mention a valid user.`) + return message.channel.send(err1); + } else { + return message.channel.send(`:x: **Unknown user.** Please mention a valid user.`); + } + } + try { + message.channel.overwritePermissions(user, { + SEND_MESSAGES: false, + READ_MESSAGES: false + }); + if(config.useEmbeds) { + const removed = new Discord.RichEmbed() + .setColor(config.colour) + .setDescription(`${user} has been removed.`) + message.channel.send(removed); + } else { + message.channel.send(`${user} has been removed.`); + } + // log + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setTitle("User Removed") + .setColor(config.colour) + .addField("Username", user, true) + .addField("Removed by", message.author, true) + .addField("Channel", message.channel, true) + .setFooter(`DiscordTickets`) + .setTimestamp(); + client.channels.get(config.logChannel).send({embed}) + } else { + client.channels.get(config.logChannel).send(`User removed to a ticket by **${message.author.tag} (${message.author.id})**`); + } + log.info(`${message.author.tag} removed a user to a ticket (#${message.channel})`) + } catch(error) { + log.error(error); + } // command ends here }, }; diff --git a/package.json b/package.json index 3538a54..22e5dab 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,11 @@ { "name": "DiscordTickets", - "version": "1.0.0", + "version": "1.1.4", "description": "A Discord ticket/support - an open-source & self-host alternative to TicketManager (name tbd)", "main": "index.js", "dependencies": { "discord.js": "^11.4.2", - "leeks.js": "^0.0.1", - "random-string": "^0.2.0" + "leeks.js": "^0.0.1" }, "devDependencies": {}, "scripts": {