consistency

This commit is contained in:
David Ralph
2020-10-03 17:18:07 +01:00
parent b0ad6b7c88
commit 4c163443cd
23 changed files with 110 additions and 168 deletions

View File

@@ -18,7 +18,6 @@ module.exports = {
example: 'add @member to #ticket-23',
args: true,
async execute(client, message, args, {config, Ticket}) {
const guild = client.guilds.cache.get(config.guild);
const notTicket = new MessageEmbed()
@@ -37,8 +36,7 @@ module.exports = {
if (!channel) {
channel = message.channel;
ticket = await Ticket.findOne({ where: { channel: message.channel.id } });
if(!ticket)
return message.channel.send(notTicket);
if (!ticket) return message.channel.send(notTicket);
} else {
ticket = await Ticket.findOne({ where: { channel: channel.id } });
@@ -50,7 +48,7 @@ module.exports = {
}
}
if(message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -61,10 +59,11 @@ module.exports = {
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
.setFooter(guild.name, guild.iconURL())
);
}
let member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
if (!member)
if (!member) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -75,6 +74,7 @@ module.exports = {
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
.setFooter(guild.name, guild.iconURL())
);
}
try {
channel.updateOverwrite(member.user, {
@@ -84,7 +84,7 @@ module.exports = {
READ_MESSAGE_HISTORY: true
});
if (channel.id !== message.channel.id)
if (channel.id !== message.channel.id) {
channel.send(
new MessageEmbed()
.setColor(config.colour)
@@ -93,7 +93,7 @@ module.exports = {
.setDescription(`${member} has been added by ${message.author}`)
.setFooter(guild.name, guild.iconURL())
);
}
message.channel.send(
new MessageEmbed()

View File

@@ -21,11 +21,7 @@ module.exports = {
aliases: ['none'],
example: 'close #ticket-17',
args: false,
async execute(client, message, args, {
config,
Ticket
}) {
async execute(client, message, args, { config, Ticket }) {
const guild = client.guilds.cache.get(config.guild);
const notTicket = new MessageEmbed()
@@ -49,11 +45,8 @@ module.exports = {
channel: channel.id
}
});
if (!ticket)
return channel.send(notTicket);
if (!ticket) return channel.send(notTicket);
} else {
ticket = await Ticket.findOne({
where: {
channel: channel.id
@@ -102,7 +95,7 @@ module.exports = {
});
collector.on('collect', async () => {
if (channel.id !== message.channel.id)
if (channel.id !== message.channel.id) {
channel.send(
new MessageEmbed()
.setColor(config.colour)
@@ -111,6 +104,7 @@ module.exports = {
.setDescription(`Ticket closed by ${message.author}`)
.setFooter(guild.name, guild.iconURL())
);
}
confirm.reactions.removeAll();
confirm.edit(
@@ -149,15 +143,13 @@ module.exports = {
}];
}
if (
fs.existsSync(`user/transcripts/raw/${ticket.get('channel')}.log`)
&&
fs.existsSync(`user/transcripts/raw/entities/${ticket.get('channel')}.json`)
)
if (fs.existsSync(`user/transcripts/raw/${ticket.get('channel')}.log`) && fs.existsSync(`user/transcripts/raw/entities/${ticket.get('channel')}.json`)) {
embed.addField('Web archive', await archive.export(Ticket, channel));
}
if (embed.fields.length < 1)
if (embed.fields.length < 1) {
embed.setDescription(`No text transcripts or archive data exists for ticket ${ticket.id}`);
}
res.embed = embed;
@@ -165,7 +157,6 @@ module.exports = {
}
}
// update database
success = true;
ticket.update({
@@ -186,7 +177,7 @@ module.exports = {
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`);
if (config.logs.discord.enabled)
if (config.logs.discord.enabled) {
client.channels.cache.get(config.logs.discord.channel).send(
new MessageEmbed()
.setColor(config.colour)
@@ -197,6 +188,7 @@ module.exports = {
.setFooter(guild.name, guild.iconURL())
.setTimestamp()
);
}
});

View File

@@ -24,7 +24,6 @@ module.exports = {
config,
Ticket
}) {
const guild = client.guilds.cache.get(config.guild);
const notTicket = new MessageEmbed()
@@ -48,11 +47,9 @@ module.exports = {
channel: channel.id
}
});
if (!ticket)
return channel.send(notTicket);
if (!ticket) return channel.send(notTicket);
} else {
ticket = await Ticket.findOne({
where: {
channel: channel.id
@@ -65,7 +62,7 @@ module.exports = {
return message.channel.send(notTicket);
}
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) {
return channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -76,6 +73,7 @@ module.exports = {
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
.setFooter(guild.name, guild.iconURL())
);
}
}
let success;
@@ -124,14 +122,9 @@ module.exports = {
raw = `user/transcripts/raw/${ticket.get('channel')}.log`,
json = `user/transcripts/raw/entities/${ticket.get('channel')}.json`;
if (fs.existsSync(txt))
fs.unlinkSync(txt);
if (fs.existsSync(raw))
fs.unlinkSync(raw);
if (fs.existsSync(json))
fs.unlinkSync(json);
if (fs.existsSync(txt)) fs.unlinkSync(txt);
if (fs.existsSync(raw)) fs.unlinkSync(raw);
if (fs.existsSync(json)) fs.unlinkSync(json);
// update database
success = true;
@@ -147,7 +140,7 @@ module.exports = {
log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`);
if (config.logs.discord.enabled)
if (config.logs.discord.enabled) {
client.channels.cache.get(config.logs.discord.channel).send(
new MessageEmbed()
.setColor(config.colour)
@@ -158,6 +151,7 @@ module.exports = {
.setFooter(guild.name, guild.iconURL())
.setTimestamp()
);
}
});

View File

@@ -18,7 +18,6 @@ module.exports = {
example: 'help new',
args: false,
execute(client, message, args, {config}) {
const guild = client.guilds.cache.get(config.guild);
const commands = Array.from(client.commands.values());
@@ -27,15 +26,12 @@ module.exports = {
let cmds = [];
for (let command of commands) {
if (command.hide)
continue;
if (command.permission && !message.member.hasPermission(command.permission))
continue;
if (command.hide) continue;
if (command.permission && !message.member.hasPermission(command.permission)) continue;
let desc = command.description;
if (desc.length > 50)
desc = desc.substring(0, 50) + '...';
if (desc.length > 50) desc = desc.substring(0, 50) + '...';
cmds.push(`**${config.prefix}${command.name}** **·** ${desc}`);
}
@@ -71,11 +67,9 @@ module.exports = {
.setTitle(command.name);
if (command.long) {
cmd.setDescription(command.long);
} else {
cmd.setDescription(command.description);
}
if (command.long) cmd.setDescription(command.long);
else cmd.setDescription(command.description);
if (command.aliases) cmd.addField('Aliases', `\`${command.aliases.join(', ')}\``, true);
if (command.usage) cmd.addField('Usage', `\`${config.prefix}${command.name} ${command.usage}\``, false);
@@ -85,12 +79,9 @@ module.exports = {
if (command.permission && !message.member.hasPermission(command.permission)) {
cmd.addField('Required Permission', `\`${command.permission}\` :exclamation: You don't have permission to use this command`, true);
} else {
cmd.addField('Required Permission', `\`${command.permission || 'none'}\``, true);
}
} else cmd.addField('Required Permission', `\`${command.permission || 'none'}\``, true);
message.channel.send(cmd);
}
// command ends here

View File

@@ -19,7 +19,6 @@ module.exports = {
example: 'new my server won\'t start',
args: false,
async execute(client, message, args, {config, Ticket}) {
const guild = client.guilds.cache.get(config.guild);
const supportRole = guild.roles.cache.get(config.staff_role);
@@ -43,7 +42,7 @@ module.exports = {
if (tickets.count >= config.tickets.max) {
let ticketList = [];
for (let t in tickets.rows) {
for (let t in tickets.rows) {
let desc = tickets.rows[t].topic.substring(0, 30);
ticketList
.push(`<#${tickets.rows[t].channel}>: \`${desc}${desc.length > 30 ? '...' : ''}\``);
@@ -75,9 +74,7 @@ module.exports = {
.setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.')
.setFooter(guild.name, guild.iconURL())
);
else if (topic.length < 1)
topic = 'No topic given';
else if (topic.length < 1) topic = 'No topic given';
let ticket = await Ticket.create({
channel: '',
@@ -175,9 +172,8 @@ module.exports = {
.setFooter(guild.name, guild.iconURL())
);
if (config.tickets.pin)
await w.pin();
// await w.pin().then(m => m.delete()); // oopsie, this deletes the pinned message
if (config.tickets.pin) await w.pin();
// await w.pin().then(m => m.delete()); // oopsie, this deletes the pinned message
if (config.logs.discord.enabled)
client.channels.cache.get(config.logs.discord.channel).send(

View File

@@ -18,19 +18,19 @@ module.exports = {
example: '',
args: false,
permission: 'MANAGE_GUILD',
async execute(client, message, args, {config, Setting}) {
async execute(client, message, _args, {config, Setting}) {
const guild = client.guilds.cache.get(config.guild);
let msgID = await Setting.findOne({ where: { key: 'panel_msg_id' } });
let chanID = await Setting.findOne({ where: { key: 'panel_chan_id' } });
let panel;
if (!chanID)
if (!chanID) {
chanID = await Setting.create({
key: 'panel_chan_id',
value: message.channel.id,
});
}
if (!msgID) {
msgID = await Setting.create({
@@ -40,12 +40,12 @@ module.exports = {
} else {
try {
panel = await client.channels.cache.get(chanID.get('value')).messages.fetch(msgID.get('value')); // get old panel message
if (panel)
if (panel) {
panel.delete({ reason: 'Creating new panel/widget' }).then(() => log.info('Deleted old panel')).catch(e => log.warn(e)); // delete old panel
}
} catch (e) {
log.warn('Couldn\'t delete old panel');
}
}
message.delete();

View File

@@ -18,7 +18,6 @@ module.exports = {
example: 'remove @member from #ticket-23',
args: true,
async execute(client, message, args, {config, Ticket}) {
const guild = client.guilds.cache.get(config.guild);
const notTicket = new MessageEmbed()
@@ -44,7 +43,7 @@ module.exports = {
} else {
ticket = await Ticket.findOne({ where: { channel: channel.id } });
if(!ticket) {
if (!ticket) {
notTicket
.setTitle(':x: **Channel is not a ticket**')
.setDescription(`${channel} is not a ticket channel.`);
@@ -52,7 +51,7 @@ module.exports = {
}
}
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -63,12 +62,11 @@ module.exports = {
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
.setFooter(guild.name, guild.iconURL())
);
}
let member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
if(!member || member.id === message.author.id || member.id === guild.me.id)
if (!member || member.id === message.author.id || member.id === guild.me.id)
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -88,7 +86,7 @@ module.exports = {
READ_MESSAGE_HISTORY: false
});
if(channel.id !== message.channel.id)
if (channel.id !== message.channel.id) {
channel.send(
new MessageEmbed()
.setColor(config.colour)
@@ -97,8 +95,7 @@ module.exports = {
.setDescription(`${member} has been removed by ${message.author}`)
.setFooter(guild.name, guild.iconURL())
);
}
message.channel.send(
new MessageEmbed()

View File

@@ -15,8 +15,7 @@ module.exports = {
aliases: ['data', 'statistics'],
example: '',
args: false,
async execute(client, message, args, {config, Ticket}) {
async execute(client, message, _args, {config, Ticket}) {
const guild = client.guilds.cache.get(config.guild);
let open = await Ticket.count({ where: { open: true } });

View File

@@ -17,11 +17,10 @@ module.exports = {
example: '',
args: false,
async execute(client, message, args, {config, Ticket}) {
const guild = client.guilds.cache.get(config.guild);
const supportRole = guild.roles.cache.get(config.staff_role);
if (!supportRole)
if (!supportRole) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -29,12 +28,13 @@ module.exports = {
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
.setFooter(guild.name, guild.iconURL())
);
}
let context = 'self';
let user = message.mentions.users.first() || guild.members.cache.get(args[0]);
if(user) {
if(!message.member.roles.cache.has(config.staff_role))
if (user) {
if (!message.member.roles.cache.has(config.staff_role)) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -45,12 +45,10 @@ module.exports = {
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
.setFooter(guild.name, guild.iconURL())
);
}
context = 'staff';
} else {
user = message.author;
}
} else user = message.author;
let openTickets = await Ticket.findAndCountAll({
where: {
@@ -74,8 +72,9 @@ module.exports = {
.setTitle(`${context === 'self' ? 'Your' : user.username + '\'s'} tickets`)
.setFooter(guild.name + ' | This message will be deleted in 60 seconds', guild.iconURL());
if(config.transcripts.web.enabled)
if (config.transcripts.web.enabled) {
embed.setDescription(`You can access all of your ticket archives on the [web portal](${config.transcripts.web.server}/${user.id}).`);
}
let open = [],
closed = [];
@@ -89,12 +88,14 @@ module.exports = {
let desc = closedTickets.rows[t].topic.substring(0, 30);
let transcript = '';
let c = closedTickets.rows[t].channel;
if(fs.existsSync(`user/transcripts/text/${c}.txt`) || config.transcripts.web.enabled)
if (fs.existsSync(`user/transcripts/text/${c}.txt`) || config.transcripts.web.enabled) {
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to view.`;
}
closed.push(`> **#${closedTickets.rows[t].id}**: \`${desc}${desc.length > 20 ? '...' : ''}\`${transcript}`);
}
let pre = context === 'self' ? 'You have' : user.username + ' has';
embed.addField('Open tickets', openTickets.count === 0 ? `${pre} no open tickets.` : open.join('\n\n'), false);
embed.addField('Closed tickets', closedTickets.count === 0 ? `${pre} no old tickets` : closed.join('\n\n'), false);

View File

@@ -16,7 +16,6 @@ module.exports = {
example: 'topic need help error',
args: true,
async execute(client, message, args, {config, Ticket}) {
const guild = client.guilds.cache.get(config.guild);
let ticket = await Ticket.findOne({
@@ -25,7 +24,7 @@ module.exports = {
}
});
if (!ticket)
if (!ticket) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -36,10 +35,10 @@ module.exports = {
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
.setFooter(guild.name, guild.iconURL())
);
}
let topic = args.join(' ');
if (topic.length > 256)
if (topic.length > 256) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -48,6 +47,7 @@ module.exports = {
.setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.')
.setFooter(guild.name, guild.iconURL())
);
}
message.channel.setTopic(`<@${ticket.creator}> | ` + topic);
@@ -59,7 +59,6 @@ module.exports = {
}
});
message.channel.send(
new MessageEmbed()
.setColor(config.colour)

View File

@@ -19,7 +19,6 @@ module.exports = {
example: 'transcript 57',
args: true,
async execute(client, message, args, {config, Ticket}) {
const guild = client.guilds.cache.get(config.guild);
const id = args[0];
@@ -31,7 +30,7 @@ module.exports = {
});
if (!ticket)
if (!ticket) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -40,8 +39,9 @@ module.exports = {
.setDescription('Couldn\'t find a closed ticket with that ID')
.setFooter(guild.name, guild.iconURL())
);
}
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) {
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@@ -50,6 +50,8 @@ module.exports = {
.setDescription(`You don't have permission to view ticket ${id} as it does not belong to you and you are not staff.`)
.setFooter(guild.name, guild.iconURL())
);
}
let res = {};
const embed = new MessageEmbed()
.setColor(config.colour)
@@ -69,11 +71,9 @@ module.exports = {
const BASE_URL = config.transcripts.web.server;
if (config.transcripts.web.enabled)
embed.addField('Web archive', `${BASE_URL}/${ticket.creator}/${ticket.channel}`);
if (config.transcripts.web.enabled) embed.addField('Web archive', `${BASE_URL}/${ticket.creator}/${ticket.channel}`);
if (embed.fields.length < 1)
embed.setDescription(`No text transcripts or archive data exists for ticket ${id}`);
if (embed.fields.length < 1) embed.setDescription(`No text transcripts or archive data exists for ticket ${id}`);
res.embed = embed;
@@ -85,8 +85,7 @@ module.exports = {
}
channel.send(res).then(m => {
if (channel.id === message.channel.id)
m.delete({timeout: 15000});
if (channel.id === message.channel.id) m.delete({timeout: 15000});
});
message.delete({timeout: 1500});
}