refactor: update to discord.js v13 (#203)

* build: bump djs version

* refactor(add): update

* refactor(blacklist): update

* refactor(close): update

* refactor(help): update

* refactor(new): update

* refactor(panel): update

* refactor(remove): update

* refactor(stats): update

* refactor(survey): update

* refactor(tag): update

* refactor(topic): update

* refactor(guild): update, now Structures doesn't exist

Also I don't know if this would work actually, let's see

* refactor(guild_member)

* refactor(index.js): add intents

I can't understand how you do the indentation, sorry if I made a mistake

* Update package.json

* fix(intents): add `DIRECT_MESSAGES` intents


- also fix code style and indentation

* style: fix properties order and indentation

* fix(guild)

* Update and rename message.js to messageCreate.js

* Update guild.js

* refactor(manager): fix

* Update manager.js

* fix(help)

* style: fix spacing

* fix: permission overwrites

* fix(new)

* fix(presence): rename activity to activities

* fix(presence): fix debug message

* fix: update channel types

* Update new.js

* fix(embeds): update footer function

* fix: broken code

* style: add new lines around embed blocks

* fix(messages): update remaining `send()` calls

* fix(messages): i missed one

* build: replace fastify logger with standard logger

* refactor: update message and reaction collectors

Co-authored-by: Isaac <git@eartharoid.me>
This commit is contained in:
Puneet Gopinath
2021-08-17 01:35:20 +05:30
committed by GitHub
parent 96d1ddc48c
commit 0f10908ee0
30 changed files with 749 additions and 619 deletions

View File

@@ -36,65 +36,75 @@ module.exports = class AddCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
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(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.add.response.not_a_ticket.title'))
.setDescription(i18n('commands.add.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.add.response.not_a_ticket.title'))
.setDescription(i18n('commands.add.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
const member = message.mentions.members.first() ?? message.guild.members.cache.get(args);
if (!member) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.add.response.no_member.title'))
.setDescription(i18n('commands.add.response.no_member.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.add.response.no_member.title'))
.setDescription(i18n('commands.add.response.no_member.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
if (t_row.creator !== message.author.id && !await message.member.isStaff()) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.add.response.no_permission.title'))
.setDescription(i18n('commands.add.response.no_permission.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
if (t_row.creator !== message.author.id && !await this.client.utils.isStaff(message.member)) {
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.add.response.no_permission.title'))
.setDescription(i18n('commands.add.response.no_permission.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
if (message.channel.id !== ticket.id) {
await message.channel.send(
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('commands.add.response.added.title'))
.setDescription(i18n('commands.add.response.added.description', member.toString(), ticket.toString()))
.setFooter(settings.footer, message.guild.iconURL())
);
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('commands.add.response.added.title'))
.setDescription(i18n('commands.add.response.added.description', member.toString(), ticket.toString()))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
await ticket.send(
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.member_added.title'))
.setDescription(i18n('ticket.member_added.description', member.toString(), message.author.toString()))
.setFooter(settings.footer, message.guild.iconURL())
);
await ticket.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.member_added.title'))
.setDescription(i18n('ticket.member_added.description', member.toString(), message.author.toString()))
.setFooter(settings.footer, message.guild.iconURL())
]
});
await ticket.updateOverwrite(member, {
await ticket.permissionOverwrites.edit(member, {
ATTACH_FILES: true,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
@@ -105,4 +115,4 @@ module.exports = class AddCommand extends Command {
this.client.log.info(`${message.author.tag} added ${member.user.tag} to ${ticket.id}`);
}
};
};

View File

@@ -33,19 +33,21 @@ module.exports = class BlacklistCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const member = message.mentions.members.first();
if (member && (await member.isStaff() || member.hasPermission(this.permissions))) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.blacklist.response.illegal_action.title'))
.setDescription(i18n('commands.blacklist.response.illegal_action.description', `<@${member.id}>`))
.setFooter(settings.footer, message.guild.iconURL())
);
if (member && (await this.client.utils.isStaff(member) || member.permissions.has(this.permissions))) {
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.blacklist.response.illegal_action.title'))
.setDescription(i18n('commands.blacklist.response.illegal_action.description', `<@${member.id}>`))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
@@ -60,13 +62,15 @@ module.exports = class BlacklistCommand extends Command {
} else if (/\d{17,19}/.test(input)) {
id = input;
} else if (settings.blacklist.length === 0) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.blacklist.response.empty_list.title'))
.setDescription(i18n('commands.blacklist.response.empty_list.description', settings.command_prefix))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.blacklist.response.empty_list.title'))
.setDescription(i18n('commands.blacklist.response.empty_list.description', settings.command_prefix))
.setFooter(settings.footer, message.guild.iconURL())
]
});
} else {
// list blacklisted members
const blacklist = settings.blacklist.map(element => {
@@ -74,13 +78,15 @@ module.exports = class BlacklistCommand extends Command {
if (is_role) return `» <@&${element}> (\`${element}\`)`;
else return `» <@${element}> (\`${element}\`)`;
});
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.blacklist.response.list.title'))
.setDescription(blacklist.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.blacklist.response.list.title'))
.setDescription(blacklist.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
const is_role = role !== undefined || message.guild.roles.cache.has(id);
@@ -91,25 +97,29 @@ module.exports = class BlacklistCommand extends Command {
if (index === -1) {
new_blacklist.push(id);
await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n(`commands.blacklist.response.${member_or_role}_added.title`))
.setDescription(i18n(`commands.blacklist.response.${member_or_role}_added.description`, id))
.setFooter(settings.footer, message.guild.iconURL())
);
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n(`commands.blacklist.response.${member_or_role}_added.title`))
.setDescription(i18n(`commands.blacklist.response.${member_or_role}_added.description`, id))
.setFooter(settings.footer, message.guild.iconURL())
]
});
} else {
new_blacklist.splice(index, 1);
await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n(`commands.blacklist.response.${member_or_role}_removed.title`))
.setDescription(i18n(`commands.blacklist.response.${member_or_role}_removed.description`, id))
.setFooter(settings.footer, message.guild.iconURL())
);
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n(`commands.blacklist.response.${member_or_role}_removed.title`))
.setDescription(i18n(`commands.blacklist.response.${member_or_role}_removed.description`, id))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
settings.blacklist = new_blacklist;
await settings.save();
}
};
};

View File

@@ -7,7 +7,6 @@ const {
} = require('discord.js');
const { Op } = require('sequelize');
const toTime = require('to-time-monthsfork');
const { footer } = require('../utils/discord');
module.exports = class CloseCommand extends Command {
constructor(client) {
@@ -60,7 +59,7 @@ module.exports = class CloseCommand extends Command {
const arg_reason = this.args[1].name;
const arg_time = this.args[2].name;
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
if (args[arg_time]) {
@@ -69,13 +68,15 @@ module.exports = class CloseCommand extends Command {
try {
period = toTime(args[arg_time]).ms();
} catch {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.invalid_time.title'))
.setDescription(i18n('commands.close.response.invalid_time.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.invalid_time.title'))
.setDescription(i18n('commands.close.response.invalid_time.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
const tickets = await this.client.db.models.Ticket.findAndCountAll({
@@ -86,38 +87,46 @@ module.exports = class CloseCommand extends Command {
});
if (tickets.count === 0) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.no_tickets.title'))
.setDescription(i18n('commands.close.response.no_tickets.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.no_tickets.title'))
.setDescription(i18n('commands.close.response.no_tickets.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
} else {
const collector_message = await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.close.response.confirm_multiple.title'))
.setDescription(i18n('commands.close.response.confirm_multiple.description', tickets.count, tickets.count))
.setFooter(settings.footer, message.guild.iconURL())
);
const collector_message = await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.close.response.confirm_multiple.title'))
.setDescription(i18n('commands.close.response.confirm_multiple.description', tickets.count, tickets.count))
.setFooter(settings.footer, message.guild.iconURL())
]
});
await collector_message.react('✅');
const collector_filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '✅';
const collector = collector_message.createReactionCollector(collector_filter, { time: 30000 });
const filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '✅';
const collector = collector_message.createReactionCollector({
filter,
time: 30000
});
collector.on('collect', async () => {
await collector_message.reactions.removeAll();
await message.channel.send(
new MessageEmbed()
.setColor(settings.success_colour)
.setTitle(i18n('commands.close.response.closed_multiple.title', tickets.count, tickets.count))
.setDescription(i18n('commands.close.response.closed_multiple.description', tickets.count, tickets.count))
.setFooter(settings.footer, message.guild.iconURL())
);
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setTitle(i18n('commands.close.response.closed_multiple.title', tickets.count, tickets.count))
.setDescription(i18n('commands.close.response.closed_multiple.description', tickets.count, tickets.count))
.setFooter(settings.footer, message.guild.iconURL())
]
});
for (const ticket of tickets.rows) {
await this.client.tickets.close(ticket.id, message.author.id, message.guild.id, args[arg_reason]);
@@ -128,14 +137,16 @@ module.exports = class CloseCommand extends Command {
collector.on('end', async collected => {
if (collected.size === 0) {
await collector_message.reactions.removeAll();
await collector_message.edit(
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.close.response.confirmation_timeout.title'))
.setDescription(i18n('commands.close.response.confirmation_timeout.description'))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
);
await collector_message.edit({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.close.response.confirmation_timeout.title'))
.setDescription(i18n('commands.close.response.confirmation_timeout.description'))
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
});
setTimeout(async () => {
await collector_message
.delete()
@@ -155,41 +166,49 @@ module.exports = class CloseCommand extends Command {
t_row = await this.client.tickets.resolve(args[arg_ticket], message.guild.id);
if (!t_row) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.unresolvable.title'))
.setDescription(i18n('commands.close.response.unresolvable.description', args[arg_ticket]))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.unresolvable.title'))
.setDescription(i18n('commands.close.response.unresolvable.description', args[arg_ticket]))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
} else {
t_row = await this.client.db.models.Ticket.findOne({ where: { id: message.channel.id } });
if (!t_row) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.not_a_ticket.title'))
.setDescription(i18n('commands.close.response.not_a_ticket.description', settings.command_prefix))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.close.response.not_a_ticket.title'))
.setDescription(i18n('commands.close.response.not_a_ticket.description', settings.command_prefix))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
}
const collector_message = await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.close.response.confirm.title'))
.setDescription(i18n('commands.close.response.confirm.description', t_row.number))
.setFooter(settings.footer, message.guild.iconURL())
);
const collector_message = await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.close.response.confirm.title'))
.setDescription(i18n('commands.close.response.confirm.description', t_row.number))
.setFooter(settings.footer, message.guild.iconURL())
]
});
await collector_message.react('✅');
const collector_filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '✅';
const collector = collector_message.createReactionCollector(collector_filter, { time: 30000 });
const filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '✅';
const collector = collector_message.createReactionCollector({
filter,
time: 30000
});
collector.on('collect', async () => {
collector.stop();
@@ -198,13 +217,15 @@ module.exports = class CloseCommand extends Command {
await collector_message.delete();
} else {
await collector_message.reactions.removeAll();
await collector_message.edit(
new MessageEmbed()
.setColor(settings.success_colour)
.setTitle(i18n('commands.close.response.closed.title'))
.setDescription(i18n('commands.close.response.closed.description', t_row.number))
.setFooter(settings.footer, message.guild.iconURL())
);
await collector_message.edit({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setTitle(i18n('commands.close.response.closed.title'))
.setDescription(i18n('commands.close.response.closed.description', t_row.number))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
await this.client.tickets.close(t_row.id, message.author.id, message.guild.id, args[arg_reason]);
@@ -213,14 +234,16 @@ module.exports = class CloseCommand extends Command {
collector.on('end', async collected => {
if (collected.size === 0) {
await collector_message.reactions.removeAll();
await collector_message.edit(
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.close.response.confirmation_timeout.title'))
.setDescription(i18n('commands.close.response.confirmation_timeout.description'))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
);
await collector_message.edit({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.close.response.confirmation_timeout.title'))
.setDescription(i18n('commands.close.response.confirmation_timeout.description'))
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
});
setTimeout(async () => {
await collector_message
.delete()
@@ -234,4 +257,4 @@ module.exports = class CloseCommand extends Command {
}
}
};
};

View File

@@ -33,7 +33,7 @@ module.exports = class HelpCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const cmd = this.manager.commands.find(command => command.aliases.includes(args.toLowerCase()));
@@ -41,9 +41,9 @@ module.exports = class HelpCommand extends Command {
if (cmd) {
return await cmd.sendUsage(message.channel, args);
} else {
const is_staff = await message.member.isStaff();
const is_staff = await this.client.utils.isStaff(message.member);
const commands = this.manager.commands.filter(command => {
if (command.permissions.length >= 1) return message.member.hasPermission(command.permissions);
if (command.permissions.length >= 1) return message.member.permissions.has(command.permissions);
else if (command.staff_only) return is_staff;
else return true;
});
@@ -53,14 +53,16 @@ module.exports = class HelpCommand extends Command {
: command.description;
return `**\`${settings.command_prefix}${command.name}\` ·** ${description}`;
});
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.help.response.list.title'))
.setDescription(i18n('commands.help.response.list.description', { prefix: settings.command_prefix }))
.addField(i18n('commands.help.response.list.fields.commands'), list.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.help.response.list.title'))
.setDescription(i18n('commands.help.response.list.description', { prefix: settings.command_prefix }))
.addField(i18n('commands.help.response.list.fields.commands'), list.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
}
};
};

View File

@@ -3,7 +3,6 @@ const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
const { footer } = require('../utils/discord');
const { letters } = require('../utils/emoji');
const { wait } = require('../utils');
@@ -37,7 +36,7 @@ module.exports = class NewCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const editOrSend = async (msg, content) => {
@@ -57,12 +56,16 @@ module.exports = class NewCommand extends Command {
if (tickets.count >= cat_row.max_per_member) {
if (cat_row.max_per_member === 1) {
response = await editOrSend(response,
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.has_a_ticket.title'))
.setDescription(i18n('commands.new.response.has_a_ticket.description', tickets.rows[0].id))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
{
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.has_a_ticket.title'))
.setDescription(i18n('commands.new.response.has_a_ticket.description', tickets.rows[0].id))
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
}
);
} else {
const list = tickets.rows.map(row => {
@@ -75,33 +78,45 @@ module.exports = class NewCommand extends Command {
}
});
response = await editOrSend(response,
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.max_tickets.title', tickets.count))
.setDescription(i18n('commands.new.response.max_tickets.description', settings.command_prefix, list.join('\n')))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
{
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.max_tickets.title', tickets.count))
.setDescription(i18n('commands.new.response.max_tickets.description', settings.command_prefix, list.join('\n')))
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
}
);
}
} else {
try {
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)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.created.title'))
.setDescription(i18n('commands.new.response.created.description', `<#${t_row.id}>`))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
{
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.created.title'))
.setDescription(i18n('commands.new.response.created.description', `<#${t_row.id}>`))
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
}
);
} catch (error) {
response = await editOrSend(response,
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.error.title'))
.setDescription(error.message)
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
{
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.error.title'))
.setDescription(error.message)
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
}
);
}
}
@@ -119,39 +134,45 @@ module.exports = class NewCommand extends Command {
const categories = await this.client.db.models.Category.findAndCountAll({ where: { guild: message.guild.id } });
if (categories.count === 0) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.no_categories.title'))
.setDescription(i18n('commands.new.response.no_categories.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.no_categories.title'))
.setDescription(i18n('commands.new.response.no_categories.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
} else if (categories.count === 1) {
create(categories.rows[0]); // skip the category selection
} else {
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())
.setTitle(i18n('commands.new.response.select_category.title'))
.setDescription(i18n('commands.new.response.select_category.description', category_list.join('\n')))
.setFooter(footer(settings.footer, i18n('collector_expires_in', 30)), message.guild.iconURL())
);
const collector_message = await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.select_category.title'))
.setDescription(i18n('commands.new.response.select_category.description', category_list.join('\n')))
.setFooter(this.client.utils.footer(settings.footer, i18n('collector_expires_in', 30)), message.guild.iconURL())
]
});
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) => {
const filter = (reaction, user) => {
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);
};
const collector = collector_message.createReactionCollector(collector_filter, { time: 30000 });
const collector = collector_message.createReactionCollector({
filter,
time: 30000
});
collector.on('collect', async reaction => {
collector.stop();
@@ -168,14 +189,16 @@ module.exports = class NewCommand extends Command {
collector.on('end', async collected => {
if (collected.size === 0) {
await collector_message.reactions.removeAll();
await collector_message.edit(
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.select_category_timeout.title'))
.setDescription(i18n('commands.new.response.select_category_timeout.description'))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
);
await collector_message.edit({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.new.response.select_category_timeout.title'))
.setDescription(i18n('commands.new.response.select_category_timeout.description'))
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
});
setTimeout(async () => {
await collector_message
.delete()

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;
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
if (!args[arg_emoji]) args[arg_emoji] = [];
@@ -87,13 +87,15 @@ module.exports = class PanelCommand extends Command {
});
if (invalid_category) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.panel.response.invalid_category.title'))
.setDescription(i18n('commands.panel.response.invalid_category.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.panel.response.invalid_category.title'))
.setDescription(i18n('commands.panel.response.invalid_category.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
let panel_channel,
@@ -124,23 +126,25 @@ module.exports = class PanelCommand extends Command {
position: 1,
rateLimitPerUser: 30,
reason: `${message.author.tag} created a new reaction-less panel`,
type: 'text'
type: 'GUILD_TEXT'
});
embed.setDescription(args[arg_description]);
panel_message = await panel_channel.send(embed);
panel_message = await panel_channel.send({ embeds: [embed] });
this.client.log.info(`${message.author.tag} has created a new reaction-less panel`);
} else {
if (args[arg_categories].length !== args[arg_emoji].length) {
// send error
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.panel.response.mismatch.title'))
.setDescription(i18n('commands.panel.response.mismatch.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.panel.response.mismatch.title'))
.setDescription(i18n('commands.panel.response.mismatch.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
} else {
panel_channel = await message.guild.channels.create('create-a-ticket', {
permissionOverwrites: [
@@ -156,7 +160,7 @@ module.exports = class PanelCommand extends Command {
],
position: 1,
reason: `${message.author.tag} created a new panel`,
type: 'text'
type: 'GUILD_TEXT'
});
if (args[arg_emoji].length === 1) {
@@ -164,7 +168,7 @@ module.exports = class PanelCommand extends Command {
categories_map = {};
categories_map[args[arg_emoji][0]] = args[arg_categories][0];
embed.setDescription(args[arg_description]);
panel_message = await panel_channel.send(embed);
panel_message = await panel_channel.send({ embeds: [embed] });
await panel_message.react(args[arg_emoji][0]);
} else {
// multi category
@@ -183,7 +187,11 @@ module.exports = class PanelCommand extends Command {
}
embed.setDescription(args[arg_description] + '\n' + description);
panel_message = await panel_channel.send(embed);
panel_message = await panel_channel.send({
embeds: [
embed
]
});
for (const emoji of args[arg_emoji]) {
await panel_message.react(emoji);
@@ -196,7 +204,7 @@ module.exports = class PanelCommand extends Command {
}
}
message.channel.send(`${panel_channel}`);
message.channel.send({ content: `${panel_channel}` });
await this.client.db.models.Panel.create({
categories: categories_map,

View File

@@ -36,63 +36,73 @@ module.exports = class RemoveCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
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(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.not_a_ticket.title'))
.setDescription(i18n('commands.remove.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.not_a_ticket.title'))
.setDescription(i18n('commands.remove.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
const member = message.mentions.members.first() ?? message.guild.members.cache.get(args);
if (!member) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.no_member.title'))
.setDescription(i18n('commands.remove.response.no_member.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.no_member.title'))
.setDescription(i18n('commands.remove.response.no_member.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
if (t_row.creator !== message.author.id && !await message.member.isStaff()) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.no_permission.title'))
.setDescription(i18n('commands.remove.response.no_permission.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
if (t_row.creator !== message.author.id && !await this.client.utils.isStaff(message.member)) {
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.no_permission.title'))
.setDescription(i18n('commands.remove.response.no_permission.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
if (message.channel.id !== ticket.id) {
await message.channel.send(
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('commands.remove.response.removed.title'))
.setDescription(i18n('commands.remove.response.removed.description', member.toString(), ticket.toString()))
.setFooter(settings.footer, message.guild.iconURL())
);
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('commands.remove.response.removed.title'))
.setDescription(i18n('commands.remove.response.removed.description', member.toString(), ticket.toString()))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
await ticket.send(
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.member_removed.title'))
.setDescription(i18n('ticket.member_removed.description', member.toString(), message.author.toString()))
.setFooter(settings.footer, message.guild.iconURL())
);
await ticket.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.member_removed.title'))
.setDescription(i18n('ticket.member_removed.description', member.toString(), message.author.toString()))
.setFooter(settings.footer, message.guild.iconURL())
]
});
await ticket.permissionOverwrites
.get(member.user.id)
@@ -100,4 +110,4 @@ module.exports = class RemoveCommand extends Command {
this.client.log.info(`${message.author.tag} removed ${member.user.tag} from ${ticket.id}`);
}
};
};

View File

@@ -31,7 +31,7 @@ module.exports = class SettingsCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const attachments = [...message.attachments.values()];
@@ -48,7 +48,7 @@ module.exports = class SettingsCommand extends Command {
if (!valid) {
this.client.log.warn('Settings validation error');
return await message.channel.send(i18n('commands.settings.response.invalid', errors.map(error => `\`${error.stack}\``).join(',\n')));
return await message.channel.send({ content: i18n('commands.settings.response.invalid', errors.map(error => `\`${error.stack}\``).join(',\n')) });
}
settings.colour = data.colour;
@@ -84,7 +84,7 @@ module.exports = class SettingsCommand extends Command {
if (cat_channel.name !== c.name) await cat_channel.setName(c.name, `Tickets category updated by ${message.author.tag}`);
for (const r of c.roles) {
await cat_channel.updateOverwrite(r, {
await cat_channel.permissionOverwrites.edit(r, {
ATTACH_FILES: true,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
@@ -114,7 +114,7 @@ module.exports = class SettingsCommand extends Command {
],
position: 1,
reason: `Tickets category created by ${message.author.tag}`,
type: 'category'
type: 'GUILD_CATEGORY'
});
await this.client.db.models.Category.create({
@@ -149,7 +149,7 @@ module.exports = class SettingsCommand extends Command {
}
this.client.log.success(`Updated guild settings for "${message.guild.name}"`);
return await message.channel.send(i18n('commands.settings.response.updated'));
return await message.channel.send({ content: i18n('commands.settings.response.updated') });
} else {
// upload settings as json to be edited

View File

@@ -27,7 +27,7 @@ module.exports = class StatsCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const messages = await this.client.db.models.Message.findAndCountAll();
@@ -62,19 +62,25 @@ module.exports = class StatsCommand extends Command {
if (stats.messages) guild_embed.addField(i18n('commands.stats.fields.messages'), stats.messages, true);
await message.channel.send(guild_embed);
await message.channel.send({
embeds: [
guild_embed
]
});
if (this.client.guilds.cache.size > 1) {
await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.stats.response.global.title'))
.setDescription(i18n('commands.stats.response.global.description'))
.addField(i18n('commands.stats.fields.tickets'), stats.tickets, true)
.addField(i18n('commands.stats.fields.response_time.title'), i18n('commands.stats.fields.response_time.minutes', stats.response_time), true)
.addField(i18n('commands.stats.fields.messages'), stats.messages, true)
.setFooter(settings.footer, message.guild.iconURL())
);
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.stats.response.global.title'))
.setDescription(i18n('commands.stats.response.global.description'))
.addField(i18n('commands.stats.fields.tickets'), stats.tickets, true)
.addField(i18n('commands.stats.fields.response_time.title'), i18n('commands.stats.fields.response_time.minutes', stats.response_time), true)
.addField(i18n('commands.stats.fields.messages'), stats.messages, true)
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
}
};
};

View File

@@ -38,7 +38,7 @@ module.exports = class SurveyCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const survey = await this.client.db.models.Survey.findOne({
@@ -90,13 +90,15 @@ module.exports = class SurveyCommand extends Command {
const surveys = await this.client.db.models.Survey.findAll({ where: { guild: message.guild.id } });
const list = surveys.map(s => ` **\`${s.name}\`**`);
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.survey.response.list.title'))
.setDescription(list.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.survey.response.list.title'))
.setDescription(list.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
}
};
};

View File

@@ -37,7 +37,7 @@ module.exports = class TagCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const t_row = await this.client.db.models.Ticket.findOne({ where: { id: message.channel.id } });
@@ -52,13 +52,15 @@ module.exports = class TagCommand extends Command {
const requires_ticket = placeholders.some(p => p.startsWith('ticket.'));
if (requires_ticket && !t_row) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.tag.response.not_a_ticket.title'))
.setDescription(i18n('commands.tag.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.tag.response.not_a_ticket.title'))
.setDescription(i18n('commands.tag.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
const expected = placeholders
@@ -72,13 +74,15 @@ module.exports = class TagCommand extends Command {
try {
args = parseArgs(expected, { argv: argv(args) });
} catch (error) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.tag.response.error'))
.setDescription(`\`\`\`${error.message}\`\`\``)
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.tag.response.error'))
.setDescription(`\`\`\`${error.message}\`\`\``)
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
} else {
args = {};
@@ -87,13 +91,15 @@ module.exports = class TagCommand extends Command {
for (const p of expected) {
if (!args[p.name]) {
const list = expected.map(p => `\`${p.name}\``);
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.tag.response.error'))
.setDescription(i18n('commands.tag.response.missing', list.join(', ')))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.tag.response.error'))
.setDescription(i18n('commands.tag.response.missing', list.join(', ')))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
}
@@ -104,21 +110,25 @@ module.exports = class TagCommand extends Command {
// note that this regex is slightly different to the other
const text = tag.replace(/(?<!\\){{1,2}\s?:?([A-Za-z0-9._]+)\s?(?<!\\)}{1,2}/gi, (_$, $1) => this.client.i18n.resolve(args, $1));
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setDescription(text)
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setDescription(text)
]
});
} else {
const list = Object.keys(settings.tags).map(t => ` **\`${t}\`**`);
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.tag.response.list.title'))
.setDescription(list.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.tag.response.list.title'))
.setDescription(list.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
}
};
};

View File

@@ -30,19 +30,21 @@ module.exports = class TopicCommand extends Command {
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const t_row = await this.client.db.models.Ticket.findOne({ where: { id: message.channel.id } });
if (!t_row) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.topic.response.not_a_ticket.title'))
.setDescription(i18n('commands.topic.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.topic.response.not_a_ticket.title'))
.setDescription(i18n('commands.topic.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
await t_row.update({ topic: this.client.cryptr.encrypt(args) });
@@ -56,24 +58,28 @@ module.exports = class TopicCommand extends Command {
.replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString());
const opening_message = await message.channel.messages.fetch(t_row.opening_message);
await opening_message.edit(
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setDescription(description)
.addField(i18n('ticket.opening_message.fields.topic'), args)
.setFooter(settings.footer, message.guild.iconURL())
);
await opening_message.edit({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setDescription(description)
.addField(i18n('ticket.opening_message.fields.topic'), args)
.setFooter(settings.footer, message.guild.iconURL())
]
});
await message.channel.send(
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.topic.response.changed.title'))
.setDescription(i18n('commands.topic.response.changed.description'))
.setFooter(settings.footer, message.guild.iconURL())
);
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(i18n('commands.topic.response.changed.title'))
.setDescription(i18n('commands.topic.response.changed.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
this.client.log.info(`${message.author.tag} changed the topic of ${message.channel.id}`);
}
};
};