This commit is contained in:
David Ralph 2020-08-03 16:39:39 +01:00
parent 606d87d24e
commit 2964d1b9a6
8 changed files with 107 additions and 154 deletions

View File

@ -1,6 +1,7 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const config = require('../config.json'); const config = require('../config.json');
const log = require(`leekslazylogger`); const log = require(`leekslazylogger`);
module.exports = { module.exports = {
name: 'add', name: 'add',
description: 'Add a member to a ticket channel', description: 'Add a member to a ticket channel',
@ -14,23 +15,23 @@ module.exports = {
const client = message.client; const client = message.client;
// command starts here // command starts here
message.delete(); message.delete();
if(!message.channel.name.startsWith('ticket-')) { if (!message.channel.name.startsWith('ticket-')) {
if(config.useEmbeds) { if (config.useEmbeds) {
const notTicket = new Discord.RichEmbed() const notTicket = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: **This command can only be used within a ticket channel**`) .setDescription(`:x: **This command can only be used within a ticket channel**`);
return message.channel.send(notTicket); return message.channel.send(notTicket);
} else { } else {
return message.channel.send(`:x: **This command can only be used within a ticket channel**`) 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])); let user = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!user) { if (!user) {
if(config.useEmbeds) { if (config.useEmbeds) {
const err1 = new Discord.RichEmbed() const err1 = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: **Unknown user.** Please mention a valid user.`) .setDescription(`:x: **Unknown user.** Please mention a valid user.`);
return message.channel.send(err1); return message.channel.send(err1);
} else { } else {
return message.channel.send(`:x: **Unknown user.** Please mention a valid user.`); return message.channel.send(`:x: **Unknown user.** Please mention a valid user.`);
@ -45,13 +46,13 @@ module.exports = {
if(config.useEmbeds) { if(config.useEmbeds) {
const added = new Discord.RichEmbed() const added = new Discord.RichEmbed()
.setColor(config.colour) .setColor(config.colour)
.setDescription(`${user} has been added.`) .setDescription(`${user} has been added.`);
message.channel.send(added); message.channel.send(added);
} else { } else {
message.channel.send(`${user} has been added.`); message.channel.send(`${user} has been added.`);
} }
// log // log
if(config.useEmbeds) { if (config.useEmbeds) {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
.setTitle("User Added") .setTitle("User Added")
@ -61,15 +62,14 @@ module.exports = {
.addField("Channel", message.channel, true) .addField("Channel", message.channel, true)
.setFooter(`DiscordTickets`) .setFooter(`DiscordTickets`)
.setTimestamp(); .setTimestamp();
client.channels.get(config.logChannel).send({embed}) client.channels.get(config.logChannel).send(embed);
} else { } else {
client.channels.get(config.logChannel).send(`User added to a ticket by **${message.author.tag} (${message.author.id})**`); 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})`) log.info(`${message.author.tag} added a user to a ticket (#${message.channel})`)
} catch(error) { } catch (error) {
log.error(error); log.error(error);
} }
// command ends here // command ends here
}, },
}; };

View File

@ -1,6 +1,7 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const config = require('../config.json'); const config = require('../config.json');
const log = require(`leekslazylogger`); const log = require(`leekslazylogger`);
module.exports = { module.exports = {
name: 'close', name: 'close',
description: 'Close a ticket', description: 'Close a ticket',
@ -18,16 +19,16 @@ module.exports = {
if(config.useEmbeds) { if(config.useEmbeds) {
const notTicket = new Discord.RichEmbed() const notTicket = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: **This command can only be used within a ticket channel**`) .setDescription(`:x: **This command can only be used within a ticket channel**`);
return message.channel.send(notTicket); return message.channel.send(notTicket);
} else { } else {
return message.channel.send(`:x: **This command can only be used within a ticket channel**`) return message.channel.send(`:x: **This command can only be used within a ticket channel**`);
} }
} else { } else {
try { try {
message.channel.delete() message.channel.delete();
// log // log
if(config.useEmbeds) { if (config.useEmbeds) {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
.setTitle("Ticket Closed") .setTitle("Ticket Closed")
@ -36,20 +37,15 @@ module.exports = {
.addField("Channel", message.channel.name, true) .addField("Channel", message.channel.name, true)
.setFooter(`DiscordTickets`) .setFooter(`DiscordTickets`)
.setTimestamp(); .setTimestamp();
client.channels.get(config.logChannel).send({embed}) client.channels.get(config.logChannel).send(embed);
} else { } else {
client.channels.get(config.logChannel).send(`Ticket closed by **${message.author.tag} (${message.author.id})**`); client.channels.get(config.logChannel).send(`Ticket closed by **${message.author.tag} (${message.author.id})**`);
} }
log.info(`${message.author.tag} closed a ticket (#${message.channel.name})`) log.info(`${message.author.tag} closed a ticket (#${message.channel.name})`);
} catch (error) {
} catch(error) {
log.error(log.colour.red(error)); log.error(log.colour.red(error));
} }
} }
// command ends here // command ends here
}, },
}; };

View File

@ -7,22 +7,15 @@ module.exports = {
description: 'Displays help menu', description: 'Displays help menu',
usage: '[command]', usage: '[command]',
aliases: ['command', 'commands'], aliases: ['command', 'commands'],
example: 'help new', example: 'help new',
args: false, args: false,
cooldown: config.cooldown, cooldown: config.cooldown,
guildOnly: true, guildOnly: true,
execute(message, args) { execute(message, args) {
const client = message.client;
// command starts here // command starts here
message.delete(); message.delete();
const data = [];
const data = []; const { commands } = message.client;
const { commands } = message.client;
if (config.useEmbeds) { if (config.useEmbeds) {
if (!args.length) { if (!args.length) {
@ -31,16 +24,16 @@ module.exports = {
data.push(`\nType \`${config.prefix}help [command]\` for more information about a specific command.`); data.push(`\nType \`${config.prefix}help [command]\` for more information about a specific command.`);
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setTitle("Commands") .setTitle("Commands")
.setColor(config.colour) .setColor(config.colour)
.setDescription(`\nType \`${config.prefix}help [command]\` for more information about a specific command.`) .setDescription(`\nType \`${config.prefix}help [command]\` for more information about a specific command.`)
// .addField("...", `...`, true) // .addField("...", `...`, true)
// .addField("...", `...`, true) // .addField("...", `...`, true)
.setFooter(`DiscordTickets by Eartharoid`); .setFooter(`DiscordTickets by Eartharoid`);
var cmds = []; let cmds = [];
cmds.push(commands.map(command => embed.addField(`${config.prefix}${command.name}`, `\`${command.description}\``))); cmds.push(commands.map(command => embed.addField(`${config.prefix}${command.name}`, `\`${command.description}\``)));
message.channel.send(embed) message.channel.send(embed)
.then(() => { .then(() => {
if (message.channel.type === 'dm') return; if (message.channel.type === 'dm') return;
// message.channel.send(`A list of commands has been sent to you.`); // message.channel.send(`A list of commands has been sent to you.`);
@ -57,28 +50,25 @@ module.exports = {
if (!command) { if (!command) {
const notCmd = new Discord.RichEmbed() const notCmd = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: **Invalid command name** (\`${config.prefix}help\`)`) .setDescription(`:x: **Invalid command name** (\`${config.prefix}help\`)`);
return message.channel.send(notCmd) return message.channel.send(notCmd);
} }
const cmd = new Discord.RichEmbed() const cmd = new Discord.RichEmbed()
.setColor(config.colour) .setColor(config.colour)
.addField(`Command`,`\`${command.name}\``, true) .addField(`Command`,`\`${command.name}\``, true)
.setFooter(`DiscordTickets by Eartharoid`); .setFooter(`DiscordTickets by Eartharoid`);
if (command.aliases) cmd.addField("Aliases", `\`${command.aliases.join(', ')}\``, true); if (command.aliases) cmd.addField("Aliases", `\`${command.aliases.join(', ')}\``, true);
if (command.description) cmd.addField("Description", `\`${command.description}\``, false); if (command.description) cmd.addField("Description", `\`${command.description}\``, false);
if (command.usage) cmd.addField("Usage", `\`${config.prefix}${command.name} ${command.usage}\``, 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); if (command.example) cmd.addField("Example", `\`${config.prefix}${command.example}\``, false);
message.channel.send(cmd) message.channel.send(cmd);
} }
} else { } else {
// message.channel.send(`**Prefix =** \`${config.prefix}\`\n**Bot Version =** \`${version}\``) // message.channel.send(`**Prefix =** \`${config.prefix}\`\n**Bot Version =** \`${version}\``)
if (!args.length) { if (!args.length) {
data.push('__**Commands**__'); data.push('__**Commands**__');
data.push(commands.map(command => `**${config.prefix}${command.name}** : \`${command.description}\``).join('\n')); data.push(commands.map(command => `**${config.prefix}${command.name}** : \`${command.description}\``).join('\n'));
@ -100,9 +90,7 @@ module.exports = {
const name = args[0].toLowerCase(); const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name)); const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));
if (!command) { if (!command) return message.reply(':x: **Invalid command**');
return message.reply(':x: **Invalid command**');
}
data.push(`**Command:** \`${command.name}\``); data.push(`**Command:** \`${command.name}\``);
@ -113,11 +101,8 @@ module.exports = {
data.push(`**Cooldown:** \`${command.cooldown || 3} second(s)\``); data.push(`**Cooldown:** \`${command.cooldown || 3} second(s)\``);
message.channel.send(data, { split: true }); message.channel.send(data, { split: true });
} }
// command ends here // command ends here
}, },
}; };

View File

@ -2,6 +2,7 @@ const Discord = require('discord.js');
const config = require('../config.json'); const config = require('../config.json');
const log = require(`leekslazylogger`); const log = require(`leekslazylogger`);
// const randomString = require('random-string'); // const randomString = require('random-string');
module.exports = { module.exports = {
name: 'new', name: 'new',
description: 'Create a new ticket', description: 'Create a new ticket',
@ -30,12 +31,11 @@ module.exports = {
if (config.useEmbeds) { if (config.useEmbeds) {
const err1 = new Discord.RichEmbed() const err1 = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: You already have an open ticket.`) .setDescription(`:x: You already have an open ticket.`);
return message.channel.send(err1) return message.channel.send(err1);
} else { } else {
message.channel.send(`:x: You already have an open ticket.`) message.channel.send(`:x: You already have an open ticket.`);
} }
}; };
message.guild.createChannel(`ticket-${id}`, { message.guild.createChannel(`ticket-${id}`, {
@ -46,7 +46,6 @@ module.exports = {
let supportRole = message.guild.roles.get(config.supportRole) let supportRole = message.guild.roles.get(config.supportRole)
if (!supportRole) return message.channel.send(":x: No **Support Team** role found."); if (!supportRole) return message.channel.send(":x: No **Support Team** role found.");
c.overwritePermissions(message.guild.defaultRole, { c.overwritePermissions(message.guild.defaultRole, {
VIEW_CHANNEL: false, VIEW_CHANNEL: false,
SEND_MESSAGES: false SEND_MESSAGES: false
@ -80,20 +79,18 @@ module.exports = {
.setTimestamp(); .setTimestamp();
const welcome = new Discord.RichEmbed() const welcome = new Discord.RichEmbed()
.setColor(config.colour) .setColor(config.colour)
.setDescription(`**Ticket topic:** \`${topic}\`\n\n${config.ticketText}`) .setDescription(`**Ticket topic:** \`${topic}\`\n\n${config.ticketText}`);
if (config.useEmbeds) { if (config.useEmbeds) {
message.channel.send(created) message.channel.send(created);
let w = await c.send(welcome) let w = await c.send(welcome);
await w.pin(); await w.pin();
// c.fetchMessage(c.lastMessageID).delete() // c.fetchMessage(c.lastMessageID).delete()
} else { } else {
message.channel.send(`Your ticket (${c}) has been created.\nPlease read the information sent and follow any instructions given.`) message.channel.send(`Your ticket (${c}) has been created.\nPlease read the information sent and follow any instructions given.`);
let w = await c.send(`**Ticket topic:** \`${topic}\`\n\n${config.ticketText}`) let w = await c.send(`**Ticket topic:** \`${topic}\`\n\n${config.ticketText}`);
await w.pin() await w.pin();
// c.fetchMessage(c.lastMessageID).delete() // c.fetchMessage(c.lastMessageID).delete()
} }
// log // log
if (config.useEmbeds) { if (config.useEmbeds) {
@ -106,19 +103,12 @@ module.exports = {
.addField("Channel", c, true) .addField("Channel", c, true)
.setFooter(`DiscordTickets`) .setFooter(`DiscordTickets`)
.setTimestamp(); .setTimestamp();
client.channels.get(config.logChannel).send({ client.channels.get(config.logChannel).send(embed);
embed
})
} else { } else {
client.channels.get(config.logChannel).send(`New ticket created by **${message.author.tag} (${message.author.id})**`); client.channels.get(config.logChannel).send(`New ticket created by **${message.author.tag} (${message.author.id})**`);
} }
log.info(`${message.author.tag} created a new ticket (#ticket-${id})`) log.info(`${message.author.tag} created a new ticket (#ticket-${id})`);
}) });
// command ends here // command ends here
}, },
}; };

View File

@ -1,6 +1,6 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const config = require('../config.json'); const config = require('../config.json');
const log = require(`leekslazylogger`);
module.exports = { module.exports = {
name: 'ping', name: 'ping',
description: 'Calculate latency', description: 'Calculate latency',
@ -11,7 +11,6 @@ module.exports = {
cooldown: config.cooldown, cooldown: config.cooldown,
guildOnly: true, guildOnly: true,
execute(message, args) { execute(message, args) {
const client = message.client;
// command starts here // command starts here
message.delete(); message.delete();
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
@ -19,11 +18,7 @@ module.exports = {
.setColor(config.colour) .setColor(config.colour)
.setTimestamp() .setTimestamp()
.addField("API Latency", `${Math.round(message.client.ping)}ms`, true) .addField("API Latency", `${Math.round(message.client.ping)}ms`, true)
message.channel.send({embed}) message.channel.send(embed);
// command ends here // command ends here
}, },
}; };

View File

@ -1,6 +1,7 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const config = require('../config.json'); const config = require('../config.json');
const log = require(`leekslazylogger`); const log = require(`leekslazylogger`);
module.exports = { module.exports = {
name: 'remove', name: 'remove',
description: 'Remove a member from a ticket', description: 'Remove a member from a ticket',
@ -14,8 +15,8 @@ module.exports = {
const client = message.client; const client = message.client;
// command starts here // command starts here
message.delete(); message.delete();
if(!message.channel.name.startsWith('ticket-')) { if (!message.channel.name.startsWith('ticket-')) {
if(config.useEmbeds) { if (config.useEmbeds) {
const notTicket = new Discord.RichEmbed() const notTicket = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: **This command can only be used within a ticket channel**`) .setDescription(`:x: **This command can only be used within a ticket channel**`)
@ -26,8 +27,8 @@ module.exports = {
} }
let user = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0])); let user = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!user) { if (!user) {
if(config.useEmbeds) { if (config.useEmbeds) {
const err1 = new Discord.RichEmbed() const err1 = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: **Unknown user.** Please mention a valid user.`) .setDescription(`:x: **Unknown user.** Please mention a valid user.`)
@ -41,7 +42,7 @@ module.exports = {
SEND_MESSAGES: false, SEND_MESSAGES: false,
READ_MESSAGES: false READ_MESSAGES: false
}); });
if(config.useEmbeds) { if (config.useEmbeds) {
const removed = new Discord.RichEmbed() const removed = new Discord.RichEmbed()
.setColor(config.colour) .setColor(config.colour)
.setDescription(`${user} has been removed.`) .setDescription(`${user} has been removed.`)
@ -50,7 +51,7 @@ module.exports = {
message.channel.send(`${user} has been removed.`); message.channel.send(`${user} has been removed.`);
} }
// log // log
if(config.useEmbeds) { if (config.useEmbeds) {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
.setTitle("User Removed") .setTitle("User Removed")
@ -60,7 +61,8 @@ module.exports = {
.addField("Channel", message.channel, true) .addField("Channel", message.channel, true)
.setFooter(`DiscordTickets`) .setFooter(`DiscordTickets`)
.setTimestamp(); .setTimestamp();
client.channels.get(config.logChannel).send({embed})
client.channels.get(config.logChannel).send(embed);
} else { } else {
client.channels.get(config.logChannel).send(`User removed to a ticket by **${message.author.tag} (${message.author.id})**`); client.channels.get(config.logChannel).send(`User removed to a ticket by **${message.author.tag} (${message.author.id})**`);
} }

View File

@ -21,9 +21,9 @@
Quick Start Quick Start
--------------------- ---------------------
> For detailed instructions, visit the github repository and read the documentation. > For detailed instructions, visit the Github repository and read the documentation.
> Assuming you have created discord application, edit 'config.json' to allow the bot to > Assuming you have created a Discord application, edit 'config.json' to allow the bot to
function correctly. function correctly.
> You will need your bot token (keep it a secret) and channel & role IDs from your server > You will need your bot token (keep it a secret) and channel & role IDs from your server
@ -34,10 +34,10 @@
=============================================================================================== ===============================================================================================
> For support, visit https://github.com/eartharoid/DiscordTickets/#readme > For support, visit https://github.com/eartharoid/DiscordTickets/#readme
> My website: https://eartharoid.ml > My website: https://eartharoid.me
@name DiscordTickets @name DiscordTickets
@author Eartharoid <eartharoid@gmail.com> @author Eartharoid <contact@eartharoid.me>
@license GNU-GPLv3 @license GNU-GPLv3
############################################################################################### ###############################################################################################
@ -78,18 +78,19 @@ console.log(log.colour.yellow(leeks.styles.bold(homepage)));
console.log('\n\n'); console.log('\n\n');
console.log(log.colour.bgGrey(log.colour.grey(`\n\n==========================================================================\n\n`))) console.log(log.colour.bgGrey(log.colour.grey(`\n\n==========================================================================\n\n`)))
console.log('\n\n'); console.log('\n\n');
log.init('DiscordTickets (bot created by Eartharoid)') log.init('DiscordTickets (bot created by Eartharoid)');
// all log.* functions are logged to ./log/file.log from here onwards // all log.* functions are logged to ./log/file.log from here onwards
log.info(`Starting up...`) log.info(`Starting up...`);
client.once('ready', () => { // after bot has logged in client.once('ready', () => { // after bot has logged in
log.info(`Initialising bot...`) log.info(`Initialising bot...`);
for (const file of commands) { for (const file of commands) {
const command = require(`./commands/${file}`); const command = require(`./commands/${file}`);
client.commands.set(command.name, command); client.commands.set(command.name, command);
log.console(`> Loading '${config.prefix}${command.name}' command`); log.console(`> Loading '${config.prefix}${command.name}' command`);
} }
log.success(`Connected to Discord API`) log.success(`Connected to Discord API`)
log.success(`Logged in as ${client.user.tag}`) log.success(`Logged in as ${client.user.tag}`)
client.user.setPresence({game: {name: config.playing, type: config.activityType},status: config.status}) client.user.setPresence({game: {name: config.playing, type: config.activityType},status: config.status})
@ -104,13 +105,12 @@ client.once('ready', () => { // after bot has logged in
.setFooter(`DiscordTickets by Eartharoid`); .setFooter(`DiscordTickets by Eartharoid`);
client.channels.get(config.logChannel).send(embed) client.channels.get(config.logChannel).send(embed)
} else { } else {
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**") client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**");
} }
if (client.guilds.get(config.guildID).member(client.user).hasPermission("ADMINISTRATOR", false)) { if (client.guilds.get(config.guildID).member(client.user).hasPermission("ADMINISTRATOR", false)) {
log.info(`Checking permissions...`); log.info(`Checking permissions...`);
setTimeout(function() { setTimeout(() => log.success(`Required permissions have been granted\n\n`), 1250);
log.success(`Required permissions have been granted\n\n`)
}, 1250);
if (config.useEmbeds) { if (config.useEmbeds) {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
@ -118,30 +118,30 @@ client.once('ready', () => { // after bot has logged in
.setColor("#2ECC71") .setColor("#2ECC71")
.setDescription(":white_check_mark: **Required permissions have been granted**") .setDescription(":white_check_mark: **Required permissions have been granted**")
.setFooter(`DiscordTickets by Eartharoid`); .setFooter(`DiscordTickets by Eartharoid`);
client.channels.get(config.logChannel).send(embed)
client.channels.get(config.logChannel).send(embed);
} else { } else {
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**") client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
} }
} else { } else {
log.error(`Required permissions have not been granted`) log.error(`Required permissions have not been granted`);
log.error(`Please give the bot the 'ADMINISTRATOR' permission\n\n`) log.error(`Please give the bot the 'ADMINISTRATOR' permission\n\n`);
if (config.useEmbeds) { if (config.useEmbeds) {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(":x: **Required permissions have not been granted**\nPlease give the bot the `ADMINISTRATOR` permission") .setDescription(":x: **Required permissions have not been granted**\nPlease give the bot the `ADMINISTRATOR` permission")
.setFooter(`DiscordTickets by Eartharoid`); .setFooter(`DiscordTickets by Eartharoid`);
client.channels.get(config.logChannel).send({
embed client.channels.get(config.logChannel).send(embed);
})
} else { } else {
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**") client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**");
} }
} }
}); });
client.on('message', async message => { client.on('message', async (message) => {
// if (!message.content.startsWith(config.prefix) || message.author.bot) return; // if (!message.content.startsWith(config.prefix) || message.author.bot) return;
if (message.author.bot) return; if (message.author.bot) return;
if (message.channel.type === "dm") { if (message.channel.type === "dm") {
@ -159,16 +159,10 @@ client.on('message', async message => {
} else { } else {
client.channels.get(config.logChannel).send(`DM received from **${message.author.tag} (${message.author.id})** : \n\n\`\`\`${message.content}\`\`\``); client.channels.get(config.logChannel).send(`DM received from **${message.author.tag} (${message.author.id})** : \n\n\`\`\`${message.content}\`\`\``);
} }
} else { } else return;
return
};
} }
if (message.channel.bot) return;
// const args = message.content.slice(config.prefix.length).split(/ +/); // const args = message.content.slice(config.prefix.length).split(/ +/);
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|\\${config.prefix})\\s*`); const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|\\${config.prefix})\\s*`);
if (!prefixRegex.test(message.content)) return; if (!prefixRegex.test(message.content)) return;
const [, matchedPrefix] = message.content.match(prefixRegex); const [, matchedPrefix] = message.content.match(prefixRegex);
@ -176,14 +170,9 @@ client.on('message', async message => {
const commandName = args.shift().toLowerCase(); const commandName = args.shift().toLowerCase();
// if (!client.commands.has(commandName)) return; // if (!client.commands.has(commandName)) return;
// const command = client.commands.get(commandName); // const command = client.commands.get(commandName);
const command = client.commands.get(commandName) const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return; 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.guildOnly && message.channel.type !== 'text') {
return message.channel.send(`Sorry, this command can only be used on the server.`)
}
if (command.args && !args.length) { if (command.args && !args.length) {
// let reply = `:x: **Arguments were expected but none were provided.**`; // let reply = `:x: **Arguments were expected but none were provided.**`;
@ -196,18 +185,14 @@ client.on('message', async message => {
if (config.useEmbeds) { if (config.useEmbeds) {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`\n**Usage:** \`${config.prefix}${command.name} ${command.usage}\`\nType \`${config.prefix}help ${command.name}\` for more information`) .setDescription(`\n**Usage:** \`${config.prefix}${command.name} ${command.usage}\`\nType \`${config.prefix}help ${command.name}\` for more information`);
return message.channel.send({embed}) return message.channel.send(embed);
} else { } else {
return message.channel.send(`**Usage:** \`${config.prefix}${command.name} ${command.usage}\`\nType \`${config.prefix}help ${command.name}\` for more information`) return message.channel.send(`**Usage:** \`${config.prefix}${command.name} ${command.usage}\`\nType \`${config.prefix}help ${command.name}\` for more information`);
} }
}; };
if (!cooldowns.has(command.name)) cooldowns.set(command.name, new Discord.Collection());
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Discord.Collection());
}
const timestamps = cooldowns.get(command.name); const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || 3) * 1000; const cooldownAmount = (command.cooldown || 3) * 1000;
@ -221,11 +206,10 @@ client.on('message', async message => {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setColor("#E74C3C") .setColor("#E74C3C")
.setDescription(`:x: **Please do not spam commands** (wait ${timeLeft.toFixed(1)}s)`) .setDescription(`:x: **Please do not spam commands** (wait ${timeLeft.toFixed(1)}s)`)
return message.channel.send({embed}) return message.channel.send(embed);
} else { } else {
return message.reply(`please do not spam commands (wait ${timeLeft.toFixed(1)}s)`); return message.reply(`please do not spam commands (wait ${timeLeft.toFixed(1)}s)`);
} }
} }
} }
timestamps.set(message.author.id, now); timestamps.set(message.author.id, now);
@ -235,7 +219,7 @@ client.on('message', async message => {
try { try {
// client.commands.get(command).execute(message, args, config); // client.commands.get(command).execute(message, args, config);
command.execute(message, args); command.execute(message, args);
if(config.useEmbeds) { if (config.useEmbeds) {
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Command Log`, client.user.avatarURL) .setAuthor(`${client.user.username} / Command Log`, client.user.avatarURL)
.setTitle("Command Used") .setTitle("Command Used")
@ -243,7 +227,7 @@ client.on('message', async message => {
.addField("Command", command.name, true) .addField("Command", command.name, true)
.setFooter(`DiscordTickets`) .setFooter(`DiscordTickets`)
.setTimestamp(); .setTimestamp();
client.channels.get(config.logChannel).send({embed}) client.channels.get(config.logChannel).send(embed);
} else { } else {
client.channels.get(config.logChannel).send(`**${message.author.tag} (${message.author.id})** used the \`${command.name}\` command`); client.channels.get(config.logChannel).send(`**${message.author.tag} (${message.author.id})** used the \`${command.name}\` command`);
} }
@ -253,23 +237,25 @@ client.on('message', async message => {
message.channel.send(`:x: **Oof!** An error occured whilst executing that command.\nThe issue has been reported.`); message.channel.send(`:x: **Oof!** An error occured whilst executing that command.\nThe issue has been reported.`);
log.error(`An unknown error occured whilst executing the '${command.name}' command`); log.error(`An unknown error occured whilst executing the '${command.name}' command`);
} }
}); });
client.on('error', error => {
client.on('error', (error) => {
log.warn(`Potential error detected\n(likely Discord API connection issue)\n`); log.warn(`Potential error detected\n(likely Discord API connection issue)\n`);
log.error(`Client error:\n${error}`); log.error(`Client error:\n${error}`);
}); });
client.on('warn', (e) => log.warn(`${e}`)); client.on('warn', (e) => log.warn(`${e}`));
if(config.debugLevel == 1){ client.on('debug', (e) => log.debug(`${e}`)) }; if (config.debugLevel == 1) client.on('debug', (e) => log.debug(`${e}`));
process.on('unhandledRejection', error => { process.on('unhandledRejection', (error) => {
log.warn(`An error was not caught`); log.warn(`An error was not caught`);
log.error(`Uncaught error: \n${error.stack}`); log.error(`Uncaught error: \n${error.stack}`);
}); });
process.on('beforeExit', (code) => { process.on('beforeExit', (code) => {
log.basic(log.colour.yellowBright(`Disconected from Discord API`)); log.basic(log.colour.yellowBright(`Disconected from Discord API`));
log.basic(`Exiting (${code})`); log.basic(`Exiting (${code})`);
}); });
client.login(config.token); client.login(config.token);

View File

@ -1,13 +1,12 @@
{ {
"name": "DiscordTickets", "name": "discordtickets",
"version": "1.1.5", "version": "1.1.5",
"description": "A Discord ticket/support - an open-source & self-hosted bot", "description": "A Discord ticket/support - an open-source & self-hosted bot",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"discord.js": "11.x", "discord.js": "11.x",
"leekslazylogger": "^1.1.7" "leekslazylogger": "^1.1.9"
}, },
"devDependencies": {},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },