fix(settings): role ID parsing

Fixes Discord's dumb `,` problem and also allows writing something like `none` to clear the array
This commit is contained in:
Isaac 2021-10-26 16:59:14 +01:00
parent d3ed6405db
commit 7411fb9c39
No known key found for this signature in database
GPG Key ID: 87B9B6BD04EB7534

View File

@ -203,7 +203,7 @@ module.exports = class SettingsCommand extends Command {
switch (interaction.options.getSubcommand()) { switch (interaction.options.getSubcommand()) {
case default_i18n('commands.settings.options.categories.options.create.name'): { case default_i18n('commands.settings.options.categories.options.create.name'): {
const name = interaction.options.getString(default_i18n('commands.settings.options.categories.options.create.options.name.name')); const name = interaction.options.getString(default_i18n('commands.settings.options.categories.options.create.options.name.name'));
const roles = interaction.options.getString(default_i18n('commands.settings.options.categories.options.create.options.roles.name'))?.replace(/\s/g, '').split(','); const roles = interaction.options.getString(default_i18n('commands.settings.options.categories.options.create.options.roles.name'))?.match(/\d{17,19}/g) ?? [];
const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES']; const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
const cat_channel = await interaction.guild.channels.create(name, { const cat_channel = await interaction.guild.channels.create(name, {
permissionOverwrites: [ permissionOverwrites: [
@ -299,9 +299,9 @@ module.exports = class SettingsCommand extends Command {
if (name_format !== null) category.set('name_format', name_format); if (name_format !== null) category.set('name_format', name_format);
if (opening_message !== null) category.set('opening_message', opening_message.replace(/\\n/g, '\n')); if (opening_message !== null) category.set('opening_message', opening_message.replace(/\\n/g, '\n'));
if (opening_questions !== null) category.set('opening_questions', JSON.parse(opening_questions)); if (opening_questions !== null) category.set('opening_questions', JSON.parse(opening_questions));
if (ping !== null) category.set('ping', ping.replace(/\s/g, '').split(',')); if (ping !== null) category.set('ping', ping.match(/\d{17,19}/g) ?? []);
if (require_topic !== null) category.set('require_topic', require_topic); if (require_topic !== null) category.set('require_topic', require_topic);
if (roles !== null) category.set('roles', roles.replace(/\s/g, '').split(',')); if (roles !== null) category.set('roles', roles.match(/\d{17,19}/g) ?? []);
if (survey !== null) category.set('survey', survey); if (survey !== null) category.set('survey', survey);
await category.save(); await category.save();
interaction.editReply({ interaction.editReply({