Clean up and comment some code

This commit is contained in:
Isaac
2021-04-06 16:18:58 +01:00
parent e4f0f2a954
commit f96cae3c1e
11 changed files with 164 additions and 115 deletions

View File

@@ -108,10 +108,10 @@ module.exports = class NewCommand extends Command {
.setFooter(settings.footer, message.guild.iconURL())
);
} else if (categories.count === 1) {
create(categories.rows[0]);
create(categories.rows[0]); // skip the category selection
} else {
let letters_array = Object.values(letters);
let category_list = categories.rows.map((category, i) => `${letters_array[i]} » ${category.name}`);
let letters_array = Object.values(letters); // convert the A-Z emoji object to an array
let category_list = categories.rows.map((category, i) => `${letters_array[i]} » ${category.name}`); // list category names with an A-Z emoji
let collector_message = await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
@@ -122,11 +122,11 @@ module.exports = class NewCommand extends Command {
);
for (let i in categories.rows) {
await collector_message.react(letters_array[i]);
await collector_message.react(letters_array[i]); // add the correct number of letter reactions
}
const collector_filter = (reaction, user) => {
let allowed = letters_array.slice(0, categories.count);
let 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);
};
@@ -135,10 +135,10 @@ module.exports = class NewCommand extends Command {
});
collector.on('collect', async (reaction) => {
let index = letters_array.findIndex(value => value === reaction.emoji.name);
let index = letters_array.findIndex(value => value === reaction.emoji.name); // find where the letter is in the alphabet
if (index === -1) return await collector_message.delete({ timeout: 15000 });
await collector_message.reactions.removeAll();
create(categories.rows[index], collector_message);
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) => {
@@ -152,7 +152,10 @@ module.exports = class NewCommand extends Command {
.setDescription(i18n('commands.new.response.select_category_timeout.description', category_list.join('\n')))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
);
collector_message.delete({ timeout: 15000 });
setTimeout(async () => {
await collector_message.delete();
await message.delete();
}, 15000);
}
});
}

View File

@@ -46,10 +46,12 @@ module.exports = class SettingsCommand extends Command {
id: c.id
}
});
category.name = c.name;
category.roles = c.roles;
category.max_per_member = c.max_per_member;
category.name = c.name;
category.name_format = c.name_format;
category.opening_message = c.opening_message;
category.require_topic = c.require_topic;
category.roles = c.roles;
category.save();
let cat_channel = await this.client.channels.fetch(c.id);
@@ -99,6 +101,8 @@ module.exports = class SettingsCommand extends Command {
name: c.name,
name_format: c.name_format,
guild: message.guild.id,
opening_message: c.opening_message,
require_topic: c.require_topic,
roles: c.roles,
});
@@ -133,6 +137,8 @@ module.exports = class SettingsCommand extends Command {
max_per_member: c.max_per_member,
name: c.name,
name_format: c.name_format,
opening_message: c.opening_message,
require_topic: c.require_topic,
roles: c.roles
};
});