This commit is contained in:
Isaac
2021-05-22 00:04:18 +01:00
parent 777719d1b3
commit 32f43ac18f
58 changed files with 837 additions and 926 deletions

View File

@@ -1,30 +1,32 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
module.exports = class AddCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.add.name'),
description: i18n('commands.add.description'),
aliases: [],
process_args: false,
args: [
{
name: i18n('commands.add.args.member.name'),
description: i18n('commands.add.args.member.description'),
example: i18n('commands.add.args.member.example'),
required: true,
name: i18n('commands.add.args.member.name'),
required: true
},
{
name: i18n('commands.add.args.ticket.name'),
description: i18n('commands.add.args.ticket.description'),
example: i18n('commands.add.args.ticket.example'),
required: false,
name: i18n('commands.add.args.ticket.name'),
required: false
}
]
],
description: i18n('commands.add.description'),
internal: true,
name: i18n('commands.add.name'),
process_args: false
});
}
@@ -38,7 +40,7 @@ module.exports = class AddCommand extends Command {
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);
const t_row = await this.client.tickets.resolve(ticket.id, message.guild.id);
if (!t_row) {
return await message.channel.send(
@@ -93,10 +95,10 @@ module.exports = class AddCommand extends Command {
);
await ticket.updateOverwrite(member, {
VIEW_CHANNEL: true,
ATTACH_FILES: true,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true
VIEW_CHANNEL: true
}, `${message.author.tag} added ${member.user.tag} to the ticket`);
await this.client.tickets.archives.updateMember(ticket.id, member);

View File

@@ -1,27 +1,29 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
module.exports = class BlacklistCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.blacklist.name'),
description: i18n('commands.blacklist.description'),
aliases: [
i18n('commands.blacklist.aliases.unblacklist'),
i18n('commands.blacklist.aliases.unblacklist')
],
process_args: false,
args: [
{
name: i18n('commands.blacklist.args.member_or_role.name'),
description: i18n('commands.blacklist.args.member_or_role.description'),
example: i18n('commands.blacklist.args.member_or_role.example'),
required: false,
name: i18n('commands.blacklist.args.member_or_role.name'),
required: false
}
],
permissions: ['MANAGE_GUILD']
description: i18n('commands.blacklist.description'),
internal: true,
name: i18n('commands.blacklist.name'),
permissions: ['MANAGE_GUILD'],
process_args: false
});
}
@@ -45,16 +47,19 @@ module.exports = class BlacklistCommand extends Command {
.setFooter(settings.footer, message.guild.iconURL())
);
}
const role = message.mentions.roles.first();
let id;
const input = args.trim().split(/\s/g)[0];
if (member) id = member.id;
else if (role) id = role.id;
else if (/\d{17,19}/.test(input)) id = input;
else if (settings.blacklist?.length === 0) {
if (member) {
id = member.id;
} else if (role) {
id = role.id;
} 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)

View File

@@ -1,6 +1,10 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, MessageMentions, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed,
MessageMentions
} = require('discord.js');
const { Op } = require('sequelize');
const toTime = require('to-time-monthsfork');
const { footer } = require('../utils/discord');
@@ -9,43 +13,40 @@ module.exports = class CloseCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.close.name'),
description: i18n('commands.close.description'),
aliases: [
i18n('commands.close.aliases.delete'),
i18n('commands.close.aliases.lock'),
i18n('commands.close.aliases.lock')
],
process_args: true,
args: [
{
name: i18n('commands.close.args.ticket.name'),
alias: i18n('commands.close.args.ticket.alias'),
description: i18n('commands.close.args.ticket.description'),
example: i18n('commands.close.args.ticket.example'),
name: i18n('commands.close.args.ticket.name'),
required: false,
// for arg parsing
alias: i18n('commands.close.args.ticket.alias'),
type: String
},
{
name: i18n('commands.close.args.reason.name'),
alias: i18n('commands.close.args.reason.alias'),
description: i18n('commands.close.args.reason.description'),
example: i18n('commands.close.args.reason.example'),
name: i18n('commands.close.args.reason.name'),
required: false,
// for arg parsing
alias: i18n('commands.close.args.reason.alias'),
type: String
},
{
name: i18n('commands.close.args.time.name'),
alias: i18n('commands.close.args.time.alias'),
description: i18n('commands.close.args.time.description'),
example: i18n('commands.close.args.time.example'),
name: i18n('commands.close.args.time.name'),
required: false,
// for arg parsing
alias: i18n('commands.close.args.time.alias'),
type: String
}
]
],
description: i18n('commands.close.description'),
internal: true,
name: i18n('commands.close.name'),
process_args: true
});
}
@@ -79,10 +80,8 @@ module.exports = class CloseCommand extends Command {
const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: {
last_message: {
[Op.lte]: new Date(Date.now() - period)
},
guild: message.guild.id
guild: message.guild.id,
last_message: { [Op.lte]: new Date(Date.now() - period) }
}
});
@@ -105,13 +104,9 @@ module.exports = class CloseCommand extends Command {
await collector_message.react('✅');
const collector_filter = (reaction, user) => {
return user.id === message.author.id && reaction.emoji.name === '✅';
};
const collector_filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '✅';
const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000
});
const collector = collector_message.createReactionCollector(collector_filter, { time: 30000 });
collector.on('collect', async () => {
await collector_message.reactions.removeAll();
@@ -130,7 +125,7 @@ module.exports = class CloseCommand extends Command {
});
collector.on('end', async (collected) => {
collector.on('end', async collected => {
if (collected.size === 0) {
await collector_message.reactions.removeAll();
await collector_message.edit(
@@ -169,11 +164,7 @@ module.exports = class CloseCommand extends Command {
);
}
} else {
t_row = await this.client.db.models.Ticket.findOne({
where: {
id: message.channel.id
}
});
t_row = await this.client.db.models.Ticket.findOne({ where: { id: message.channel.id } });
if (!t_row) {
return await message.channel.send(
@@ -196,13 +187,9 @@ module.exports = class CloseCommand extends Command {
await collector_message.react('✅');
const collector_filter = (reaction, user) => {
return user.id === message.author.id && reaction.emoji.name === '✅';
};
const collector_filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '✅';
const collector = collector_message.createReactionCollector(collector_filter, {
time: 30000
});
const collector = collector_message.createReactionCollector(collector_filter, { time: 30000 });
collector.on('collect', async () => {
collector.stop();
@@ -223,7 +210,7 @@ module.exports = class CloseCommand extends Command {
await this.client.tickets.close(t_row.id, message.author.id, message.guild.id, args[arg_reason]);
});
collector.on('end', async (collected) => {
collector.on('end', async collected => {
if (collected.size === 0) {
await collector_message.reactions.removeAll();
await collector_message.edit(
@@ -244,7 +231,7 @@ module.exports = class CloseCommand extends Command {
}, 15000);
}
});
}
}
};

View File

@@ -1,33 +1,35 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
module.exports = class HelpCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.help.name'),
description: i18n('commands.help.description'),
aliases: [
i18n('commands.help.aliases.command'),
i18n('commands.help.aliases.commands'),
i18n('commands.help.aliases.commands')
],
process_args: false,
args: [
{
name: i18n('commands.help.args.command.name'),
description: i18n('commands.help.args.command.description'),
example: i18n('commands.help.args.command.example'),
required: false,
name: i18n('commands.help.args.command.name'),
required: false
}
]
],
description: i18n('commands.help.description'),
internal: true,
name: i18n('commands.help.name'),
process_args: false
});
}
/**
* @param {Message} message
* @param {string} args
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
@@ -54,9 +56,7 @@ module.exports = class HelpCommand extends Command {
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.help.response.list.title'))
.setDescription(i18n('commands.help.response.list.description', {
prefix: settings.command_prefix,
}))
.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

@@ -1,6 +1,8 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
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');
@@ -9,23 +11,23 @@ module.exports = class NewCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.new.name'),
description: i18n('commands.new.description'),
aliases: [
i18n('commands.new.aliases.create'),
i18n('commands.new.aliases.open'),
i18n('commands.new.aliases.ticket'),
i18n('commands.new.aliases.ticket')
],
process_args: false,
args: [
{
name: i18n('commands.new.args.topic.name'),
description: i18n('commands.new.args.topic.description'),
example: i18n('commands.new.args.topic.example'),
required: false,
name: i18n('commands.new.args.topic.name'),
required: false
}
]
],
description: i18n('commands.new.description'),
internal: true,
name: i18n('commands.new.name'),
process_args: false
});
}
@@ -114,11 +116,7 @@ module.exports = class NewCommand extends Command {
}, 15000);
};
const categories = await this.client.db.models.Category.findAndCountAll({
where: {
guild: message.guild.id
}
});
const categories = await this.client.db.models.Category.findAndCountAll({ where: { guild: message.guild.id } });
if (categories.count === 0) {
return await message.channel.send(
@@ -153,21 +151,21 @@ module.exports = class NewCommand extends Command {
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(collector_filter, { time: 30000 });
collector.on('collect', async (reaction) => {
collector.on('collect', async reaction => {
collector.stop();
const index = letters_array.findIndex(value => value === reaction.emoji.name); // find where the letter is in the alphabet
if (index === -1) return setTimeout(async () => {
await collector_message.delete();
}, 15000);
if (index === -1) {
return setTimeout(async () => {
await collector_message.delete();
}, 15000);
}
await collector_message.reactions.removeAll();
create(categories.rows[index], collector_message); // create the ticket, passing the existing response message to be edited instead of creating a new one
});
collector.on('end', async (collected) => {
collector.on('end', async collected => {
if (collected.size === 0) {
await collector_message.reactions.removeAll();
await collector_message.edit(

View File

@@ -1,59 +1,59 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const { some, wait } = require('../utils');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
const {
some, wait
} = require('../utils');
const { emojify } = require('node-emoji');
module.exports = class PanelCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.panel.name'),
description: i18n('commands.panel.description'),
aliases: [],
process_args: true,
args: [
{
name: i18n('commands.panel.args.title.name'),
alias: i18n('commands.panel.args.title.alias'),
description: i18n('commands.panel.args.title.description'),
example: i18n('commands.panel.args.title.example'),
name: i18n('commands.panel.args.title.name'),
required: false,
// for arg parsing
alias: i18n('commands.panel.args.title.alias'),
type: String
},
{
name: i18n('commands.panel.args.description.name'),
alias: i18n('commands.panel.args.description.alias'),
description: i18n('commands.panel.args.description.description'),
example: i18n('commands.panel.args.description.example'),
name: i18n('commands.panel.args.description.name'),
required: true,
// for arg parsing
alias: i18n('commands.panel.args.description.alias'),
type: String
},
{
name: i18n('commands.panel.args.emoji.name'),
alias: i18n('commands.panel.args.emoji.alias'),
description: i18n('commands.panel.args.emoji.description'),
example: i18n('commands.panel.args.emoji.example'),
required: false,
// for arg parsing
alias: i18n('commands.panel.args.emoji.alias'),
type: String,
multiple: true,
name: i18n('commands.panel.args.emoji.name'),
required: false,
type: String
},
{
name: i18n('commands.panel.args.categories.name'),
alias: i18n('commands.panel.args.categories.alias'),
description: i18n('commands.panel.args.categories.description'),
example: i18n('commands.panel.args.categories.example'),
required: true,
// for arg parsing
alias: i18n('commands.panel.args.categories.alias'),
type: String,
multiple: true,
name: i18n('commands.panel.args.categories.name'),
required: true,
type: String
}
],
permissions: ['MANAGE_GUILD']
description: i18n('commands.panel.description'),
internal: true,
name: i18n('commands.panel.name'),
permissions: ['MANAGE_GUILD'],
process_args: true
});
}
@@ -72,21 +72,20 @@ module.exports = class PanelCommand extends Command {
const settings = await message.guild.getSettings();
const i18n = this.client.i18n.getLocale(settings.locale);
if (!args[arg_emoji])
args[arg_emoji] = [];
if (!args[arg_emoji]) args[arg_emoji] = [];
args[arg_emoji] = args[arg_emoji].map(emoji => emojify(emoji.replace(/\\/g, '')));
const invalid_category = await some(args[arg_categories], async id => {
const cat_row = await this.client.db.models.Category.findOne({
where: {
id: id,
guild: message.guild.id
guild: message.guild.id,
id
}
});
return !cat_row;
});
if (invalid_category) {
return await message.channel.send(
new MessageEmbed()
@@ -99,36 +98,35 @@ module.exports = class PanelCommand extends Command {
let panel_channel,
panel_message;
let categories_map = args[arg_categories][0];
const embed = new MessageEmbed()
.setColor(settings.colour)
.setFooter(settings.footer, message.guild.iconURL());
if (args[arg_title])
embed.setTitle(args[arg_title]);
if (args[arg_title]) embed.setTitle(args[arg_title]);
if (args[arg_emoji].length === 0) {
// reaction-less panel
panel_channel = await message.guild.channels.create('create-a-ticket', {
type: 'text',
rateLimitPerUser: 30,
permissionOverwrites: [
{
id: message.guild.roles.everyone,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
deny: ['ATTACH_FILES', 'EMBED_LINKS', 'ADD_REACTIONS']
deny: ['ATTACH_FILES', 'EMBED_LINKS', 'ADD_REACTIONS'],
id: message.guild.roles.everyone
},
{
id: this.client.user.id,
allow: ['EMBED_LINKS']
allow: ['EMBED_LINKS'],
id: this.client.user.id
}
],
position: 1,
reason: `${message.author.tag} created a new reaction-less panel`
rateLimitPerUser: 30,
reason: `${message.author.tag} created a new reaction-less panel`,
type: 'text'
});
embed.setDescription(args[arg_description]);
panel_message = await panel_channel.send(embed);
@@ -145,20 +143,20 @@ module.exports = class PanelCommand extends Command {
);
} else {
panel_channel = await message.guild.channels.create('create-a-ticket', {
type: 'text',
permissionOverwrites: [
{
id: message.guild.roles.everyone,
allow: ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY'],
deny: ['SEND_MESSAGES', 'ADD_REACTIONS']
deny: ['SEND_MESSAGES', 'ADD_REACTIONS'],
id: message.guild.roles.everyone
},
{
id: this.client.user.id,
allow: ['SEND_MESSAGES', 'EMBED_LINKS']
allow: ['SEND_MESSAGES', 'EMBED_LINKS'],
id: this.client.user.id
}
],
position: 1,
reason: `${message.author.tag} created a new panel`
reason: `${message.author.tag} created a new panel`,
type: 'text'
});
if (args[arg_emoji].length === 1) {
@@ -172,13 +170,13 @@ module.exports = class PanelCommand extends Command {
// multi category
let description = '';
categories_map = {};
for (const i in args[arg_emoji]) {
categories_map[args[arg_emoji][i]] = args[arg_categories][i];
const cat_row = await this.client.db.models.Category.findOne({
where: {
id: args[arg_categories][i],
guild: message.guild.id
guild: message.guild.id,
id: args[arg_categories][i]
}
});
description += `\n> ${args[arg_emoji][i]} | ${cat_row.name}`;
@@ -191,7 +189,7 @@ module.exports = class PanelCommand extends Command {
await panel_message.react(emoji);
await wait(1000); // 1 reaction per second rate-limit
}
}
this.client.log.info(`${message.author.tag} has created a new panel`);
@@ -204,7 +202,7 @@ module.exports = class PanelCommand extends Command {
categories: categories_map,
channel: panel_channel.id,
guild: message.guild.id,
message: panel_message.id,
message: panel_message.id
});
}
};

View File

@@ -1,30 +1,32 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
module.exports = class RemoveCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.remove.name'),
description: i18n('commands.remove.description'),
aliases: [],
process_args: false,
args: [
{
name: i18n('commands.remove.args.member.name'),
description: i18n('commands.remove.args.member.description'),
example: i18n('commands.remove.args.member.example'),
required: true,
name: i18n('commands.remove.args.member.name'),
required: true
},
{
name: i18n('commands.remove.args.ticket.name'),
description: i18n('commands.remove.args.ticket.description'),
example: i18n('commands.remove.args.ticket.example'),
required: false,
name: i18n('commands.remove.args.ticket.name'),
required: false
}
]
],
description: i18n('commands.remove.description'),
internal: true,
name: i18n('commands.remove.name'),
process_args: false
});
}

View File

@@ -1,22 +1,24 @@
const Command = require('../modules/commands/command');
const fetch = require('node-fetch');
// eslint-disable-next-line no-unused-vars
const { MessageAttachment, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageAttachment
} = require('discord.js');
const { Validator } = require('jsonschema');
module.exports = class SettingsCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
aliases: [
i18n('commands.settings.aliases.config')
],
args: [],
description: i18n('commands.settings.description'),
internal: true,
name: i18n('commands.settings.name'),
description: i18n('commands.settings.description'),
aliases: [
i18n('commands.settings.aliases.config'),
],
process_args: false,
args: [],
permissions: ['MANAGE_GUILD']
permissions: ['MANAGE_GUILD'],
process_args: false
});
this.schema = require('./extra/settings.schema.json');
@@ -40,7 +42,9 @@ module.exports = class SettingsCommand extends Command {
this.client.log.info(`Downloading settings for "${message.guild.name}"`);
const data = await (await fetch(attachments[0].url)).json();
const { valid, errors } = this.v.validate(data, this.schema);
const {
valid, errors
} = this.v.validate(data, this.schema);
if (!valid) {
this.client.log.warn('Settings validation error');
@@ -60,11 +64,7 @@ module.exports = class SettingsCommand extends Command {
for (const c of data.categories) {
if (c.id) {
// existing category
const cat_row = await this.client.db.models.Category.findOne({
where: {
id: c.id
}
});
const cat_row = await this.client.db.models.Category.findOne({ where: { id: c.id } });
cat_row.claiming = c.claiming;
cat_row.image = c.image;
cat_row.max_per_member = c.max_per_member;
@@ -81,15 +81,14 @@ module.exports = class SettingsCommand extends Command {
const cat_channel = await this.client.channels.fetch(c.id);
if (cat_channel) {
if (cat_channel.name !== c.name)
await cat_channel.setName(c.name, `Tickets category updated by ${message.author.tag}`);
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, {
VIEW_CHANNEL: true,
ATTACH_FILES: true,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true
VIEW_CHANNEL: true
}, `Tickets category updated by ${message.author.tag}`);
}
}
@@ -97,33 +96,31 @@ module.exports = class SettingsCommand extends Command {
// create a new category
const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
const cat_channel = await message.guild.channels.create(c.name, {
type: 'category',
reason: `Tickets category created by ${message.author.tag}`,
position: 1,
permissionOverwrites: [
...[
{
id: message.guild.roles.everyone,
deny: ['VIEW_CHANNEL']
deny: ['VIEW_CHANNEL'],
id: message.guild.roles.everyone
},
{
id: this.client.user.id,
allow: allowed_permissions
allow: allowed_permissions,
id: this.client.user.id
}
],
...c.roles.map(r => {
return {
id: r,
allow: allowed_permissions
};
})
]
...c.roles.map(r => ({
allow: allowed_permissions,
id: r
}))
],
position: 1,
reason: `Tickets category created by ${message.author.tag}`,
type: 'category'
});
await this.client.db.models.Category.create({
id: cat_channel.id,
claiming: c.claiming,
guild: message.guild.id,
id: cat_channel.id,
image: c.image,
max_per_member: c.max_per_member,
name: c.name,
@@ -141,11 +138,11 @@ module.exports = class SettingsCommand extends Command {
for (const survey in data.surveys) {
const survey_data = {
guild: message.guild.id,
name: survey,
name: survey
};
const [s_row] = await this.client.db.models.Survey.findOrCreate({
where: survey_data,
defaults: survey_data
defaults: survey_data,
where: survey_data
});
s_row.questions = data.surveys[survey];
await s_row.save();
@@ -156,35 +153,25 @@ module.exports = class SettingsCommand extends Command {
} else {
// upload settings as json to be edited
const categories = await this.client.db.models.Category.findAll({
where: {
guild: message.guild.id
}
});
const surveys = await this.client.db.models.Survey.findAll({
where: {
guild: message.guild.id
}
});
const categories = await this.client.db.models.Category.findAll({ where: { guild: message.guild.id } });
const surveys = await this.client.db.models.Survey.findAll({ where: { guild: message.guild.id } });
const data = {
categories: categories.map(c => {
return {
id: c.id,
claiming: c.claiming,
image: c.image,
max_per_member: c.max_per_member,
name: c.name,
name_format: c.name_format,
opening_message: c.opening_message,
opening_questions: c.opening_questions,
ping: c.ping,
require_topic: c.require_topic,
roles: c.roles,
survey: c.survey
};
}),
categories: categories.map(c => ({
claiming: c.claiming,
id: c.id,
image: c.image,
max_per_member: c.max_per_member,
name: c.name,
name_format: c.name_format,
opening_message: c.opening_message,
opening_questions: c.opening_questions,
ping: c.ping,
require_topic: c.require_topic,
roles: c.roles,
survey: c.survey
})),
colour: settings.colour,
command_prefix: settings.command_prefix,
error_colour: settings.error_colour,
@@ -197,7 +184,9 @@ module.exports = class SettingsCommand extends Command {
};
for (const survey in surveys) {
const { name, questions } = surveys[survey];
const {
name, questions
} = surveys[survey];
data.surveys[name] = questions;
}
@@ -206,9 +195,7 @@ module.exports = class SettingsCommand extends Command {
`Settings for ${message.guild.name}.json`
);
return await message.channel.send({
files: [attachment]
});
return await message.channel.send({ files: [attachment] });
}
}
};

View File

@@ -1,24 +1,24 @@
const Command = require('../modules/commands/command');
const Keyv = require('keyv');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
module.exports = class StatsCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
aliases: [],
args: [],
description: i18n('commands.stats.description'),
internal: true,
name: i18n('commands.stats.name'),
description: i18n('commands.stats.description'),
aliases: [],
process_args: false,
args: [],
staff_only: true
});
this.cache = new Keyv({
namespace: 'cache.commands.stats'
});
this.cache = new Keyv({ namespace: 'cache.commands.stats' });
}
/**
@@ -35,27 +35,19 @@ module.exports = class StatsCommand extends Command {
let stats = await this.cache.get(message.guild.id);
if (!stats) {
const tickets = await this.client.db.models.Ticket.findAndCountAll({
where: {
guild: message.guild.id
}
});
const tickets = await this.client.db.models.Ticket.findAndCountAll({ where: { guild: message.guild.id } });
stats = { // maths
tickets: tickets.count,
messages: settings.log_messages
? await messages.rows
.reduce(async (acc, row) => (await this.client.db.models.Ticket.findOne({
where: {
id: row.ticket
}
})).guild === message.guild.id
.reduce(async (acc, row) => (await this.client.db.models.Ticket.findOne({ where: { id: row.ticket } }))
.guild === message.guild.id
? await acc + 1
: await acc, 0)
: null,
response_time: Math.floor(tickets.rows.reduce((acc, row) => row.first_response
? acc + ((Math.abs(new Date(row.createdAt) - new Date(row.first_response)) / 1000) / 60)
: acc, 0) / tickets.count)
: acc, 0) / tickets.count),
tickets: tickets.count
};
await this.cache.set(message.guild.id, stats, 60 * 60 * 1000); // cache for an hour
}
@@ -67,7 +59,7 @@ module.exports = class StatsCommand extends Command {
.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)
.setFooter(settings.footer, message.guild.iconURL());
if (stats.messages) guild_embed.addField(i18n('commands.stats.fields.messages'), stats.messages, true);
await message.channel.send(guild_embed);

View File

@@ -1,6 +1,10 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageAttachment, MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageAttachment,
MessageEmbed
} = require('discord.js');
const fsp = require('fs').promises;
const { path } = require('../utils/fs');
const mustache = require('mustache');
@@ -9,21 +13,21 @@ module.exports = class SurveyCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.survey.name'),
description: i18n('commands.survey.description'),
aliases: [
i18n('commands.survey.aliases.surveys')
],
process_args: false,
args: [
{
name: i18n('commands.survey.args.survey.name'),
description: i18n('commands.survey.args.survey.description'),
example: i18n('commands.survey.args.survey.example'),
required: false,
name: i18n('commands.survey.args.survey.name'),
required: false
}
],
description: i18n('commands.survey.description'),
internal: true,
name: i18n('commands.survey.name'),
process_args: false,
staff_only: true
});
}
@@ -39,49 +43,41 @@ module.exports = class SurveyCommand extends Command {
const survey = await this.client.db.models.Survey.findOne({
where: {
name: args,
guild: message.guild.id
guild: message.guild.id,
name: args
}
});
if (survey) {
const { rows: responses, count } = await this.client.db.models.SurveyResponse.findAndCountAll({
where: {
survey: survey.id
}
});
const {
rows: responses, count
} = await this.client.db.models.SurveyResponse.findAndCountAll({ where: { survey: survey.id } });
const users = new Set();
for (const i in responses) {
const ticket = await this.client.db.models.Ticket.findOne({
where: {
id: responses[i].ticket
}
});
const ticket = await this.client.db.models.Ticket.findOne({ where: { id: responses[i].ticket } });
users.add(ticket.creator);
const answers = responses[i].answers.map(a => this.client.cryptr.decrypt(a));
answers.unshift(ticket.number);
responses[i] = answers;
}
let template = await fsp.readFile(path('./src/commands/extra/survey.template.html'), {
encoding: 'utf8'
});
let template = await fsp.readFile(path('./src/commands/extra/survey.template.html'), { encoding: 'utf8' });
template = template.replace(/[\r\n\t]/g, '');
survey.questions.unshift('Ticket #');
const html = mustache.render(template, {
survey: survey.name.charAt(0).toUpperCase() + survey.name.slice(1),
columns: survey.questions,
count: {
responses: count,
users: users.size
},
columns: survey.questions,
responses
responses,
survey: survey.name.charAt(0).toUpperCase() + survey.name.slice(1)
});
const attachment = new MessageAttachment(
@@ -89,15 +85,9 @@ module.exports = class SurveyCommand extends Command {
`${survey.name}.html`
);
return await message.channel.send({
files: [attachment]
});
return await message.channel.send({ files: [attachment] });
} else {
const surveys = await this.client.db.models.Survey.findAll({
where: {
guild: message.guild.id
}
});
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(

View File

@@ -1,6 +1,8 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
const { parseArgsStringToArgv: argv } = require('string-argv');
const parseArgs = require('command-line-args');
@@ -8,41 +10,37 @@ module.exports = class TagCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.tag.name'),
description: i18n('commands.tag.description'),
aliases: [
i18n('commands.tag.aliases.faq'),
i18n('commands.tag.aliases.t'),
i18n('commands.tag.aliases.tags'),
i18n('commands.tag.aliases.tags')
],
process_args: false,
args: [
{
name: i18n('commands.tag.args.tag.name'),
description: i18n('commands.tag.args.command.description'),
example: i18n('commands.tag.args.tag.example'),
required: false,
name: i18n('commands.tag.args.tag.name'),
required: false
}
],
description: i18n('commands.tag.description'),
internal: true,
name: i18n('commands.tag.name'),
process_args: false,
staff_only: true
});
}
/**
* @param {Message} message
* @param {string} args
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await message.guild.getSettings();
const i18n = this.client.i18n.getLocale(settings.locale);
const t_row = await this.client.db.models.Ticket.findOne({
where: {
id: message.channel.id
}
});
const t_row = await this.client.db.models.Ticket.findOne({ where: { id: message.channel.id } });
args = args.split(/\s/g); // convert to an array
const tag_name = args.shift(); // shift the first element
@@ -63,14 +61,12 @@ module.exports = class TagCommand extends Command {
);
}
let expected = placeholders
const expected = placeholders
.filter(p => p.startsWith(':'))
.map(p => {
return {
name: p.substr(1, p.length),
type: String,
};
});
.map(p => ({
name: p.substr(1, p.length),
type: String
}));
if (expected.length >= 1) {
try {
@@ -107,7 +103,7 @@ 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));
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)

View File

@@ -1,24 +1,26 @@
const Command = require('../modules/commands/command');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
module.exports = class TopicCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.topic.name'),
description: i18n('commands.topic.description'),
aliases: [],
process_args: false,
args: [
{
name: i18n('commands.topic.args.new_topic.name'),
description: i18n('commands.topic.args.new_topic.description'),
example: i18n('commands.topic.args.new_topic.example'),
required: true,
name: i18n('commands.topic.args.new_topic.name'),
required: true
}
]
],
description: i18n('commands.topic.description'),
internal: true,
name: i18n('commands.topic.name'),
process_args: false
});
}
@@ -31,11 +33,7 @@ module.exports = class TopicCommand extends Command {
const settings = await message.guild.getSettings();
const i18n = this.client.i18n.getLocale(settings.locale);
const t_row = await this.client.db.models.Ticket.findOne({
where: {
id: message.channel.id
}
});
const t_row = await this.client.db.models.Ticket.findOne({ where: { id: message.channel.id } });
if (!t_row) {
return await message.channel.send(
@@ -47,18 +45,12 @@ module.exports = class TopicCommand extends Command {
);
}
await t_row.update({
topic: this.client.cryptr.encrypt(args)
});
await t_row.update({ topic: this.client.cryptr.encrypt(args) });
const member = await message.guild.members.fetch(t_row.creator);
/* await */message.channel.setTopic(`${member} | ${args}`, { reason: 'User updated ticket topic' });
const cat_row = await this.client.db.models.Category.findOne({
where: {
id: t_row.category
}
});
const cat_row = await this.client.db.models.Category.findOne({ where: { id: t_row.category } });
const description = cat_row.opening_message
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
.replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString());