diff --git a/commands/add.js b/commands/add.js new file mode 100644 index 0000000..9bdf93d --- /dev/null +++ b/commands/add.js @@ -0,0 +1,22 @@ +const Discord = require('discord.js'); +const config = require('../config.json'); +module.exports = { + name: 'add', + description: 'Add a member to a ticket channel', + usage: '<@member>', + aliases: ['adduser'], + example: 'add @exampleUser', + args: false, + cooldown: config.cooldown, + guildOnly: true, + execute(message, args) { + const client = message.client; + // command starts here + message.delete(); + + + + + // command ends here + }, +}; diff --git a/commands/close.js b/commands/close.js new file mode 100644 index 0000000..e6c7e8e --- /dev/null +++ b/commands/close.js @@ -0,0 +1,22 @@ +const Discord = require('discord.js'); +const config = require('../config.json'); +module.exports = { + name: 'close', + description: 'Close a ticket', + usage: '', + aliases: ['none'], + example: '', + args: false, + cooldown: config.cooldown, + guildOnly: true, + execute(message, args) { + const client = message.client; + // command starts here + message.delete(); + + + + + // command ends here + }, +}; diff --git a/commands/example-command.js.example b/commands/example-command.js.example index a14ab67..931e39b 100644 --- a/commands/example-command.js.example +++ b/commands/example-command.js.example @@ -4,10 +4,11 @@ module.exports = { name: 'example-command', description: 'An example command', usage: '[args]', - aliases: ['command', 'commands'], + aliases: ['none'], example: 'example-command', args: false, cooldown: config.cooldown, + guildOnly: true, execute(message, args) { const client = message.client; // command starts here diff --git a/commands/help.js b/commands/help.js index 1c4e8b6..4fd5f70 100644 --- a/commands/help.js +++ b/commands/help.js @@ -9,6 +9,7 @@ module.exports = { example: 'help new', args: false, cooldown: config.cooldown, + guildOnly: true, execute(message, args) { const client = message.client; // command starts here @@ -65,6 +66,7 @@ module.exports = { const cmd = new Discord.RichEmbed() .setAuthor(`${client.user.username} / Commands`, client.user.avatarURL) .setColor(config.colour) + .addField(`Command`,`\`${command.name}\``, true) .setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`); if (command.aliases) cmd.addField("Aliases", `\`${command.aliases.join(', ')}\``, true); diff --git a/commands/new.js b/commands/new.js index 191fe90..09d6db6 100644 --- a/commands/new.js +++ b/commands/new.js @@ -1,5 +1,6 @@ const Discord = require('discord.js'); const config = require('../config.json'); +const randomString = require('random-string'); module.exports = { name: 'new', description: 'Create a new ticket', @@ -8,11 +9,22 @@ module.exports = { example: 'new I found an error', args: true, cooldown: config.cooldown, + guildOnly: true, execute(message, args) { const client = message.client; // command starts here message.delete(); const ticketChannel = "channel"; + let topic = args.join(" "); + + function num(){ + return randomString({ + length: 4, + numeric: true, + letters: false, + special: false, + }) + }; // log if(config.useEmbeds) { diff --git a/commands/ping.js b/commands/ping.js new file mode 100644 index 0000000..41ea0a8 --- /dev/null +++ b/commands/ping.js @@ -0,0 +1,29 @@ +const Discord = require('discord.js'); +const config = require('../config.json'); +module.exports = { + name: 'ping', + description: 'Calculate latency', + usage: '', + aliases: ['none'], + example: '', + args: false, + cooldown: config.cooldown, + guildOnly: true, + execute(message, args) { + const client = message.client; + // command starts here + message.delete(); + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Pong!`, client.user.avatarURL) + .setColor(config.colour) + .setTimestamp() + .addField("API Latency", `${Math.round(message.client.ping)}ms`, true) + .setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`); + message.channel.send({embed}) + + + + + // command ends here + }, +}; diff --git a/commands/remove.js b/commands/remove.js new file mode 100644 index 0000000..0160c1d --- /dev/null +++ b/commands/remove.js @@ -0,0 +1,22 @@ +const Discord = require('discord.js'); +const config = require('../config.json'); +module.exports = { + name: 'remove', + description: 'Remove a member from a ticket', + usage: '<@member>', + aliases: ['kick'], + example: 'remove @exampleUser', + args: false, + cooldown: config.cooldown, + guildOnly: true, + execute(message, args) { + const client = message.client; + // command starts here + message.delete(); + + + + + // command ends here + }, +}; diff --git a/image.png b/image.png new file mode 100644 index 0000000..ecf605f Binary files /dev/null and b/image.png differ diff --git a/index.js b/index.js index b3c52c8..f979102 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ /* ############################################################################################### - ____ _ _____ _ _ _ + ____ _ _____ _ _ | _ \ (_) ___ ___ ___ _ __ __| | |_ _| (_) ___ | | __ ___ | |_ ___ | | | | | | / __| / __| / _ \ | '__| / _` | | | | | / __| | |/ / / _ \ | __| / __| | |_| | | | \__ \ | (__ | (_) | | | | (_| | | | | | | (__ | < | __/ | |_ \__ \ @@ -138,12 +138,12 @@ client.once('ready', () => { // after bot has logged in }); -client.on('message', message => { +client.on('message', async message => { // if (!message.content.startsWith(config.prefix) || message.author.bot) return; if (message.author.bot) return; if (message.channel.type === "dm") { if (message.author.id === client.user.id) return; - message.channel.send(`Sorry, commands can only be used on the server.`) + // message.channel.send(`Sorry, commands can only be used on the server.`) if (config.logDMs) { if (config.useEmbeds) { const embed = new Discord.RichEmbed() @@ -167,9 +167,9 @@ client.on('message', message => { // const args = message.content.slice(config.prefix.length).split(/ +/); + const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|\\${config.prefix})\\s*`); if (!prefixRegex.test(message.content)) return; - const [, matchedPrefix] = message.content.match(prefixRegex); const args = message.content.slice(matchedPrefix.length).trim().split(/ +/); const commandName = args.shift().toLowerCase(); @@ -180,6 +180,10 @@ client.on('message', message => { if (!command) return; + if (command.guildOnly && message.channel.type !== 'text') { + return message.channel.send(`Sorry, this command can only be used on the server.`) + } + if (command.args && !args.length) { // let reply = `:x: **Arguments were expected but none were provided.**`; // @@ -238,7 +242,7 @@ client.on('message', message => { } catch (error) { console.error(error); message.channel.send(`:x: **Oof!** An error occured whilst executing that command.\nThe issue has been reported.`); - console.log(leeks.colors.red(`[ERROR] An unknown error occured whilst executing '${command}' command`)); + console.log(leeks.colors.red(`[ERROR] An unknown error occured whilst executing the '${command.name}' command`)); } }); diff --git a/package.json b/package.json index 14e0e13..3538a54 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "dependencies": { "discord.js": "^11.4.2", - "leeks.js": "^0.0.1" + "leeks.js": "^0.0.1", + "random-string": "^0.2.0" }, "devDependencies": {}, "scripts": {