Make @davidjcralph happy

const
This commit is contained in:
Isaac 2021-05-18 18:12:07 +01:00
parent 37adac1dd0
commit 8a15f34342
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
31 changed files with 176 additions and 167 deletions

View File

@ -34,11 +34,11 @@ module.exports = class AddCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let ticket = message.mentions.channels.first() ?? message.channel; const ticket = message.mentions.channels.first() ?? message.channel;
let t_row = await this.client.tickets.resolve(ticket.id, message.guild.id); const t_row = await this.client.tickets.resolve(ticket.id, message.guild.id);
if (!t_row) { if (!t_row) {
return await message.channel.send( return await message.channel.send(
@ -50,7 +50,7 @@ module.exports = class AddCommand extends Command {
); );
} }
let member = message.mentions.members.first() ?? message.guild.members.cache.get(args); const member = message.mentions.members.first() ?? message.guild.members.cache.get(args);
if (!member) { if (!member) {
return await message.channel.send( return await message.channel.send(

View File

@ -31,10 +31,10 @@ module.exports = class BlacklistCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let member = message.mentions.members.first(); const member = message.mentions.members.first();
if (member && (await member.isStaff() || member.hasPermission(this.permissions))) { if (member && (await member.isStaff() || member.hasPermission(this.permissions))) {
return await message.channel.send( return await message.channel.send(
@ -47,9 +47,9 @@ module.exports = class BlacklistCommand extends Command {
} }
let role = message.mentions.roles.first(); const role = message.mentions.roles.first();
let id; let id;
let input = args.trim().split(/\s/g)[0]; const input = args.trim().split(/\s/g)[0];
if (member) id = member.id; if (member) id = member.id;
else if (role) id = role.id; else if (role) id = role.id;
@ -64,7 +64,7 @@ module.exports = class BlacklistCommand extends Command {
); );
} else { } else {
// list blacklisted members // list blacklisted members
let blacklist = settings.blacklist.map(element => { const blacklist = settings.blacklist.map(element => {
const is_role = message.guild.roles.cache.has(element); const is_role = message.guild.roles.cache.has(element);
if (is_role) return `» <@&${element}> (\`${element}\`)`; if (is_role) return `» <@&${element}> (\`${element}\`)`;
else return `» <@${element}> (\`${element}\`)`; else return `» <@${element}> (\`${element}\`)`;
@ -79,10 +79,10 @@ module.exports = class BlacklistCommand extends Command {
} }
const is_role = role !== undefined || message.guild.roles.cache.has(id); const is_role = role !== undefined || message.guild.roles.cache.has(id);
let member_or_role = is_role ? 'role' : 'member'; const member_or_role = is_role ? 'role' : 'member';
let index = settings.blacklist.findIndex(element => element === id); const index = settings.blacklist.findIndex(element => element === id);
let new_blacklist = [ ...settings.blacklist]; const new_blacklist = [ ...settings.blacklist ];
if (index === -1) { if (index === -1) {
new_blacklist.push(id); new_blacklist.push(id);

View File

@ -59,7 +59,7 @@ module.exports = class CloseCommand extends Command {
const arg_reason = this.args[1].name; const arg_reason = this.args[1].name;
const arg_time = this.args[2].name; const arg_time = this.args[2].name;
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
if (args[arg_time]) { if (args[arg_time]) {
@ -77,7 +77,7 @@ module.exports = class CloseCommand extends Command {
); );
} }
let tickets = await this.client.db.models.Ticket.findAndCountAll({ const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: { where: {
last_message: { last_message: {
[Op.lte]: new Date(Date.now() - period) [Op.lte]: new Date(Date.now() - period)
@ -95,7 +95,7 @@ module.exports = class CloseCommand extends Command {
.setFooter(settings.footer, message.guild.iconURL()) .setFooter(settings.footer, message.guild.iconURL())
); );
} else { } else {
let collector_message = await message.channel.send( const collector_message = await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setTitle(i18n('commands.close.response.confirm_multiple.title')) .setTitle(i18n('commands.close.response.confirm_multiple.title'))
@ -109,7 +109,7 @@ module.exports = class CloseCommand extends Command {
return user.id === message.author.id && reaction.emoji.name === '✅'; return user.id === message.author.id && reaction.emoji.name === '✅';
}; };
let collector = collector_message.createReactionCollector(collector_filter, { const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000 time: 30000
}); });
@ -124,7 +124,7 @@ module.exports = class CloseCommand extends Command {
.setFooter(settings.footer, message.guild.iconURL()) .setFooter(settings.footer, message.guild.iconURL())
); );
for (let ticket of tickets.rows) { for (const ticket of tickets.rows) {
await this.client.tickets.close(ticket.id, message.author.id, message.guild.id, args[arg_reason]); await this.client.tickets.close(ticket.id, message.author.id, message.guild.id, args[arg_reason]);
} }
@ -186,7 +186,7 @@ module.exports = class CloseCommand extends Command {
} }
} }
let collector_message = await message.channel.send( const collector_message = await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setTitle(i18n('commands.close.response.confirm.title')) .setTitle(i18n('commands.close.response.confirm.title'))
@ -200,7 +200,7 @@ module.exports = class CloseCommand extends Command {
return user.id === message.author.id && reaction.emoji.name === '✅'; return user.id === message.author.id && reaction.emoji.name === '✅';
}; };
let collector = collector_message.createReactionCollector(collector_filter, { const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000 time: 30000
}); });

View File

@ -31,7 +31,7 @@ module.exports = class HelpCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
const cmd = this.manager.commands.find(command => command.aliases.includes(args.toLowerCase())); const cmd = this.manager.commands.find(command => command.aliases.includes(args.toLowerCase()));
@ -39,13 +39,12 @@ module.exports = class HelpCommand extends Command {
if (cmd) { if (cmd) {
return await cmd.sendUsage(message.channel, args); return await cmd.sendUsage(message.channel, args);
} else { } else {
let commands = this.manager.commands.filter(async command => { const commands = this.manager.commands.filter(async command => {
if (command.permissions.length >= 1) return !message.member.hasPermission(command.permissions); if (command.permissions.length >= 1) return !message.member.hasPermission(command.permissions);
else if (command.staff_only) return await message.member.isStaff(); else if (command.staff_only) return await message.member.isStaff();
}); });
let list = commands.map(command => { const list = commands.map(command => {
// let description = command.description; const description = command.description.length > 50
let description = command.description.length > 50
? command.description.substring(0, 50) + '...' ? command.description.substring(0, 50) + '...'
: command.description; : command.description;
return `**\`${settings.command_prefix}${command.name}\` ·** ${description}`; return `**\`${settings.command_prefix}${command.name}\` ·** ${description}`;

View File

@ -35,7 +35,7 @@ module.exports = class NewCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
const editOrSend = async (msg, content) => { const editOrSend = async (msg, content) => {
@ -44,7 +44,7 @@ module.exports = class NewCommand extends Command {
}; };
const create = async (cat_row, response) => { const create = async (cat_row, response) => {
let tickets = await this.client.db.models.Ticket.findAndCountAll({ const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: { where: {
category: cat_row.id, category: cat_row.id,
creator: message.author.id, creator: message.author.id,
@ -63,10 +63,10 @@ module.exports = class NewCommand extends Command {
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL()) .setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
); );
} else { } else {
let list = tickets.rows.map(row => { const list = tickets.rows.map(row => {
if (row.topic) { if (row.topic) {
let description = row.topic.substring(0, 30); const description = row.topic.substring(0, 30);
let ellipses = row.topic.length > 30 ? '...' : ''; const ellipses = row.topic.length > 30 ? '...' : '';
return `<#${row.id}>: \`${description}${ellipses}\``; return `<#${row.id}>: \`${description}${ellipses}\``;
} else { } else {
return `<#${row.id}>`; return `<#${row.id}>`;
@ -83,7 +83,7 @@ module.exports = class NewCommand extends Command {
} }
} else { } else {
try { try {
let t_row = await this.client.tickets.create(message.guild.id, message.author.id, cat_row.id, args); const t_row = await this.client.tickets.create(message.guild.id, message.author.id, cat_row.id, args);
response = await editOrSend(response, response = await editOrSend(response,
new MessageEmbed() new MessageEmbed()
.setColor(settings.success_colour) .setColor(settings.success_colour)
@ -114,7 +114,7 @@ module.exports = class NewCommand extends Command {
}, 15000); }, 15000);
}; };
let categories = await this.client.db.models.Category.findAndCountAll({ const categories = await this.client.db.models.Category.findAndCountAll({
where: { where: {
guild: message.guild.id guild: message.guild.id
} }
@ -132,9 +132,9 @@ module.exports = class NewCommand extends Command {
} else if (categories.count === 1) { } else if (categories.count === 1) {
create(categories.rows[0]); // skip the category selection create(categories.rows[0]); // skip the category selection
} else { } else {
let letters_array = Object.values(letters); // convert the A-Z emoji object to an array const letters_array = Object.values(letters); // convert the A-Z emoji object to an array
let category_list = categories.rows.map((category, i) => `${letters_array[i]} » ${category.name}`); // list category names with an A-Z emoji const category_list = categories.rows.map((category, i) => `${letters_array[i]} » ${category.name}`); // list category names with an A-Z emoji
let collector_message = await message.channel.send( const collector_message = await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL()) .setAuthor(message.author.username, message.author.displayAvatarURL())
@ -143,23 +143,23 @@ module.exports = class NewCommand extends Command {
.setFooter(footer(settings.footer, i18n('collector_expires_in', 30)), message.guild.iconURL()) .setFooter(footer(settings.footer, i18n('collector_expires_in', 30)), message.guild.iconURL())
); );
for (let i in categories.rows) { for (const i in categories.rows) {
collector_message.react(letters_array[i]); // add the correct number of letter reactions collector_message.react(letters_array[i]); // add the correct number of letter reactions
await wait(1000); // 1 reaction per second rate-limit await wait(1000); // 1 reaction per second rate-limit
} }
const collector_filter = (reaction, user) => { const collector_filter = (reaction, user) => {
let allowed = letters_array.slice(0, categories.count); // get the first x letters of the emoji array const allowed = letters_array.slice(0, categories.count); // get the first x letters of the emoji array
return user.id === message.author.id && allowed.includes(reaction.emoji.name); return user.id === message.author.id && allowed.includes(reaction.emoji.name);
}; };
let collector = collector_message.createReactionCollector(collector_filter, { const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000 time: 30000
}); });
collector.on('collect', async (reaction) => { collector.on('collect', async (reaction) => {
collector.stop(); collector.stop();
let index = letters_array.findIndex(value => value === reaction.emoji.name); // find where the letter is in the alphabet const index = letters_array.findIndex(value => value === reaction.emoji.name); // find where the letter is in the alphabet
if (index === -1) return setTimeout(async () => { if (index === -1) return setTimeout(async () => {
await collector_message.delete(); await collector_message.delete();
}, 15000); }, 15000);

View File

@ -69,7 +69,7 @@ module.exports = class PanelCommand extends Command {
const arg_emoji = this.args[2].name; const arg_emoji = this.args[2].name;
const arg_categories = this.args[3].name; const arg_categories = this.args[3].name;
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
if (!args[arg_emoji]) if (!args[arg_emoji])
@ -78,7 +78,7 @@ module.exports = class PanelCommand extends Command {
args[arg_emoji] = args[arg_emoji].map(emoji => emojify(emoji.replace(/\\/g, ''))); args[arg_emoji] = args[arg_emoji].map(emoji => emojify(emoji.replace(/\\/g, '')));
const invalid_category = await some(args[arg_categories], async id => { const invalid_category = await some(args[arg_categories], async id => {
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: id, id: id,
guild: message.guild.id guild: message.guild.id
@ -102,7 +102,7 @@ module.exports = class PanelCommand extends Command {
let categories_map = args[arg_categories][0]; let categories_map = args[arg_categories][0];
let embed = new MessageEmbed() const embed = new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setFooter(settings.footer, message.guild.iconURL()); .setFooter(settings.footer, message.guild.iconURL());
@ -173,9 +173,9 @@ module.exports = class PanelCommand extends Command {
let description = ''; let description = '';
categories_map = {}; categories_map = {};
for (let i in args[arg_emoji]) { for (const i in args[arg_emoji]) {
categories_map[args[arg_emoji][i]] = args[arg_categories][i]; categories_map[args[arg_emoji][i]] = args[arg_categories][i];
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: args[arg_categories][i], id: args[arg_categories][i],
guild: message.guild.id guild: message.guild.id
@ -187,7 +187,7 @@ module.exports = class PanelCommand extends Command {
embed.setDescription(args[arg_description] + '\n' + description); embed.setDescription(args[arg_description] + '\n' + description);
panel_message = await panel_channel.send(embed); panel_message = await panel_channel.send(embed);
for (let emoji of args[arg_emoji]) { for (const emoji of args[arg_emoji]) {
await panel_message.react(emoji); await panel_message.react(emoji);
await wait(1000); // 1 reaction per second rate-limit await wait(1000); // 1 reaction per second rate-limit
} }

View File

@ -34,11 +34,11 @@ module.exports = class RemoveCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let ticket = message.mentions.channels.first() ?? message.channel; const ticket = message.mentions.channels.first() ?? message.channel;
let t_row = await this.client.tickets.resolve(ticket.id, message.guild.id); const t_row = await this.client.tickets.resolve(ticket.id, message.guild.id);
if (!t_row) { if (!t_row) {
return await message.channel.send( return await message.channel.send(
@ -50,7 +50,7 @@ module.exports = class RemoveCommand extends Command {
); );
} }
let member = message.mentions.members.first() ?? message.guild.members.cache.get(args); const member = message.mentions.members.first() ?? message.guild.members.cache.get(args);
if (!member) { if (!member) {
return await message.channel.send( return await message.channel.send(

View File

@ -19,7 +19,7 @@ module.exports = class SettingsCommand extends Command {
permissions: ['MANAGE_GUILD'] permissions: ['MANAGE_GUILD']
}); });
this.schema = require('../settings_schema.json'); this.schema = require('../settings.schema.json');
this.v = new Validator(); this.v = new Validator();
} }
@ -30,16 +30,16 @@ module.exports = class SettingsCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message) { async execute(message) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let attachments = [ ...message.attachments.values() ]; const attachments = [ ...message.attachments.values() ];
if (attachments.length >= 1) { if (attachments.length >= 1) {
// load settings from json // load settings from json
this.client.log.info(`Downloading settings for "${message.guild.name}"`); this.client.log.info(`Downloading settings for "${message.guild.name}"`);
let data = await (await fetch(attachments[0].url)).json(); const data = await (await fetch(attachments[0].url)).json();
const { valid, errors } = this.v.validate(data, this.schema); const { valid, errors } = this.v.validate(data, this.schema);
@ -55,13 +55,14 @@ module.exports = class SettingsCommand extends Command {
settings.locale = data.locale; settings.locale = data.locale;
settings.log_messages = data.log_messages; settings.log_messages = data.log_messages;
settings.success_colour = data.success_colour; settings.success_colour = data.success_colour;
settings.tags = data.tags;
await settings.save(); await settings.save();
for (let c of data.categories) { for (const c of data.categories) {
if (c.id) { if (c.id) {
// existing category // existing category
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: c.id id: c.id
} }
@ -79,13 +80,13 @@ module.exports = class SettingsCommand extends Command {
cat_row.survey = c.survey; cat_row.survey = c.survey;
cat_row.save(); cat_row.save();
let cat_channel = await this.client.channels.fetch(c.id); const cat_channel = await this.client.channels.fetch(c.id);
if (cat_channel) { if (cat_channel) {
if (cat_channel.name !== c.name) if (cat_channel.name !== c.name)
await cat_channel.setName(c.name, `Tickets category updated by ${message.author.tag}`); await cat_channel.setName(c.name, `Tickets category updated by ${message.author.tag}`);
for (let r of c.roles) { for (const r of c.roles) {
await cat_channel.updateOverwrite(r, { await cat_channel.updateOverwrite(r, {
VIEW_CHANNEL: true, VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true, READ_MESSAGE_HISTORY: true,
@ -99,7 +100,7 @@ module.exports = class SettingsCommand extends Command {
// create a new category // create a new category
const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES']; const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
let cat_channel = await message.guild.channels.create(c.name, { const cat_channel = await message.guild.channels.create(c.name, {
type: 'category', type: 'category',
reason: `Tickets category created by ${message.author.tag}`, reason: `Tickets category created by ${message.author.tag}`,
position: 1, position: 1,
@ -142,12 +143,12 @@ module.exports = class SettingsCommand extends Command {
} }
} }
for (let survey in data.surveys) { for (const survey in data.surveys) {
let survey_data = { const survey_data = {
guild: message.guild.id, guild: message.guild.id,
name: survey, name: survey,
}; };
let [s_row] = await this.client.db.models.Survey.findOrCreate({ const [s_row] = await this.client.db.models.Survey.findOrCreate({
where: survey_data, where: survey_data,
defaults: survey_data defaults: survey_data
}); });
@ -162,19 +163,19 @@ module.exports = class SettingsCommand extends Command {
// upload settings as json to be edited // upload settings as json to be edited
let categories = await this.client.db.models.Category.findAll({ const categories = await this.client.db.models.Category.findAll({
where: { where: {
guild: message.guild.id guild: message.guild.id
} }
}); });
let surveys = await this.client.db.models.Survey.findAll({ const surveys = await this.client.db.models.Survey.findAll({
where: { where: {
guild: message.guild.id guild: message.guild.id
} }
}); });
let data = { const data = {
categories: categories.map(c => { categories: categories.map(c => {
return { return {
id: c.id, id: c.id,
@ -199,14 +200,15 @@ module.exports = class SettingsCommand extends Command {
log_messages: settings.log_messages, log_messages: settings.log_messages,
success_colour: settings.success_colour, success_colour: settings.success_colour,
surveys: {}, surveys: {},
tags: settings.tags
}; };
for (let survey in surveys) { for (const survey in surveys) {
const { name, questions } = surveys[survey]; const { name, questions } = surveys[survey];
data.surveys[name] = questions; data.surveys[name] = questions;
} }
let attachment = new MessageAttachment( const attachment = new MessageAttachment(
Buffer.from(JSON.stringify(data, null, 2)), Buffer.from(JSON.stringify(data, null, 2)),
`Settings for ${message.guild.name}.json` `Settings for ${message.guild.name}.json`
); );

View File

@ -27,7 +27,7 @@ module.exports = class StatsCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message) { async execute(message) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
const messages = await this.client.db.models.Message.findAndCountAll(); const messages = await this.client.db.models.Message.findAndCountAll();
@ -35,7 +35,7 @@ module.exports = class StatsCommand extends Command {
let stats = await this.cache.get(message.guild.id); let stats = await this.cache.get(message.guild.id);
if (!stats) { if (!stats) {
let tickets = await this.client.db.models.Ticket.findAndCountAll({ const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: { where: {
guild: message.guild.id guild: message.guild.id
} }
@ -60,7 +60,7 @@ module.exports = class StatsCommand extends Command {
await this.cache.set(message.guild.id, stats, 60 * 60 * 1000); // cache for an hour await this.cache.set(message.guild.id, stats, 60 * 60 * 1000); // cache for an hour
} }
let guild_embed = new MessageEmbed() const guild_embed = new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setTitle(i18n('commands.stats.response.guild.title')) .setTitle(i18n('commands.stats.response.guild.title'))
.setDescription(i18n('commands.stats.response.guild.description')) .setDescription(i18n('commands.stats.response.guild.description'))

View File

@ -28,10 +28,10 @@ module.exports = class TopicCommand extends Command {
* @returns {Promise<void|any>} * @returns {Promise<void|any>}
*/ */
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let t_row = await this.client.db.models.Ticket.findOne({ const t_row = await this.client.db.models.Ticket.findOne({
where: { where: {
id: message.channel.id id: message.channel.id
} }
@ -51,18 +51,18 @@ module.exports = class TopicCommand extends Command {
topic: this.client.cryptr.encrypt(args) topic: this.client.cryptr.encrypt(args)
}); });
let member = await message.guild.members.fetch(t_row.creator); const member = await message.guild.members.fetch(t_row.creator);
/* await */message.channel.setTopic(`${member} | ${args}`, { reason: 'User updated ticket topic' }); /* await */message.channel.setTopic(`${member} | ${args}`, { reason: 'User updated ticket topic' });
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: t_row.category id: t_row.category
} }
}); });
let description = cat_row.opening_message const description = cat_row.opening_message
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName) .replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
.replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString()); .replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString());
let opening_message = await message.channel.messages.fetch(t_row.opening_message); const opening_message = await message.channel.messages.fetch(t_row.opening_message);
await opening_message.edit( await opening_message.edit(
new MessageEmbed() new MessageEmbed()

View File

@ -14,7 +14,7 @@ module.exports = async (client) => {
DB_NAME DB_NAME
} = process.env; } = process.env;
let type = (DB_TYPE || 'sqlite').toLowerCase(); const type = (DB_TYPE || 'sqlite').toLowerCase();
const supported = Object.keys(types); const supported = Object.keys(types);
if (!supported.includes(type)) { if (!supported.includes(type)) {
@ -25,7 +25,7 @@ module.exports = async (client) => {
try { try {
types[type].packages.forEach(pkg => require(pkg)); types[type].packages.forEach(pkg => require(pkg));
} catch { } catch {
let required = types[type].packages.map(i => `"${i}"`).join(' and '); const required = types[type].packages.map(i => `"${i}"`).join(' and ');
client.log.error(new Error(`Please install the package(s) for your selected database type: ${required}`)); client.log.error(new Error(`Please install the package(s) for your selected database type: ${required}`));
return process.exit(); return process.exit();
} }

View File

@ -39,6 +39,10 @@ module.exports = ({ config }, sequelize) => {
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: 'GREEN' defaultValue: 'GREEN'
}, },
tags: {
type: DataTypes.JSON,
defaultValue: {}
}
}, { }, {
tableName: DB_TABLE_PREFIX + 'guilds' tableName: DB_TABLE_PREFIX + 'guilds'
}); });

View File

@ -50,8 +50,8 @@ if (!checkFile('./.env', './example.env')) {
const file = path('./.env'); const file = path('./.env');
const crypto = require('crypto'); const crypto = require('crypto');
let key = 'DB_ENCRYPTION_KEY='; const key = 'DB_ENCRYPTION_KEY=';
let value = crypto const value = crypto
.randomBytes(24) .randomBytes(24)
.toString('hex'); .toString('hex');
@ -132,14 +132,14 @@ class Bot extends Client {
/** A [Cryptr](https://www.npmjs.com/package/cryptr) instance */ /** A [Cryptr](https://www.npmjs.com/package/cryptr) instance */
this.cryptr = new Cryptr(process.env.DB_ENCRYPTION_KEY); this.cryptr = new Cryptr(process.env.DB_ENCRYPTION_KEY);
let locales = {}; const locales = {};
fs.readdirSync(path('./src/locales')) fs.readdirSync(path('./src/locales'))
.filter(file => file.endsWith('.json')) .filter(file => file.endsWith('.json'))
.forEach(file => { .forEach(file => {
let data = fs.readFileSync(path(`./src/locales/${file}`), { const data = fs.readFileSync(path(`./src/locales/${file}`), {
encoding: 'utf8' encoding: 'utf8'
}); });
let name = file.slice(0, file.length - 5); const name = file.slice(0, file.length - 5);
locales[name] = JSON.parse(data); locales[name] = JSON.parse(data);
}); });
@ -179,7 +179,7 @@ class Bot extends Client {
* You can see the source here: https://github.com/discord-tickets/stats * You can see the source here: https://github.com/discord-tickets/stats
*/ */
if (this.config.super_secret_setting) { // you can disable it if you really want if (this.config.super_secret_setting) { // you can disable it if you really want
let tickets = await this.db.models.Ticket.count(); const tickets = await this.db.models.Ticket.count();
await fetch(`https://stats.discordtickets.app/client?id=${this.user.id}&tickets=${tickets}`, { await fetch(`https://stats.discordtickets.app/client?id=${this.user.id}&tickets=${tickets}`, {
method: 'post', method: 'post',
}).catch(e => { }).catch(e => {
@ -187,7 +187,7 @@ class Bot extends Client {
this.log.debug(e); this.log.debug(e);
}); });
this.guilds.cache.forEach(async g => { this.guilds.cache.forEach(async g => {
let members = (await g.fetch()).approximateMemberCount; const members = (await g.fetch()).approximateMemberCount;
await fetch(`https://stats.discordtickets.app/guild?id=${g.id}&members=${members}`, { await fetch(`https://stats.discordtickets.app/guild?id=${g.id}&members=${members}`, {
method: 'post', method: 'post',
}).catch(e => { }).catch(e => {

View File

@ -8,14 +8,14 @@ module.exports = class GuildMemberRemoveEventListener extends EventListener {
} }
async execute(member) { async execute(member) {
let tickets = await this.client.db.models.Ticket.findAndCountAll({ const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: { where: {
creator: member.id, creator: member.id,
guild: member.guild.id guild: member.guild.id
} }
}); });
for (let ticket of tickets.rows) { for (const ticket of tickets.rows) {
await this.client.tickets.close(ticket.id, null, member.guild.id, 'Member left the guild'); await this.client.tickets.close(ticket.id, null, member.guild.id, 'Member left the guild');
} }

View File

@ -17,7 +17,7 @@ module.exports = class MessageEventListener extends EventListener {
if (!settings) settings = await message.guild.createSettings(); if (!settings) settings = await message.guild.createSettings();
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let t_row = await this.client.db.models.Ticket.findOne({ const t_row = await this.client.db.models.Ticket.findOne({
where: { where: {
id: message.channel.id id: message.channel.id
} }
@ -34,7 +34,7 @@ module.exports = class MessageEventListener extends EventListener {
} else { } else {
if (message.author.bot) return; if (message.author.bot) return;
let p_row = await this.client.db.models.Panel.findOne({ const p_row = await this.client.db.models.Panel.findOne({
where: { where: {
channel: message.channel.id channel: message.channel.id
} }
@ -45,13 +45,13 @@ module.exports = class MessageEventListener extends EventListener {
await message.delete(); await message.delete();
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: p_row.categories id: p_row.categories
} }
}); });
let tickets = await this.client.db.models.Ticket.findAndCountAll({ const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: { where: {
category: cat_row.id, category: cat_row.id,
creator: message.author.id, creator: message.author.id,
@ -75,10 +75,10 @@ module.exports = class MessageEventListener extends EventListener {
response = await message.channel.send(embed); response = await message.channel.send(embed);
} }
} else { } else {
let list = tickets.rows.map(row => { const list = tickets.rows.map(row => {
if (row.topic) { if (row.topic) {
let description = row.topic.substring(0, 30); const description = row.topic.substring(0, 30);
let ellipses = row.topic.length > 30 ? '...' : ''; const ellipses = row.topic.length > 30 ? '...' : '';
return `<#${row.id}>: \`${description}${ellipses}\``; return `<#${row.id}>: \`${description}${ellipses}\``;
} else { } else {
return `<#${row.id}>`; return `<#${row.id}>`;

View File

@ -50,7 +50,7 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
}); });
} }
let t_row = await this.client.db.models.Ticket.findOne({ const t_row = await this.client.db.models.Ticket.findOne({
where: { where: {
id: channel.id id: channel.id
} }
@ -68,13 +68,13 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
VIEW_CHANNEL: true, VIEW_CHANNEL: true,
}, `Ticket claimed by ${member.user.tag}`); }, `Ticket claimed by ${member.user.tag}`);
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: t_row.category id: t_row.category
} }
}); });
for (let role of cat_row.roles) { for (const role of cat_row.roles) {
await channel.updateOverwrite(role, { await channel.updateOverwrite(role, {
VIEW_CHANNEL: false, VIEW_CHANNEL: false,
}, `Ticket claimed by ${member.user.tag}`); }, `Ticket claimed by ${member.user.tag}`);
@ -94,7 +94,7 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
await r.users.remove(u.id); await r.users.remove(u.id);
} }
} else { } else {
let p_row = await this.client.db.models.Panel.findOne({ const p_row = await this.client.db.models.Panel.findOne({
where: { where: {
message: r.message.id message: r.message.id
} }
@ -104,16 +104,16 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
// panels // panels
await r.users.remove(u.id); await r.users.remove(u.id);
let category_id = p_row.categories[r.emoji.name]; const category_id = p_row.categories[r.emoji.name];
if (!category_id) return; if (!category_id) return;
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: category_id id: category_id
} }
}); });
let tickets = await this.client.db.models.Ticket.findAndCountAll({ const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: { where: {
category: cat_row.id, category: cat_row.id,
creator: u.id, creator: u.id,
@ -137,10 +137,10 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
response = await channel.send(embed); response = await channel.send(embed);
} }
} else { } else {
let list = tickets.rows.map(row => { const list = tickets.rows.map(row => {
if (row.topic) { if (row.topic) {
let description = row.topic.substring(0, 30); const description = row.topic.substring(0, 30);
let ellipses = row.topic.length > 30 ? '...' : ''; const ellipses = row.topic.length > 30 ? '...' : '';
return `<#${row.id}>: \`${description}${ellipses}\``; return `<#${row.id}>: \`${description}${ellipses}\``;
} else { } else {
return `<#${row.id}>`; return `<#${row.id}>`;

View File

@ -39,7 +39,7 @@ module.exports = class MessageReactionRemoveEventListener extends EventListener
const channel = r.message.channel; const channel = r.message.channel;
const member = await guild.members.fetch(u.id); const member = await guild.members.fetch(u.id);
let t_row = await this.client.db.models.Ticket.findOne({ const t_row = await this.client.db.models.Ticket.findOne({
where: { where: {
id: channel.id id: channel.id
} }
@ -57,13 +57,13 @@ module.exports = class MessageReactionRemoveEventListener extends EventListener
.get(member.user.id) .get(member.user.id)
?.delete(`Ticket released by ${member.user.tag}`); ?.delete(`Ticket released by ${member.user.tag}`);
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: t_row.category id: t_row.category
} }
}); });
for (let role of cat_row.roles) { for (const role of cat_row.roles) {
await channel.updateOverwrite(role, { await channel.updateOverwrite(role, {
VIEW_CHANNEL: true, VIEW_CHANNEL: true,
}, `Ticket released by ${member.user.tag}`); }, `Ticket released by ${member.user.tag}`);

View File

@ -18,7 +18,7 @@ module.exports = class ReadyEventListener extends EventListener {
if (this.client.config.presence.presences.length > 1) { if (this.client.config.presence.presences.length > 1) {
const { selectPresence } = require('../utils/discord'); const { selectPresence } = require('../utils/discord');
setInterval(() => { setInterval(() => {
let presence = selectPresence(); const presence = selectPresence();
this.client.user.setPresence(presence); this.client.user.setPresence(presence);
this.client.log.debug(`Updated presence: ${presence.activity.type} ${presence.activity.name}`); this.client.log.debug(`Updated presence: ${presence.activity.type} ${presence.activity.name}`);
}, this.client.config.presence.duration * 1000); }, this.client.config.presence.duration * 1000);

View File

@ -120,14 +120,14 @@ module.exports = class Command {
* @returns {Message} * @returns {Message}
*/ */
async sendUsage(channel, alias) { async sendUsage(channel, alias) {
let settings = await channel.guild.settings; const settings = await channel.guild.settings;
if (!alias) alias = this.name; if (!alias) alias = this.name;
const prefix = settings.command_prefix; const prefix = settings.command_prefix;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
const addArgs = (embed, arg) => { const addArgs = (embed, arg) => {
let required = arg.required ? '`❗` ' : ''; const required = arg.required ? '`❗` ' : '';
let description = `» ${i18n('cmd_usage.args.description', arg.description)}`; let description = `» ${i18n('cmd_usage.args.description', arg.description)}`;
if (arg.example) description += `\n» ${i18n('cmd_usage.args.example', arg.example)}`; if (arg.example) description += `\n» ${i18n('cmd_usage.args.example', arg.example)}`;
embed.addField(required + arg.name, description); embed.addField(required + arg.name, description);

View File

@ -48,7 +48,7 @@ module.exports = class CommandManager {
const is_internal = (exists && cmd.internal) || (exists && this.commands.get(cmd.name).internal); const is_internal = (exists && cmd.internal) || (exists && this.commands.get(cmd.name).internal);
if (is_internal) { if (is_internal) {
let plugin = this.client.plugins.plugins.find(p => p.commands.includes(cmd.name)); const plugin = this.client.plugins.plugins.find(p => p.commands.includes(cmd.name));
if (plugin) if (plugin)
this.client.log.commands(`The "${plugin.name}" plugin has overridden the internal "${cmd.name}" command`); this.client.log.commands(`The "${plugin.name}" plugin has overridden the internal "${cmd.name}" command`);
else else
@ -69,7 +69,7 @@ module.exports = class CommandManager {
async handle(message) { async handle(message) {
if (message.author.bot) return; // ignore self and other bots if (message.author.bot) return; // ignore self and other bots
let settings = await message.guild.settings; const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let is_blacklisted = false; let is_blacklisted = false;
@ -100,14 +100,14 @@ module.exports = class CommandManager {
let cmd_name = message.content.match(new RegExp(`^(${escaped_prefix}|${client_mention}\\s?)(\\S+)`, 'mi')); // capture prefix and command let cmd_name = message.content.match(new RegExp(`^(${escaped_prefix}|${client_mention}\\s?)(\\S+)`, 'mi')); // capture prefix and command
if (!cmd_name) return; // stop here if the message is not a command if (!cmd_name) return; // stop here if the message is not a command
let raw_args = message.content.replace(cmd_name[0], '').trim(); // remove the prefix and command const raw_args = message.content.replace(cmd_name[0], '').trim(); // remove the prefix and command
cmd_name = cmd_name[2].toLowerCase(); // set cmd_name to the actual command alias, effectively removing the prefix cmd_name = cmd_name[2].toLowerCase(); // set cmd_name to the actual command alias, effectively removing the prefix
const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name)); const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name));
if (!cmd) return; if (!cmd) return;
let bot_permissions = message.guild.me.permissionsIn(message.channel); const bot_permissions = message.guild.me.permissionsIn(message.channel);
let required_bot_permissions = [ const required_bot_permissions = [
'ADD_REACTIONS', 'ADD_REACTIONS',
'ATTACH_FILES', 'ATTACH_FILES',
'EMBED_LINKS', 'EMBED_LINKS',
@ -118,7 +118,7 @@ module.exports = class CommandManager {
]; ];
if (!bot_permissions.has(required_bot_permissions)) { if (!bot_permissions.has(required_bot_permissions)) {
let perms = required_bot_permissions.map(p => `\`${p}\``).join(', '); const perms = required_bot_permissions.map(p => `\`${p}\``).join(', ');
if (bot_permissions.has(['EMBED_LINKS', 'SEND_MESSAGES'])) { if (bot_permissions.has(['EMBED_LINKS', 'SEND_MESSAGES'])) {
await message.channel.send( await message.channel.send(
new MessageEmbed() new MessageEmbed()
@ -138,7 +138,7 @@ module.exports = class CommandManager {
const missing_permissions = cmd.permissions instanceof Array && !message.member.hasPermission(cmd.permissions); const missing_permissions = cmd.permissions instanceof Array && !message.member.hasPermission(cmd.permissions);
if (missing_permissions) { if (missing_permissions) {
let perms = cmd.permissions.map(p => `\`${p}\``).join(', '); const perms = cmd.permissions.map(p => `\`${p}\``).join(', ');
return await message.channel.send( return await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(settings.error_colour) .setColor(settings.error_colour)
@ -162,7 +162,7 @@ module.exports = class CommandManager {
try { try {
args = parseArgs(cmd.args, { argv: argv(raw_args) }); args = parseArgs(cmd.args, { argv: argv(raw_args) });
} catch (error) { } catch (error) {
let help_cmd = `${settings.command_prefix}${i18n('commands.help.name')} ${cmd_name}`; const help_cmd = `${settings.command_prefix}${i18n('commands.help.name')} ${cmd_name}`;
return await message.channel.send( return await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(settings.error_colour) .setColor(settings.error_colour)
@ -170,7 +170,7 @@ module.exports = class CommandManager {
.setDescription(i18n('cmd_usage.invalid_named_args.description', error.message, help_cmd)) .setDescription(i18n('cmd_usage.invalid_named_args.description', error.message, help_cmd))
); );
} }
for (let arg of cmd.args) { for (const arg of cmd.args) {
if (arg.required && args[arg.name] === undefined) { if (arg.required && args[arg.name] === undefined) {
return await cmd.sendUsage(message.channel, cmd_name); // send usage if any required arg is missing return await cmd.sendUsage(message.channel, cmd_name); // send usage if any required arg is missing
} }

View File

@ -22,7 +22,7 @@ module.exports = class ListenerLoader {
try { try {
file = require(`../../listeners/${file}`); file = require(`../../listeners/${file}`);
const listener = new file(this.client); const listener = new file(this.client);
let on = listener.once ? 'once' : 'on'; const on = listener.once ? 'once' : 'on';
if (listener.raw) if (listener.raw)
this.client.ws[on](listener.event, (...data) => listener.execute(...data)); this.client.ws[on](listener.event, (...data) => listener.execute(...data));
else else

View File

@ -55,7 +55,7 @@ module.exports = class PluginManager {
author = author.name ?? 'unknown'; author = author.name ?? 'unknown';
} }
let about = { const about = {
id, id,
version, version,
author, author,
@ -79,8 +79,8 @@ module.exports = class PluginManager {
load() { load() {
this.client.config.plugins.forEach(plugin => { this.client.config.plugins.forEach(plugin => {
try { try {
let main = require(plugin); const main = require(plugin);
let pkg = require(`${plugin}/package.json`); const pkg = require(`${plugin}/package.json`);
this.register(main, pkg); this.register(main, pkg);
} catch (e) { } catch (e) {
this.handleError(plugin); this.handleError(plugin);

View File

@ -27,7 +27,7 @@ module.exports = class Plugin {
/** An official plugin? */ /** An official plugin? */
this.official = this.manager.official.includes(this.id); this.official = this.manager.official.includes(this.id);
let { const {
id, id,
version, version,
author, author,
@ -70,7 +70,7 @@ module.exports = class Plugin {
*/ */
this.description = description; this.description = description;
let clean = this.id.replace(/@[-_a-zA-Z0-9]+\//, ''); const clean = this.id.replace(/@[-_a-zA-Z0-9]+\//, '');
/** /**
* Information about the plugin directory * Information about the plugin directory
@ -104,7 +104,7 @@ module.exports = class Plugin {
*/ */
createConfig(template) { createConfig(template) {
this.createDirectory(); this.createDirectory();
let file = join(this.directory.path, 'config.json'); const file = join(this.directory.path, 'config.json');
if (!fs.existsSync(file)) { if (!fs.existsSync(file)) {
this.client.log.plugins(`Creating plugin config file for "${this.name}"`); this.client.log.plugins(`Creating plugin config file for "${this.name}"`);
fs.writeFileSync(file, JSON.stringify(template, null, 2)); fs.writeFileSync(file, JSON.stringify(template, null, 2));
@ -120,7 +120,7 @@ module.exports = class Plugin {
*/ */
resetConfig(template) { resetConfig(template) {
this.createDirectory(); this.createDirectory();
let file = join(this.directory.path, 'config.json'); const file = join(this.directory.path, 'config.json');
this.client.log.plugins(`Resetting plugin config file for "${this.name}"`); this.client.log.plugins(`Resetting plugin config file for "${this.name}"`);
fs.writeFileSync(file, JSON.stringify(template, null, 2)); fs.writeFileSync(file, JSON.stringify(template, null, 2));
} }

View File

@ -19,7 +19,7 @@ module.exports = class TicketArchives {
async addMessage(message) { async addMessage(message) {
try { try {
// await this.client.db.transaction(async t => { // await this.client.db.transaction(async t => {
let t_row = await this.client.db.models.Ticket.findOne({ const t_row = await this.client.db.models.Ticket.findOne({
where: { where: {
id: message.channel.id id: message.channel.id
}, },
@ -53,7 +53,7 @@ module.exports = class TicketArchives {
async updateMessage(message) { async updateMessage(message) {
try { try {
// await this.client.db.transaction(async t => { // await this.client.db.transaction(async t => {
let m_row = await this.client.db.models.Message.findOne({ const m_row = await this.client.db.models.Message.findOne({
where: { where: {
id: message.id id: message.id
}, },
@ -86,7 +86,7 @@ module.exports = class TicketArchives {
async deleteMessage(message) { async deleteMessage(message) {
try { try {
// await this.client.db.transaction(async t => { // await this.client.db.transaction(async t => {
let msg = await this.client.db.models.Message.findOne({ const msg = await this.client.db.models.Message.findOne({
where: { where: {
id: message.id id: message.id
}, },
@ -129,12 +129,12 @@ module.exports = class TicketArchives {
try { try {
// await this.client.db.transaction(async t => { // await this.client.db.transaction(async t => {
let u_model_data = { const u_model_data = {
user: member.user.id, user: member.user.id,
ticket: ticket_id ticket: ticket_id
}; };
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({ const [u_row] = await this.client.db.models.UserEntity.findOrCreate({
where: u_model_data, where: u_model_data,
defaults: { defaults: {
...u_model_data, ...u_model_data,
@ -163,11 +163,11 @@ module.exports = class TicketArchives {
async updateChannel(ticket_id, channel) { async updateChannel(ticket_id, channel) {
try { try {
// await this.client.db.transaction(async t => { // await this.client.db.transaction(async t => {
let c_model_data = { const c_model_data = {
channel: channel.id, channel: channel.id,
ticket: ticket_id ticket: ticket_id
}; };
let [c_row] = await this.client.db.models.ChannelEntity.findOrCreate({ const [c_row] = await this.client.db.models.ChannelEntity.findOrCreate({
where: c_model_data, where: c_model_data,
defaults: c_model_data, defaults: c_model_data,
/* transaction: t */ /* transaction: t */
@ -188,11 +188,11 @@ module.exports = class TicketArchives {
async updateRole(ticket_id, role) { async updateRole(ticket_id, role) {
try { try {
// await this.client.db.transaction(async t => { // await this.client.db.transaction(async t => {
let r_model_data = { const r_model_data = {
role: role.id, role: role.id,
ticket: ticket_id ticket: ticket_id
}; };
let [r_row] = await this.client.db.models.RoleEntity.findOrCreate({ const [r_row] = await this.client.db.models.RoleEntity.findOrCreate({
where: r_model_data, where: r_model_data,
defaults: r_model_data, defaults: r_model_data,
/* transaction: t */ /* transaction: t */

View File

@ -30,7 +30,7 @@ module.exports = class TicketManager extends EventEmitter {
async create(guild_id, creator_id, category_id, topic) { async create(guild_id, creator_id, category_id, topic) {
if (!topic) topic = ''; if (!topic) topic = '';
let cat_row = await this.client.db.models.Category.findOne({ const cat_row = await this.client.db.models.Category.findOne({
where: { where: {
id: category_id id: category_id
} }
@ -39,24 +39,24 @@ module.exports = class TicketManager extends EventEmitter {
if (!cat_row) if (!cat_row)
throw new Error('Ticket category does not exist'); throw new Error('Ticket category does not exist');
let cat_channel = await this.client.channels.fetch(category_id); const cat_channel = await this.client.channels.fetch(category_id);
if (cat_channel.children.size >= 50) if (cat_channel.children.size >= 50)
throw new Error('Ticket category has reached child channel limit (50)'); throw new Error('Ticket category has reached child channel limit (50)');
let number = (await this.client.db.models.Ticket.count({ const number = (await this.client.db.models.Ticket.count({
where: { where: {
guild: guild_id guild: guild_id
} }
})) + 1; })) + 1;
let guild = this.client.guilds.cache.get(guild_id); const guild = this.client.guilds.cache.get(guild_id);
let member = await guild.members.fetch(creator_id); const member = await guild.members.fetch(creator_id);
let name = cat_row.name_format const name = cat_row.name_format
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName) .replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
.replace(/{+\s?num(ber)?\s?}+/gi, number); .replace(/{+\s?num(ber)?\s?}+/gi, number);
let t_channel = await guild.channels.create(name, { const t_channel = await guild.channels.create(name, {
type: 'text', type: 'text',
topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`, topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`,
parent: category_id, parent: category_id,
@ -70,7 +70,7 @@ module.exports = class TicketManager extends EventEmitter {
ATTACH_FILES: true ATTACH_FILES: true
}, `Ticket channel created by ${member.user.tag}`); }, `Ticket channel created by ${member.user.tag}`);
let t_row = await this.client.db.models.Ticket.create({ const t_row = await this.client.db.models.Ticket.create({
id: t_channel.id, id: t_channel.id,
number, number,
guild: guild_id, guild: guild_id,
@ -80,7 +80,7 @@ module.exports = class TicketManager extends EventEmitter {
}); });
(async () => { (async () => {
let settings = await guild.settings; const settings = await guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
topic = t_row.topic topic = t_row.topic
@ -88,7 +88,7 @@ module.exports = class TicketManager extends EventEmitter {
: ''; : '';
if (cat_row.ping instanceof Array && cat_row.ping.length > 0) { if (cat_row.ping instanceof Array && cat_row.ping.length > 0) {
let mentions = cat_row.ping.map(id => id === 'everyone' const mentions = cat_row.ping.map(id => id === 'everyone'
? '@everyone' ? '@everyone'
: id === 'here' : id === 'here'
? '@here' ? '@here'
@ -101,10 +101,10 @@ module.exports = class TicketManager extends EventEmitter {
await t_channel.send(cat_row.image); await t_channel.send(cat_row.image);
} }
let description = cat_row.opening_message const description = cat_row.opening_message
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName) .replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
.replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString()); .replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString());
let embed = new MessageEmbed() const embed = new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL()) .setAuthor(member.user.username, member.user.displayAvatarURL())
.setDescription(description) .setDescription(description)
@ -112,14 +112,14 @@ module.exports = class TicketManager extends EventEmitter {
if (topic) embed.addField(i18n('ticket.opening_message.fields.topic'), topic); if (topic) embed.addField(i18n('ticket.opening_message.fields.topic'), topic);
let sent = await t_channel.send(member.user.toString(), embed); const sent = await t_channel.send(member.user.toString(), embed);
await sent.pin({ reason: 'Ticket opening message' }); await sent.pin({ reason: 'Ticket opening message' });
await t_row.update({ await t_row.update({
opening_message: sent.id opening_message: sent.id
}); });
let pinned = t_channel.messages.cache.last(); const pinned = t_channel.messages.cache.last();
if (pinned.system) { if (pinned.system) {
pinned pinned
@ -139,7 +139,7 @@ module.exports = class TicketManager extends EventEmitter {
} }
if (cat_row.require_topic && topic.length === 0) { if (cat_row.require_topic && topic.length === 0) {
let collector_message = await t_channel.send( const collector_message = await t_channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setTitle('⚠️ ' + i18n('commands.new.request_topic.title')) .setTitle('⚠️ ' + i18n('commands.new.request_topic.title'))
@ -149,7 +149,7 @@ module.exports = class TicketManager extends EventEmitter {
const collector_filter = (message) => message.author.id === t_row.creator; const collector_filter = (message) => message.author.id === t_row.creator;
let collector = t_channel.createMessageCollector(collector_filter, { const collector = t_channel.createMessageCollector(collector_filter, {
time: 120000 time: 120000
}); });
@ -211,24 +211,24 @@ module.exports = class TicketManager extends EventEmitter {
* @param {string} [reason] - The reason for closing the ticket * @param {string} [reason] - The reason for closing the ticket
*/ */
async close(ticket_id, closer_id, guild_id, reason) { async close(ticket_id, closer_id, guild_id, reason) {
let t_row = await this.resolve(ticket_id, guild_id); const t_row = await this.resolve(ticket_id, guild_id);
if (!t_row) throw new Error(`A ticket with the ID or number "${ticket_id}" could not be resolved`); if (!t_row) throw new Error(`A ticket with the ID or number "${ticket_id}" could not be resolved`);
ticket_id = t_row.id; ticket_id = t_row.id;
this.emit('beforeClose', ticket_id); this.emit('beforeClose', ticket_id);
let guild = this.client.guilds.cache.get(t_row.guild); const guild = this.client.guilds.cache.get(t_row.guild);
let settings = await guild.settings; const settings = await guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
let channel = await this.client.channels.fetch(t_row.id); const channel = await this.client.channels.fetch(t_row.id);
if (closer_id) { if (closer_id) {
let member = await guild.members.fetch(closer_id); const member = await guild.members.fetch(closer_id);
await this.archives.updateMember(ticket_id, member); await this.archives.updateMember(ticket_id, member);
if (channel) { if (channel) {
let description = reason const description = reason
? i18n('ticket.closed_by_member_with_reason.description', member.user.toString(), reason) ? i18n('ticket.closed_by_member_with_reason.description', member.user.toString(), reason)
: i18n('ticket.closed_by_member.description', member.user.toString()); : i18n('ticket.closed_by_member.description', member.user.toString());
await channel.send( await channel.send(
@ -248,7 +248,7 @@ module.exports = class TicketManager extends EventEmitter {
this.client.log.info(`${member.user.tag} closed a ticket (${ticket_id})${reason ? `: "${reason}"` : ''}`); this.client.log.info(`${member.user.tag} closed a ticket (${ticket_id})${reason ? `: "${reason}"` : ''}`);
} else { } else {
if (channel) { if (channel) {
let description = reason const description = reason
? i18n('ticket.closed_with_reason.description') ? i18n('ticket.closed_with_reason.description')
: i18n('ticket.closed.description'); : i18n('ticket.closed.description');
await channel.send( await channel.send(
@ -267,7 +267,7 @@ module.exports = class TicketManager extends EventEmitter {
this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`); this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`);
} }
let pinned = await channel.messages.fetchPinned(); const pinned = await channel.messages.fetchPinned();
await t_row.update({ await t_row.update({
open: false, open: false,

View File

@ -95,6 +95,9 @@
}, },
"surveys": { "surveys": {
"type": "object" "type": "object"
},
"tags": {
"type": "object"
} }
}, },
"required": [ "required": [
@ -106,6 +109,7 @@
"locale", "locale",
"log_messages", "log_messages",
"success_colour", "success_colour",
"surveys" "surveys",
"tags"
] ]
} }

View File

@ -13,7 +13,7 @@ Structures.extend('Guild', Guild => {
} }
async deleteSettings() { async deleteSettings() {
let row = await this.settings; const row = await this.settings;
return await row.destroy(); return await row.destroy();
} }

View File

@ -7,7 +7,7 @@ Structures.extend('GuildMember', GuildMember => {
} }
async isStaff() { async isStaff() {
let guild_categories = await this.client.db.models.Category.findAll({ const guild_categories = await this.client.db.models.Category.findAll({
where: { where: {
guild: this.guild.id guild: this.guild.id
} }

View File

@ -4,21 +4,21 @@ const link = require('terminal-link');
const semver = require('semver'); const semver = require('semver');
const { format } = require('leekslazylogger-fastify'); const { format } = require('leekslazylogger-fastify');
let { version: current } = require('../package.json'); const { version: current } = require('../package.json');
module.exports = async client => { module.exports = async client => {
if (!client.config.update_notice) return; if (!client.config.update_notice) return;
const json = await (await fetch('https://api.github.com/repos/discord-tickets/bot/releases')).json(); const json = await (await fetch('https://api.github.com/repos/discord-tickets/bot/releases')).json();
const update = json[0]; const update = json[0];
let latest = semver.coerce(update.tag_name); const latest = semver.coerce(update.tag_name);
if (!semver.valid(latest)) return; if (!semver.valid(latest)) return;
if (semver.lt(current, latest)) { if (semver.lt(current, latest)) {
client.log.notice(`There is an update available for Discord Tickets (${current} -> ${update.tag_name})`); client.log.notice(`There is an update available for Discord Tickets (${current} -> ${update.tag_name})`);
let lines = [ const lines = [
`&k&6You are currently using &c${current}&6, the latest is &a${update.tag_name}&6.&r`, `&k&6You are currently using &c${current}&6, the latest is &a${update.tag_name}&6.&r`,
`&k&6Download "&f${update.name}&6" from&r`, `&k&6Download "&f${update.name}&6" from&r`,
link('&k&6the GitHub releases page.&r&6', 'https://github.com/discord-tickets/bot/releases/') link('&k&6the GitHub releases page.&r&6', 'https://github.com/discord-tickets/bot/releases/')

View File

@ -18,7 +18,7 @@ module.exports = {
* @returns {PresenceData} * @returns {PresenceData}
*/ */
selectPresence: () => { selectPresence: () => {
let length = config.presence.presences.length; const length = config.presence.presences.length;
if (length === 0) return {}; if (length === 0) return {};
let num; let num;
@ -33,7 +33,7 @@ module.exports = {
num = current_presence; num = current_presence;
} }
let { const {
activity: name, activity: name,
status, status,
type, type,

View File

@ -1,7 +1,7 @@
module.exports = { module.exports = {
int2hex: (int) => int.toString(16).toUpperCase(), int2hex: (int) => int.toString(16).toUpperCase(),
some: async (array, func) => { some: async (array, func) => {
for (let element of array) { for (const element of array) {
if (await func(element)) return true; if (await func(element)) return true;
} }
return false; return false;