Merge pull request #209 from discord-tickets/d.js-v13

Update to discord.js v13
This commit is contained in:
Isaac 2021-08-16 21:19:44 +01:00 committed by GitHub
commit 6d4248d563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 1759 additions and 1060 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@eartharoid/discord-tickets",
"version": "3.0.0",
"version": "3.1.0-dev",
"private": true,
"description": "An open-source Discord bot for ticket management",
"main": "src/index.js",
@ -12,7 +12,7 @@
"test": "echo \"Nothing to test! Run with 'npm start'\" && exit 1"
},
"engines": {
"node": ">=14"
"node": ">=16.6"
},
"repository": {
"type": "git",
@ -32,33 +32,33 @@
"funding": "https://github.com/discord-tickets/bot/?sponsor=1",
"dependencies": {
"@eartharoid/i18n": "^1.0.0",
"boxen": "^5.0.0",
"command-line-args": "^5.1.1",
"boxen": "^5.0.1",
"command-line-args": "^5.2.0",
"cryptr": "^6.0.2",
"discord.js": "^12.5.1",
"dotenv": "^8.2.0",
"discord.js": "^13.1.0",
"dotenv": "^8.6.0",
"jsonschema": "^1.4.0",
"keyv": "^4.0.3",
"leeks.js": "^0.2.2",
"leekslazylogger-fastify": "^0.1.1",
"leekslazylogger": "^3.0.2",
"mustache": "^4.2.0",
"node-emoji": "^1.10.0",
"node-emoji": "^1.11.0",
"node-fetch": "^2.6.1",
"semver": "^7.3.4",
"sequelize": "^6.5.0",
"semver": "^7.3.5",
"sequelize": "^6.6.5",
"string-argv": "^0.3.1",
"terminal-link": "^2.1.1",
"to-time-monthsfork": "^1.1.4"
},
"devDependencies": {
"all-contributors-cli": "^6.20.0",
"eslint": "^7.21.0",
"mariadb": "^2.5.2",
"mysql2": "^2.2.5",
"nodemon": "^2.0.7",
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"tedious": "^11.0.3"
"eslint": "^7.32.0",
"mariadb": "^2.5.4",
"mysql2": "^2.3.0",
"nodemon": "^2.0.12",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"tedious": "^11.4.0"
},
"optionalDependencies": {
"sqlite3": "^5.0.2"

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
"description": "https:\/\/discordtickets.app",
"features": null,
"images": [
"quay.io\/parkervcp\/pterodactyl-images:debian_nodejs-14"
"quay.io\/parkervcp\/pterodactyl-images:debian_nodejs-16"
],
"file_denylist": [],
"startup": "if [[ ! -z ${VERSION} ]]; then\r\n echo -e \\\"Using version ${VERSION}\\\";\r\nelse\r\n echo -e \\\"Please set the VERSION variable \\(e.g. v3.0.0\\)\\\";\r\n exit 0;\r\nfi;\r\n\r\nif [[ -d .git ]]; then\r\n git fetch --all --tags;\r\n git checkout tags\/${VERSION};\r\nfi;\r\n\r\nif [[ ! -z ${PLUGINS} ]]; then\r\n \/usr\/local\/bin\/npm install ${PLUGINS};\r\nfi;\r\n\r\nif [ -f \/home\/container\/package.json ]; then\r\n \/usr\/local\/bin\/npm install --production;\r\nfi;\r\n\r\n\/usr\/local\/bin\/npm start",

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(
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(
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(
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(
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(
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,

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(
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(
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(
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,22 +97,26 @@ module.exports = class BlacklistCommand extends Command {
if (index === -1) {
new_blacklist.push(id);
await message.channel.send(
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(
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;

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(
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(
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(
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(
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(
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(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
);
.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(
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(
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(
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(
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(
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(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
);
.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

@ -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(
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,
{
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(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
.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,
{
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(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
.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,
{
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(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
]
}
);
} catch (error) {
response = await editOrSend(response,
{
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(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
.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(
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(
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(footer(settings.footer, i18n('collector_expires_in', 30)), message.guild.iconURL())
);
.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(
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(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
);
.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(
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(
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(
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(
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(
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(
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(
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)

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,10 +62,15 @@ 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(
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.stats.response.global.title'))
@ -74,7 +79,8 @@ module.exports = class StatsCommand extends Command {
.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(
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(
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(
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(
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,20 +110,24 @@ 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(
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(
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(
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,23 +58,27 @@ 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(
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(
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}`);
}

View File

@ -24,8 +24,9 @@
process.title = 'Discord Tickets';
const node_version = Number(process.versions.node.split('.')[0]);
if (node_version < 14) return console.log(`\x07Error: Discord Tickets does not work on Node v${node_version}. Please upgrade to v14 or above.`);
const min_node_version = '16.6.0';
const semver = require('semver');
if (semver.lt(process.versions.node, min_node_version)) return console.log(`\x07Error: Discord Tickets does not work on Node v${process.versions.node}; please upgrade to v${min_node_version} or above.`);
const leeks = require('leeks.js');
const fs = require('fs');
@ -82,7 +83,7 @@ process.on('unhandledRejection', error => {
log.error(error);
});
const { selectPresence } = require('./utils/discord');
const DiscordUtils = require('./utils/discord');
const Cryptr = require('cryptr');
const I18n = require('@eartharoid/i18n');
const ListenerLoader = require('./modules/listeners/loader');
@ -92,14 +93,12 @@ const TicketManager = require('./modules/tickets/manager');
const fetch = require('node-fetch');
require('./modules/structures')(); // load extended structures before creating the client
const {
Client,
Intents
} = require('discord.js');
// eslint-disable-next-line no-unused-vars
const FastifyLogger = require('leekslazylogger-fastify');
const Logger = require('leekslazylogger');
/**
* The Discord client
@ -109,13 +108,18 @@ const FastifyLogger = require('leekslazylogger-fastify');
class Bot extends Client {
constructor() {
super({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS
],
partials: [
'CHANNEL',
'MESSAGE',
'REACTION'
],
presence: selectPresence(),
ws: { intents: Intents.NON_PRIVILEGED }
presence: DiscordUtils.selectPresence()
});
(async () => {
@ -124,7 +128,7 @@ class Bot extends Client {
/**
* A [leekslazylogger](https://logger.eartharoid.me) instance
* @type {FastifyLogger}
* @type {Logger}
*/
this.log = log;
@ -169,6 +173,9 @@ class Bot extends Client {
this.plugins = new PluginManager(this);
this.plugins.load(); // load plugins
/** Some utility methods */
this.utils = new DiscordUtils(this);
this.log.info('Connecting to Discord API...');
this.login();

View File

@ -7,6 +7,6 @@ module.exports = class GuildDeleteEventListener extends EventListener {
async execute(guild) {
this.client.log.info(`Removed from "${guild.name}"`);
// await guild.deleteSettings();
await guild.deleteSettings();
}
};

View File

@ -1,17 +1,16 @@
const EventListener = require('../modules/listeners/listener');
const { MessageEmbed } = require('discord.js');
const { footer } = require('../utils/discord');
module.exports = class MessageEventListener extends EventListener {
module.exports = class MessageCreateEventListener extends EventListener {
constructor(client) {
super(client, { event: 'message' });
super(client, { event: 'messageCreate' });
}
async execute(message) {
if (!message.guild) return;
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 } });
@ -53,11 +52,11 @@ module.exports = class MessageEventListener extends EventListener {
.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());
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL());
try {
response = await message.author.send(embed);
response = await message.author.send({ embeds: [embed] });
} catch {
response = await message.channel.send(embed);
response = await message.channel.send({ embeds: [embed] });
}
} else {
const list = tickets.rows.map(row => {
@ -74,11 +73,11 @@ module.exports = class MessageEventListener extends EventListener {
.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.author.iconURL());
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.author.iconURL());
try {
response = await message.author.send(embed);
response = await message.author.send({ embeds: [embed] });
} catch {
response = await message.channel.send(embed);
response = await message.channel.send({ embeds: [embed] });
}
}
} else {
@ -90,11 +89,11 @@ module.exports = class MessageEventListener extends EventListener {
.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());
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL());
try {
response = await message.author.send(embed);
response = await message.author.send({ embeds: [embed] });
} catch {
response = await message.channel.send(embed);
response = await message.channel.send({ embeds: [embed] });
}
}
}

View File

@ -8,7 +8,7 @@ module.exports = class MessageDeleteEventListener extends EventListener {
async execute(message) {
if (!message.guild) return;
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
if (settings.log_messages && !message.system) this.client.tickets.archives.deleteMessage(message); // mark the message as deleted in the database (if it exists)
}

View File

@ -1,89 +1,90 @@
const EventListener = require('../modules/listeners/listener');
const { MessageEmbed } = require('discord.js');
const { footer } = require('../utils/discord');
module.exports = class MessageReactionAddEventListener extends EventListener {
constructor(client) {
super(client, { event: 'messageReactionAdd' });
}
async execute(r, u) {
async execute(reaction, user) {
if (r.partial) {
if (reaction.partial) {
try {
await r.fetch();
await reaction.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.partial) {
if (user.partial) {
try {
await u.fetch();
await user.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.id === this.client.user.id) return;
if (user.id === this.client.user.id) return;
const guild = r.message.guild;
const guild = reaction.message.guild;
if (!guild) return;
const settings = await guild.getSettings();
const settings = await this.client.utils.getSettings(guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const channel = r.message.channel;
const member = await guild.members.fetch(u.id);
const channel = reaction.message.channel;
const member = await guild.members.fetch(user.id);
if (settings.blacklist.includes(u.id)) {
return this.client.log.info(`Ignoring blacklisted member ${u.tag}`);
if (settings.blacklist.includes(user.id)) {
return this.client.log.info(`Ignoring blacklisted member ${user.tag}`);
} else {
settings.blacklist.forEach(element => {
if (guild.roles.cache.has(element) && member.roles.cache.has(element)) {
return this.client.log.info(`Ignoring member ${u.tag} with blacklisted role`);
return this.client.log.info(`Ignoring member ${user.tag} with blacklisted role`);
}
});
}
const t_row = await this.client.db.models.Ticket.findOne({ where: { id: channel.id } });
if (t_row && t_row.opening_message === r.message.id) {
if (r.emoji.name === '🙌' && await member.isStaff()) {
if (t_row && t_row.opening_message === reaction.message.id) {
if (reaction.emoji.name === '🙌' && await this.client.utils.isStaff(member)) {
// ticket claiming
await t_row.update({ claimed_by: member.user.id });
await channel.updateOverwrite(member.user.id, { VIEW_CHANNEL: true }, `Ticket claimed by ${member.user.tag}`);
await channel.permissionOverwrites.edit(member.user.id, { VIEW_CHANNEL: true }, `Ticket claimed by ${member.user.tag}`);
const cat_row = await this.client.db.models.Category.findOne({ where: { id: t_row.category } });
for (const role of cat_row.roles) {
await channel.updateOverwrite(role, { VIEW_CHANNEL: false }, `Ticket claimed by ${member.user.tag}`);
await channel.permissionOverwrites.edit(role, { VIEW_CHANNEL: false }, `Ticket claimed by ${member.user.tag}`);
}
this.client.log.info(`${member.user.tag} has claimed "${channel.name}" in "${guild.name}"`);
await channel.send(
await channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.claimed.title'))
.setDescription(i18n('ticket.claimed.description', member.toString()))
.setFooter(settings.footer, guild.iconURL())
);
]
});
} else {
await r.users.remove(u.id);
await reaction.users.remove(user.id);
}
} else {
const p_row = await this.client.db.models.Panel.findOne({ where: { message: r.message.id } });
const p_row = await this.client.db.models.Panel.findOne({ where: { message: reaction.message.id } });
if (p_row && typeof p_row.categories !== 'string') {
// panels
await r.users.remove(u.id);
await reaction.users.remove(user.id);
const category_id = p_row.categories[r.emoji.name];
const category_id = p_row.categories[reaction.emoji.name];
if (!category_id) return;
const cat_row = await this.client.db.models.Category.findOne({ where: { id: category_id } });
@ -91,7 +92,7 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: {
category: cat_row.id,
creator: u.id,
creator: user.id,
open: true
}
});
@ -102,14 +103,14 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
if (cat_row.max_per_member === 1) {
const embed = new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(u.username, u.displayAvatarURL())
.setAuthor(user.username, user.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)), guild.iconURL());
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), guild.iconURL());
try {
response = await u.send(embed);
response = await user.send({ embeds: [embed] });
} catch {
response = await channel.send(embed);
response = await channel.send({ embeds: [embed] });
}
} else {
const list = tickets.rows.map(row => {
@ -123,30 +124,30 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
});
const embed = new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(u.username, u.displayAvatarURL())
.setAuthor(user.username, user.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)), u.iconURL());
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), user.iconURL());
try {
response = await u.send(embed);
response = await user.send({ embeds: [embed] });
} catch {
response = await channel.send(embed);
response = await channel.send({ embeds: [embed] });
}
}
} else {
try {
await this.client.tickets.create(guild.id, u.id, cat_row.id);
await this.client.tickets.create(guild.id, user.id, cat_row.id);
} catch (error) {
const embed = new MessageEmbed()
.setColor(settings.error_colour)
.setAuthor(u.username, u.displayAvatarURL())
.setAuthor(user.username, user.displayAvatarURL())
.setTitle(i18n('commands.new.response.error.title'))
.setDescription(error.message)
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), guild.iconURL());
.setFooter(this.client.utils.footer(settings.footer, i18n('message_will_be_deleted_in', 15)), guild.iconURL());
try {
response = await u.send(embed);
response = await user.send({ embeds: [embed] });
} catch {
response = await channel.send(embed);
response = await channel.send({ embeds: [embed] });
}
}
}

View File

@ -7,39 +7,39 @@ module.exports = class MessageReactionRemoveEventListener extends EventListener
super(client, { event: 'messageReactionRemove' });
}
async execute(r, u) {
async execute(reaction, user) {
// release (unclaim) ticket
if (r.partial) {
if (reaction.partial) {
try {
await r.fetch();
await reaction.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.partial) {
if (user.partial) {
try {
await u.fetch();
await user.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.id === this.client.user.id) return;
if (user.id === this.client.user.id) return;
const guild = r.message.guild;
const guild = reaction.message.guild;
if (!guild) return;
const settings = await guild.getSettings();
const settings = await this.client.utils.getSettings(guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const channel = r.message.channel;
const member = await guild.members.fetch(u.id);
const channel = reaction.message.channel;
const member = await guild.members.fetch(user.id);
const t_row = await this.client.db.models.Ticket.findOne({ where: { id: channel.id } });
if (t_row && t_row.opening_message === r.message.id) {
if (r.emoji.name === '🙌' && await member.isStaff()) {
if (t_row && t_row.opening_message === reaction.message.id) {
if (reaction.emoji.name === '🙌' && await this.client.utils.isStaff(member)) {
// ticket claiming
await t_row.update({ claimed_by: null });
@ -51,19 +51,21 @@ module.exports = class MessageReactionRemoveEventListener extends EventListener
const cat_row = await this.client.db.models.Category.findOne({ where: { id: t_row.category } });
for (const role of cat_row.roles) {
await channel.updateOverwrite(role, { VIEW_CHANNEL: true }, `Ticket released by ${member.user.tag}`);
await channel.permissionOverwrites.edit(role, { VIEW_CHANNEL: true }, `Ticket released by ${member.user.tag}`);
}
this.client.log.info(`${member.user.tag} has released "${channel.name}" in "${guild.name}"`);
await channel.send(
await channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.released.title'))
.setDescription(i18n('ticket.released.description', member.toString()))
.setFooter(settings.footer, guild.iconURL())
);
]
});
}
}
}

View File

@ -16,7 +16,7 @@ module.exports = class MessageUpdateEventListener extends EventListener {
if (!newm.guild) return;
const settings = await newm.guild.getSettings();
const settings = await this.client.utils.getSettings(newm.guild);
if (settings.log_messages && !newm.system) this.client.tickets.archives.updateMessage(newm); // update the message in the database
}

View File

@ -20,7 +20,7 @@ module.exports = class ReadyEventListener extends EventListener {
setInterval(() => {
const presence = selectPresence();
this.client.user.setPresence(presence);
this.client.log.debug(`Updated presence: ${presence.activity.type} ${presence.activity.name}`);
this.client.log.debug(`Updated presence: ${presence.activities[0].type} ${presence.activities[0].name}`);
}, this.client.config.presence.duration * 1000);
}

View File

@ -1,6 +1,6 @@
const { path } = require('./utils/fs');
const config = require('../user/config');
const Logger = require('leekslazylogger-fastify');
const Logger = require('leekslazylogger');
module.exports = new Logger({
debug: config.debug,
directory: path('./logs/'),

View File

@ -122,7 +122,7 @@ module.exports = class Command {
* @returns {Promise<Message>}
*/
async sendUsage(channel, alias) {
const settings = await channel.guild.getSettings();
const settings = await this.client.utils.getSettings(channel.guild);
if (!alias) alias = this.name;
const prefix = settings.command_prefix;
@ -156,7 +156,7 @@ module.exports = class Command {
}
this.args.forEach(arg => addArgs(embed, arg));
return await channel.send(embed);
return await channel.send({ embeds: [embed] });
}

View File

@ -72,7 +72,7 @@ module.exports = class CommandManager {
async handle(message) {
if (message.author.bot) return; // ignore self and other bots
const settings = await message.guild.getSettings();
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const prefix = settings.command_prefix;
const escaped_prefix = prefix.toLowerCase().replace(/(?=\W)/g, '\\'); // (lazy) escape every character so it can be used in a RexExp
@ -122,14 +122,16 @@ module.exports = class CommandManager {
if (!bot_permissions.has(required_bot_permissions)) {
const perms = required_bot_permissions.map(p => `\`${p}\``).join(', ');
if (bot_permissions.has(['EMBED_LINKS', 'SEND_MESSAGES'])) {
await message.channel.send(
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor('ORANGE')
.setTitle(i18n('bot.missing_permissions.title'))
.setDescription(i18n('bot.missing_permissions.description', perms))
);
]
});
} else if (bot_permissions.has('SEND_MESSAGES')) {
await message.channel.send('⚠️ ' + i18n('bot.missing_permissions.description', perms));
await message.channel.send({ content: '⚠️ ' + i18n('bot.missing_permissions.description', perms) });
} else if (bot_permissions.has('ADD_REACTIONS')) {
await message.react('⚠️');
} else {
@ -138,24 +140,28 @@ module.exports = class CommandManager {
return;
}
const missing_permissions = cmd.permissions instanceof Array && !message.member.hasPermission(cmd.permissions);
const missing_permissions = cmd.permissions instanceof Array && !message.member.permissions.has(cmd.permissions);
if (missing_permissions) {
const perms = cmd.permissions.map(p => `\`${p}\``).join(', ');
return await message.channel.send(
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('missing_permissions.title'))
.setDescription(i18n('missing_permissions.description', perms))
);
]
});
}
if (cmd.staff_only && await message.member.isStaff() === false) {
return await message.channel.send(
if (cmd.staff_only && await this.client.utils.isStaff(message.member) === false) {
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('staff_only.title'))
.setDescription(i18n('staff_only.description'))
);
]
});
}
let args = raw_args;
@ -165,12 +171,14 @@ module.exports = class CommandManager {
args = parseArgs(cmd.args, { argv: argv(raw_args) });
} catch (error) {
const help_cmd = `${settings.command_prefix}${i18n('commands.help.name')} ${cmd_name}`;
return await message.channel.send(
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('cmd_usage.invalid_named_args.title'))
.setDescription(i18n('cmd_usage.invalid_named_args.description', error.message, help_cmd))
);
]
});
}
for (const arg of cmd.args) {
if (arg.required && args[arg.name] === undefined) {
@ -191,12 +199,14 @@ module.exports = class CommandManager {
} catch (e) {
this.client.log.warn(`An error occurred whilst executing the ${cmd.name} command`);
this.client.log.error(e);
await message.channel.send(
await message.channel.send({
embeds: [
new MessageEmbed()
.setColor('ORANGE')
.setTitle(i18n('command_execution_error.title'))
.setDescription(i18n('command_execution_error.description'))
); // hopefully no user will ever see this message
]
}); // hopefully no user will ever see this message
}
}

View File

@ -1,9 +0,0 @@
const fs = require('fs');
const { path } = require('../utils/fs');
module.exports = () => {
const files = fs.readdirSync(path('./src/structures'))
.filter(file => file.endsWith('.js'));
for (const file of files) require(`../structures/${file}`);
};

View File

@ -2,7 +2,6 @@
const EventEmitter = require('events');
const TicketArchives = require('./archives');
const { MessageEmbed } = require('discord.js');
const { footer } = require('../../utils/discord');
/** Manages tickets */
module.exports = class TicketManager extends EventEmitter {
@ -51,10 +50,10 @@ module.exports = class TicketManager extends EventEmitter {
parent: category_id,
reason: `${creator.user.tag} requested a new ticket channel`,
topic: `${creator}${topic.length > 0 ? ` | ${topic}` : ''}`,
type: 'text'
type: 'GUILD_TEXT'
});
t_channel.updateOverwrite(creator_id, {
t_channel.permissionOverwrites.edit(creator_id, {
ATTACH_FILES: true,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
@ -71,7 +70,7 @@ module.exports = class TicketManager extends EventEmitter {
});
(async () => {
const settings = await guild.getSettings();
const settings = await this.client.utils.getSettings(guild);
const i18n = this.client.i18n.getLocale(settings.locale);
topic = t_row.topic
@ -85,11 +84,11 @@ module.exports = class TicketManager extends EventEmitter {
? '@here'
: `<@&${id}>`);
await t_channel.send(mentions.join(', '));
await t_channel.send({ content: mentions.join(', ') });
}
if (cat_row.image) {
await t_channel.send(cat_row.image);
await t_channel.send({ content: cat_row.image });
}
const description = cat_row.opening_message
@ -103,7 +102,10 @@ module.exports = class TicketManager extends EventEmitter {
if (topic) embed.addField(i18n('ticket.opening_message.fields.topic'), topic);
const sent = await t_channel.send(creator.user.toString(), embed);
const sent = await t_channel.send({
content: creator.user.toString(),
embeds: [embed]
});
await sent.pin({ reason: 'Ticket opening message' });
await t_row.update({ opening_message: sent.id });
@ -128,17 +130,21 @@ module.exports = class TicketManager extends EventEmitter {
}
if (cat_row.require_topic && topic.length === 0) {
const collector_message = await t_channel.send(
const collector_message = await t_channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle('⚠️ ' + i18n('commands.new.request_topic.title'))
.setDescription(i18n('commands.new.request_topic.description'))
.setFooter(footer(settings.footer, i18n('collector_expires_in', 120)), guild.iconURL())
);
.setFooter(this.client.utils.footer(settings.footer, i18n('collector_expires_in', 120)), guild.iconURL())
]
});
const collector_filter = message => message.author.id === t_row.creator;
const collector = t_channel.createMessageCollector(collector_filter, { time: 120000 });
const filter = message => message.author.id === t_row.creator;
const collector = t_channel.createMessageCollector({
filter,
time: 120000
});
collector.on('collect', async message => {
topic = message.content;
@ -161,22 +167,26 @@ module.exports = class TicketManager extends EventEmitter {
.delete()
.catch(() => this.client.log.warn('Failed to delete topic collector message'));
if (cat_row.opening_questions) {
await t_channel.send(
await t_channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setDescription(i18n('ticket.questions', questions))
.setFooter(settings.footer, guild.iconURL())
);
]
});
}
});
} else {
if (cat_row.opening_questions) {
await t_channel.send(
await t_channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setDescription(i18n('ticket.questions', questions))
.setFooter(settings.footer, guild.iconURL())
);
]
});
}
}
})();
@ -203,7 +213,7 @@ module.exports = class TicketManager extends EventEmitter {
this.emit('beforeClose', ticket_id);
const guild = this.client.guilds.cache.get(t_row.guild);
const settings = await guild.getSettings();
const settings = await this.client.utils.getSettings(guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const channel = await this.client.channels.fetch(t_row.id);
@ -224,14 +234,16 @@ module.exports = class TicketManager extends EventEmitter {
const description = reason
? i18n('ticket.closed_by_member_with_reason.description', closer.user.toString(), reason)
: i18n('ticket.closed_by_member.description', closer.user.toString());
await channel.send(
await channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setAuthor(closer.user.username, closer.user.displayAvatarURL())
.setTitle(i18n('ticket.closed.title'))
.setDescription(description)
.setFooter(settings.footer, guild.iconURL())
);
]
});
setTimeout(async () => {
await channel.delete(`Ticket channel closed by ${closer.user.tag}${reason ? `: "${reason}"` : ''}`);
@ -242,13 +254,15 @@ module.exports = class TicketManager extends EventEmitter {
const description = reason
? i18n('ticket.closed_with_reason.description')
: i18n('ticket.closed.description');
await channel.send(
await channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setTitle(i18n('ticket.closed.title'))
.setDescription(description)
.setFooter(settings.footer, guild.iconURL())
);
]
});
setTimeout(async () => {
await channel.delete(`Ticket channel closed${reason ? `: "${reason}"` : ''}`);
@ -272,20 +286,25 @@ module.exports = class TicketManager extends EventEmitter {
});
if (survey) {
const r_collector_message = await channel.send(
creator.toString(),
const r_collector_message = await channel.send({
content: creator.toString(),
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('ticket.survey.start.title'))
.setDescription(i18n('ticket.survey.start.description', creator.toString(), survey.questions.length))
.setFooter(i18n('collector_expires_in', 60))
);
]
});
await r_collector_message.react('✅');
const collector_filter = (reaction, user) => user.id === creator.user.id && reaction.emoji.name === '✅';
const filter = (reaction, user) => user.id === creator.user.id && reaction.emoji.name === '✅';
const r_collector = r_collector_message.createReactionCollector(collector_filter, { time: 60000 });
const r_collector = r_collector_message.createReactionCollector({
filter,
time: 60000
});
r_collector.on('collect', async () => {
r_collector.stop();
@ -293,17 +312,20 @@ module.exports = class TicketManager extends EventEmitter {
let answers = [];
let number = 1;
for (const question of survey.questions) {
await channel.send(
await channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.colour)
.setTitle(`${number++}/${survey.questions.length}`)
.setDescription(question)
.setFooter(i18n('collector_expires_in', 60))
);
]
});
try {
const collected = await channel.awaitMessages(filter, {
const collected = await channel.awaitMessages({
errors: ['time'],
filter,
max: 1,
time: 60000
});
@ -313,13 +335,15 @@ module.exports = class TicketManager extends EventEmitter {
}
}
await channel.send(
await channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.success_colour)
.setTitle(i18n('ticket.survey.complete.title'))
.setDescription(i18n('ticket.survey.complete.description'))
.setFooter(settings.footer, guild.iconURL())
);
]
});
answers = answers.map(a => this.client.cryptr.encrypt(a));
await this.client.db.models.SurveyResponse.create({

View File

@ -1,21 +0,0 @@
const { Structures } = require('discord.js');
Structures.extend('Guild', Guild => class extends Guild {
constructor(client, data) {
super(client, data);
}
async deleteSettings() {
const row = await this.settings;
return await row.destroy();
}
async getSettings() {
const data = { id: this.id };
const [settings] = await this.client.db.models.Guild.findOrCreate({
defaults: data,
where: data
});
return settings;
}
});

View File

@ -1,14 +0,0 @@
const { Structures } = require('discord.js');
Structures.extend('GuildMember', GuildMember => class extends GuildMember {
constructor(client, data, guild) {
super(client, data, guild);
}
async isStaff() {
const guild_categories = await this.client.db.models.Category.findAll({ where: { guild: this.guild.id } });
return guild_categories.some(cat => cat.roles.some(r => this.roles.cache.has(r)));
}
});

View File

@ -1,23 +1,66 @@
const config = require('../../user/config');
const {
Guild, // eslint-disable-line no-unused-vars
GuildMember // eslint-disable-line no-unused-vars
} = require('discord.js');
const config = require('../../user/config');
let current_presence = -1;
module.exports = {
module.exports = class DiscordUtils {
constructor(client) {
this.client = client;
}
/**
*
* Generate embed footer text
* @param {string} text
* @param {string} [additional]
* @returns {string}
*/
footer: (text, additional) => {
footer(text, additional) {
if (text && additional) return `${text} | ${additional}`;
else return additional || text || '';
},
}
/**
* Check if a guild member is staff
* @param {GuildMember} member - the guild member
* @returns {boolean}
*/
async isStaff(member) {
const guild_categories = await this.client.db.models.Category.findAll({ where: { guild: member.guild.id } });
return guild_categories.some(cat => cat.roles.some(r => member.roles.cache.has(r)));
}
/**
* get a guild's settings
* @param {Guild} guild - The Guild
* @returns {Promise<Model>}
*/
async getSettings(guild) {
const data = { id: guild.id };
const [settings] = await this.client.db.models.Guild.findOrCreate({
defaults: data,
where: data
});
return settings;
}
/**
* Delete a guild's settings
* @param {Guild} guild - The Guild
* @returns {Promise<Number>}
*/
async deleteSettings(guild) {
const row = await this.getSettings(guild);
return await row.destroy();
}
/**
* Select a presence from the config
* @returns {PresenceData}
*/
selectPresence: () => {
static selectPresence() {
const length = config.presence.presences.length;
if (length === 0) return {};
@ -42,11 +85,13 @@ module.exports = {
} = config.presence.presences[num];
return {
activity: {
activities: [
{
name,
type,
url
},
}
],
status
};
}