mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-04 09:21:25 +03:00
Make @davidjcralph happy
const
This commit is contained in:
@@ -120,14 +120,14 @@ module.exports = class Command {
|
||||
* @returns {Message}
|
||||
*/
|
||||
async sendUsage(channel, alias) {
|
||||
let settings = await channel.guild.settings;
|
||||
const settings = await channel.guild.settings;
|
||||
if (!alias) alias = this.name;
|
||||
|
||||
const prefix = settings.command_prefix;
|
||||
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||
|
||||
const addArgs = (embed, arg) => {
|
||||
let required = arg.required ? '`❗` ' : '';
|
||||
const required = arg.required ? '`❗` ' : '';
|
||||
let description = `» ${i18n('cmd_usage.args.description', arg.description)}`;
|
||||
if (arg.example) description += `\n» ${i18n('cmd_usage.args.example', arg.example)}`;
|
||||
embed.addField(required + arg.name, description);
|
||||
|
@@ -48,7 +48,7 @@ module.exports = class CommandManager {
|
||||
const is_internal = (exists && cmd.internal) || (exists && this.commands.get(cmd.name).internal);
|
||||
|
||||
if (is_internal) {
|
||||
let plugin = this.client.plugins.plugins.find(p => p.commands.includes(cmd.name));
|
||||
const plugin = this.client.plugins.plugins.find(p => p.commands.includes(cmd.name));
|
||||
if (plugin)
|
||||
this.client.log.commands(`The "${plugin.name}" plugin has overridden the internal "${cmd.name}" command`);
|
||||
else
|
||||
@@ -69,7 +69,7 @@ module.exports = class CommandManager {
|
||||
async handle(message) {
|
||||
if (message.author.bot) return; // ignore self and other bots
|
||||
|
||||
let settings = await message.guild.settings;
|
||||
const settings = await message.guild.settings;
|
||||
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||
|
||||
let is_blacklisted = false;
|
||||
@@ -100,14 +100,14 @@ module.exports = class CommandManager {
|
||||
let cmd_name = message.content.match(new RegExp(`^(${escaped_prefix}|${client_mention}\\s?)(\\S+)`, 'mi')); // capture prefix and command
|
||||
if (!cmd_name) return; // stop here if the message is not a command
|
||||
|
||||
let raw_args = message.content.replace(cmd_name[0], '').trim(); // remove the prefix and command
|
||||
const raw_args = message.content.replace(cmd_name[0], '').trim(); // remove the prefix and command
|
||||
cmd_name = cmd_name[2].toLowerCase(); // set cmd_name to the actual command alias, effectively removing the prefix
|
||||
|
||||
const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name));
|
||||
if (!cmd) return;
|
||||
|
||||
let bot_permissions = message.guild.me.permissionsIn(message.channel);
|
||||
let required_bot_permissions = [
|
||||
const bot_permissions = message.guild.me.permissionsIn(message.channel);
|
||||
const required_bot_permissions = [
|
||||
'ADD_REACTIONS',
|
||||
'ATTACH_FILES',
|
||||
'EMBED_LINKS',
|
||||
@@ -118,7 +118,7 @@ module.exports = class CommandManager {
|
||||
];
|
||||
|
||||
if (!bot_permissions.has(required_bot_permissions)) {
|
||||
let perms = required_bot_permissions.map(p => `\`${p}\``).join(', ');
|
||||
const perms = required_bot_permissions.map(p => `\`${p}\``).join(', ');
|
||||
if (bot_permissions.has(['EMBED_LINKS', 'SEND_MESSAGES'])) {
|
||||
await message.channel.send(
|
||||
new MessageEmbed()
|
||||
@@ -138,7 +138,7 @@ module.exports = class CommandManager {
|
||||
|
||||
const missing_permissions = cmd.permissions instanceof Array && !message.member.hasPermission(cmd.permissions);
|
||||
if (missing_permissions) {
|
||||
let perms = cmd.permissions.map(p => `\`${p}\``).join(', ');
|
||||
const perms = cmd.permissions.map(p => `\`${p}\``).join(', ');
|
||||
return await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.error_colour)
|
||||
@@ -162,7 +162,7 @@ module.exports = class CommandManager {
|
||||
try {
|
||||
args = parseArgs(cmd.args, { argv: argv(raw_args) });
|
||||
} catch (error) {
|
||||
let help_cmd = `${settings.command_prefix}${i18n('commands.help.name')} ${cmd_name}`;
|
||||
const help_cmd = `${settings.command_prefix}${i18n('commands.help.name')} ${cmd_name}`;
|
||||
return await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.error_colour)
|
||||
@@ -170,7 +170,7 @@ module.exports = class CommandManager {
|
||||
.setDescription(i18n('cmd_usage.invalid_named_args.description', error.message, help_cmd))
|
||||
);
|
||||
}
|
||||
for (let arg of cmd.args) {
|
||||
for (const arg of cmd.args) {
|
||||
if (arg.required && args[arg.name] === undefined) {
|
||||
return await cmd.sendUsage(message.channel, cmd_name); // send usage if any required arg is missing
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ module.exports = class ListenerLoader {
|
||||
try {
|
||||
file = require(`../../listeners/${file}`);
|
||||
const listener = new file(this.client);
|
||||
let on = listener.once ? 'once' : 'on';
|
||||
const on = listener.once ? 'once' : 'on';
|
||||
if (listener.raw)
|
||||
this.client.ws[on](listener.event, (...data) => listener.execute(...data));
|
||||
else
|
||||
|
@@ -55,7 +55,7 @@ module.exports = class PluginManager {
|
||||
author = author.name ?? 'unknown';
|
||||
}
|
||||
|
||||
let about = {
|
||||
const about = {
|
||||
id,
|
||||
version,
|
||||
author,
|
||||
@@ -79,8 +79,8 @@ module.exports = class PluginManager {
|
||||
load() {
|
||||
this.client.config.plugins.forEach(plugin => {
|
||||
try {
|
||||
let main = require(plugin);
|
||||
let pkg = require(`${plugin}/package.json`);
|
||||
const main = require(plugin);
|
||||
const pkg = require(`${plugin}/package.json`);
|
||||
this.register(main, pkg);
|
||||
} catch (e) {
|
||||
this.handleError(plugin);
|
||||
|
@@ -27,7 +27,7 @@ module.exports = class Plugin {
|
||||
/** An official plugin? */
|
||||
this.official = this.manager.official.includes(this.id);
|
||||
|
||||
let {
|
||||
const {
|
||||
id,
|
||||
version,
|
||||
author,
|
||||
@@ -70,7 +70,7 @@ module.exports = class Plugin {
|
||||
*/
|
||||
this.description = description;
|
||||
|
||||
let clean = this.id.replace(/@[-_a-zA-Z0-9]+\//, '');
|
||||
const clean = this.id.replace(/@[-_a-zA-Z0-9]+\//, '');
|
||||
|
||||
/**
|
||||
* Information about the plugin directory
|
||||
@@ -104,7 +104,7 @@ module.exports = class Plugin {
|
||||
*/
|
||||
createConfig(template) {
|
||||
this.createDirectory();
|
||||
let file = join(this.directory.path, 'config.json');
|
||||
const file = join(this.directory.path, 'config.json');
|
||||
if (!fs.existsSync(file)) {
|
||||
this.client.log.plugins(`Creating plugin config file for "${this.name}"`);
|
||||
fs.writeFileSync(file, JSON.stringify(template, null, 2));
|
||||
@@ -120,7 +120,7 @@ module.exports = class Plugin {
|
||||
*/
|
||||
resetConfig(template) {
|
||||
this.createDirectory();
|
||||
let file = join(this.directory.path, 'config.json');
|
||||
const file = join(this.directory.path, 'config.json');
|
||||
this.client.log.plugins(`Resetting plugin config file for "${this.name}"`);
|
||||
fs.writeFileSync(file, JSON.stringify(template, null, 2));
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ module.exports = class TicketArchives {
|
||||
async addMessage(message) {
|
||||
try {
|
||||
// await this.client.db.transaction(async t => {
|
||||
let t_row = await this.client.db.models.Ticket.findOne({
|
||||
const t_row = await this.client.db.models.Ticket.findOne({
|
||||
where: {
|
||||
id: message.channel.id
|
||||
},
|
||||
@@ -53,7 +53,7 @@ module.exports = class TicketArchives {
|
||||
async updateMessage(message) {
|
||||
try {
|
||||
// await this.client.db.transaction(async t => {
|
||||
let m_row = await this.client.db.models.Message.findOne({
|
||||
const m_row = await this.client.db.models.Message.findOne({
|
||||
where: {
|
||||
id: message.id
|
||||
},
|
||||
@@ -86,7 +86,7 @@ module.exports = class TicketArchives {
|
||||
async deleteMessage(message) {
|
||||
try {
|
||||
// await this.client.db.transaction(async t => {
|
||||
let msg = await this.client.db.models.Message.findOne({
|
||||
const msg = await this.client.db.models.Message.findOne({
|
||||
where: {
|
||||
id: message.id
|
||||
},
|
||||
@@ -129,12 +129,12 @@ module.exports = class TicketArchives {
|
||||
|
||||
try {
|
||||
// await this.client.db.transaction(async t => {
|
||||
let u_model_data = {
|
||||
const u_model_data = {
|
||||
user: member.user.id,
|
||||
ticket: ticket_id
|
||||
};
|
||||
|
||||
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
||||
const [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
||||
where: u_model_data,
|
||||
defaults: {
|
||||
...u_model_data,
|
||||
@@ -163,11 +163,11 @@ module.exports = class TicketArchives {
|
||||
async updateChannel(ticket_id, channel) {
|
||||
try {
|
||||
// await this.client.db.transaction(async t => {
|
||||
let c_model_data = {
|
||||
const c_model_data = {
|
||||
channel: channel.id,
|
||||
ticket: ticket_id
|
||||
};
|
||||
let [c_row] = await this.client.db.models.ChannelEntity.findOrCreate({
|
||||
const [c_row] = await this.client.db.models.ChannelEntity.findOrCreate({
|
||||
where: c_model_data,
|
||||
defaults: c_model_data,
|
||||
/* transaction: t */
|
||||
@@ -188,11 +188,11 @@ module.exports = class TicketArchives {
|
||||
async updateRole(ticket_id, role) {
|
||||
try {
|
||||
// await this.client.db.transaction(async t => {
|
||||
let r_model_data = {
|
||||
const r_model_data = {
|
||||
role: role.id,
|
||||
ticket: ticket_id
|
||||
};
|
||||
let [r_row] = await this.client.db.models.RoleEntity.findOrCreate({
|
||||
const [r_row] = await this.client.db.models.RoleEntity.findOrCreate({
|
||||
where: r_model_data,
|
||||
defaults: r_model_data,
|
||||
/* transaction: t */
|
||||
|
@@ -30,7 +30,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
async create(guild_id, creator_id, category_id, topic) {
|
||||
if (!topic) topic = '';
|
||||
|
||||
let cat_row = await this.client.db.models.Category.findOne({
|
||||
const cat_row = await this.client.db.models.Category.findOne({
|
||||
where: {
|
||||
id: category_id
|
||||
}
|
||||
@@ -39,24 +39,24 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
if (!cat_row)
|
||||
throw new Error('Ticket category does not exist');
|
||||
|
||||
let cat_channel = await this.client.channels.fetch(category_id);
|
||||
const cat_channel = await this.client.channels.fetch(category_id);
|
||||
|
||||
if (cat_channel.children.size >= 50)
|
||||
throw new Error('Ticket category has reached child channel limit (50)');
|
||||
|
||||
let number = (await this.client.db.models.Ticket.count({
|
||||
const number = (await this.client.db.models.Ticket.count({
|
||||
where: {
|
||||
guild: guild_id
|
||||
}
|
||||
})) + 1;
|
||||
|
||||
let guild = this.client.guilds.cache.get(guild_id);
|
||||
let member = await guild.members.fetch(creator_id);
|
||||
let name = cat_row.name_format
|
||||
const guild = this.client.guilds.cache.get(guild_id);
|
||||
const member = await guild.members.fetch(creator_id);
|
||||
const name = cat_row.name_format
|
||||
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
|
||||
.replace(/{+\s?num(ber)?\s?}+/gi, number);
|
||||
|
||||
let t_channel = await guild.channels.create(name, {
|
||||
const t_channel = await guild.channels.create(name, {
|
||||
type: 'text',
|
||||
topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`,
|
||||
parent: category_id,
|
||||
@@ -70,7 +70,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
ATTACH_FILES: true
|
||||
}, `Ticket channel created by ${member.user.tag}`);
|
||||
|
||||
let t_row = await this.client.db.models.Ticket.create({
|
||||
const t_row = await this.client.db.models.Ticket.create({
|
||||
id: t_channel.id,
|
||||
number,
|
||||
guild: guild_id,
|
||||
@@ -80,7 +80,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
});
|
||||
|
||||
(async () => {
|
||||
let settings = await guild.settings;
|
||||
const settings = await guild.settings;
|
||||
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||
|
||||
topic = t_row.topic
|
||||
@@ -88,7 +88,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
: '';
|
||||
|
||||
if (cat_row.ping instanceof Array && cat_row.ping.length > 0) {
|
||||
let mentions = cat_row.ping.map(id => id === 'everyone'
|
||||
const mentions = cat_row.ping.map(id => id === 'everyone'
|
||||
? '@everyone'
|
||||
: id === 'here'
|
||||
? '@here'
|
||||
@@ -101,10 +101,10 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
await t_channel.send(cat_row.image);
|
||||
}
|
||||
|
||||
let description = cat_row.opening_message
|
||||
const description = cat_row.opening_message
|
||||
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
|
||||
.replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString());
|
||||
let embed = new MessageEmbed()
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(settings.colour)
|
||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||
.setDescription(description)
|
||||
@@ -112,14 +112,14 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
|
||||
if (topic) embed.addField(i18n('ticket.opening_message.fields.topic'), topic);
|
||||
|
||||
let sent = await t_channel.send(member.user.toString(), embed);
|
||||
const sent = await t_channel.send(member.user.toString(), embed);
|
||||
await sent.pin({ reason: 'Ticket opening message' });
|
||||
|
||||
await t_row.update({
|
||||
opening_message: sent.id
|
||||
});
|
||||
|
||||
let pinned = t_channel.messages.cache.last();
|
||||
const pinned = t_channel.messages.cache.last();
|
||||
|
||||
if (pinned.system) {
|
||||
pinned
|
||||
@@ -139,7 +139,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
}
|
||||
|
||||
if (cat_row.require_topic && topic.length === 0) {
|
||||
let collector_message = await t_channel.send(
|
||||
const collector_message = await t_channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.colour)
|
||||
.setTitle('⚠️ ' + i18n('commands.new.request_topic.title'))
|
||||
@@ -149,7 +149,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
|
||||
const collector_filter = (message) => message.author.id === t_row.creator;
|
||||
|
||||
let collector = t_channel.createMessageCollector(collector_filter, {
|
||||
const collector = t_channel.createMessageCollector(collector_filter, {
|
||||
time: 120000
|
||||
});
|
||||
|
||||
@@ -211,24 +211,24 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
* @param {string} [reason] - The reason for closing the ticket
|
||||
*/
|
||||
async close(ticket_id, closer_id, guild_id, reason) {
|
||||
let t_row = await this.resolve(ticket_id, guild_id);
|
||||
const t_row = await this.resolve(ticket_id, guild_id);
|
||||
if (!t_row) throw new Error(`A ticket with the ID or number "${ticket_id}" could not be resolved`);
|
||||
ticket_id = t_row.id;
|
||||
|
||||
this.emit('beforeClose', ticket_id);
|
||||
|
||||
let guild = this.client.guilds.cache.get(t_row.guild);
|
||||
let settings = await guild.settings;
|
||||
const guild = this.client.guilds.cache.get(t_row.guild);
|
||||
const settings = await guild.settings;
|
||||
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||
let channel = await this.client.channels.fetch(t_row.id);
|
||||
const channel = await this.client.channels.fetch(t_row.id);
|
||||
|
||||
if (closer_id) {
|
||||
let member = await guild.members.fetch(closer_id);
|
||||
const member = await guild.members.fetch(closer_id);
|
||||
|
||||
await this.archives.updateMember(ticket_id, member);
|
||||
|
||||
if (channel) {
|
||||
let description = reason
|
||||
const description = reason
|
||||
? i18n('ticket.closed_by_member_with_reason.description', member.user.toString(), reason)
|
||||
: i18n('ticket.closed_by_member.description', member.user.toString());
|
||||
await channel.send(
|
||||
@@ -248,7 +248,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
this.client.log.info(`${member.user.tag} closed a ticket (${ticket_id})${reason ? `: "${reason}"` : ''}`);
|
||||
} else {
|
||||
if (channel) {
|
||||
let description = reason
|
||||
const description = reason
|
||||
? i18n('ticket.closed_with_reason.description')
|
||||
: i18n('ticket.closed.description');
|
||||
await channel.send(
|
||||
@@ -267,7 +267,7 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`);
|
||||
}
|
||||
|
||||
let pinned = await channel.messages.fetchPinned();
|
||||
const pinned = await channel.messages.fetchPinned();
|
||||
|
||||
await t_row.update({
|
||||
open: false,
|
||||
|
Reference in New Issue
Block a user