Make @davidjcralph happy

const
This commit is contained in:
Isaac
2021-05-18 18:12:07 +01:00
parent 37adac1dd0
commit 8a15f34342
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>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);
let ticket = message.mentions.channels.first() ?? message.channel;
let t_row = await this.client.tickets.resolve(ticket.id, message.guild.id);
const ticket = message.mentions.channels.first() ?? message.channel;
const t_row = await this.client.tickets.resolve(ticket.id, message.guild.id);
if (!t_row) {
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) {
return await message.channel.send(

View File

@@ -31,10 +31,10 @@ module.exports = class BlacklistCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const settings = await message.guild.settings;
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))) {
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 input = args.trim().split(/\s/g)[0];
const input = args.trim().split(/\s/g)[0];
if (member) id = member.id;
else if (role) id = role.id;
@@ -64,7 +64,7 @@ module.exports = class BlacklistCommand extends Command {
);
} else {
// list blacklisted members
let blacklist = settings.blacklist.map(element => {
const blacklist = settings.blacklist.map(element => {
const is_role = message.guild.roles.cache.has(element);
if (is_role) 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);
let member_or_role = is_role ? 'role' : 'member';
let index = settings.blacklist.findIndex(element => element === id);
const member_or_role = is_role ? 'role' : 'member';
const index = settings.blacklist.findIndex(element => element === id);
let new_blacklist = [ ...settings.blacklist];
const new_blacklist = [ ...settings.blacklist ];
if (index === -1) {
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_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);
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: {
last_message: {
[Op.lte]: new Date(Date.now() - period)
@@ -95,7 +95,7 @@ module.exports = class CloseCommand extends Command {
.setFooter(settings.footer, message.guild.iconURL())
);
} else {
let collector_message = await message.channel.send(
const collector_message = await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.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 === '✅';
};
let collector = collector_message.createReactionCollector(collector_filter, {
const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000
});
@@ -124,7 +124,7 @@ module.exports = class CloseCommand extends Command {
.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]);
}
@@ -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()
.setColor(settings.colour)
.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 === '✅';
};
let collector = collector_message.createReactionCollector(collector_filter, {
const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000
});

View File

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

View File

@@ -35,7 +35,7 @@ module.exports = class NewCommand extends Command {
* @returns {Promise<void|any>}
*/
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 editOrSend = async (msg, content) => {
@@ -44,7 +44,7 @@ module.exports = class NewCommand extends Command {
};
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: {
category: cat_row.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())
);
} else {
let list = tickets.rows.map(row => {
const list = tickets.rows.map(row => {
if (row.topic) {
let description = row.topic.substring(0, 30);
let ellipses = row.topic.length > 30 ? '...' : '';
const description = row.topic.substring(0, 30);
const ellipses = row.topic.length > 30 ? '...' : '';
return `<#${row.id}>: \`${description}${ellipses}\``;
} else {
return `<#${row.id}>`;
@@ -83,7 +83,7 @@ module.exports = class NewCommand extends Command {
}
} else {
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,
new MessageEmbed()
.setColor(settings.success_colour)
@@ -114,7 +114,7 @@ module.exports = class NewCommand extends Command {
}, 15000);
};
let categories = await this.client.db.models.Category.findAndCountAll({
const categories = await this.client.db.models.Category.findAndCountAll({
where: {
guild: message.guild.id
}
@@ -132,9 +132,9 @@ module.exports = class NewCommand extends Command {
} else if (categories.count === 1) {
create(categories.rows[0]); // skip the category selection
} else {
let 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
let collector_message = await message.channel.send(
const letters_array = Object.values(letters); // convert the A-Z emoji object to an array
const category_list = categories.rows.map((category, i) => `${letters_array[i]} » ${category.name}`); // list category names with an A-Z emoji
const collector_message = await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.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())
);
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
await wait(1000); // 1 reaction per second rate-limit
}
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);
};
let collector = collector_message.createReactionCollector(collector_filter, {
const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000
});
collector.on('collect', async (reaction) => {
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 () => {
await collector_message.delete();
}, 15000);

View File

@@ -69,7 +69,7 @@ module.exports = class PanelCommand extends Command {
const arg_emoji = this.args[2].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);
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, '')));
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: {
id: id,
guild: message.guild.id
@@ -102,7 +102,7 @@ module.exports = class PanelCommand extends Command {
let categories_map = args[arg_categories][0];
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setColor(settings.colour)
.setFooter(settings.footer, message.guild.iconURL());
@@ -173,9 +173,9 @@ module.exports = class PanelCommand extends Command {
let description = '';
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];
let cat_row = await this.client.db.models.Category.findOne({
const cat_row = await this.client.db.models.Category.findOne({
where: {
id: args[arg_categories][i],
guild: message.guild.id
@@ -187,7 +187,7 @@ module.exports = class PanelCommand extends Command {
embed.setDescription(args[arg_description] + '\n' + description);
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 wait(1000); // 1 reaction per second rate-limit
}

View File

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

View File

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

View File

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

View File

@@ -28,10 +28,10 @@ module.exports = class TopicCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const settings = await message.guild.settings;
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: {
id: message.channel.id
}
@@ -51,18 +51,18 @@ module.exports = class TopicCommand extends Command {
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' });
let cat_row = await this.client.db.models.Category.findOne({
const cat_row = await this.client.db.models.Category.findOne({
where: {
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?(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(
new MessageEmbed()