Skip to content

Commit

Permalink
fix: keep priority when moving (closes #467)
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Jul 30, 2023
1 parent 8a8bc2b commit 34b5090
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/commands/slash/move.js
Expand Up @@ -2,7 +2,7 @@ const { SlashCommand } = require('@eartharoid/dbf');
const { ApplicationCommandOptionType } = require('discord.js');
const ExtendedEmbedBuilder = require('../../lib/embed');
const { isStaff } = require('../../lib/users');

const { getEmoji } = require('./priority');
module.exports = class MoveSlashCommand extends SlashCommand {
constructor(client, options) {
const name = 'move';
Expand Down Expand Up @@ -129,7 +129,7 @@ module.exports = class MoveSlashCommand extends SlashCommand {
.replace(/{+\s?num(ber)?\s?}+/gi, ticket.number === 1488 ? '1487b' : ticket.number);
await interaction.channel.edit({
lockPermissions: false,
name: channelName,
name: ticket.priority ? getEmoji(ticket.priority) + channelName : channelName,
parent: discordCategory,
permissionOverwrites: [
{
Expand Down
36 changes: 14 additions & 22 deletions src/commands/slash/priority.js
Expand Up @@ -4,6 +4,15 @@ const ExtendedEmbedBuilder = require('../../lib/embed');
const { logTicketEvent } = require('../../lib/logging');
const { isStaff } = require('../../lib/users');

const getEmoji = priority => {
const emojis = {
'HIGH': '🔴',
'MEDIUM': '🟠',
'LOW': '🟢', // eslint-disable-line sort-keys
};
return emojis[priority];
};

module.exports = class PrioritySlashCommand extends SlashCommand {
constructor(client, options) {
const name = 'priority';
Expand Down Expand Up @@ -37,25 +46,6 @@ module.exports = class PrioritySlashCommand extends SlashCommand {
});
}

getEmoji(priority) {
let emoji;
switch (priority) {
case 'HIGH': {
emoji = '🔴';
break;
}
case 'MEDIUM': {
emoji = '🟠';
break;
}
case 'LOW': {
emoji = '🟢';
break;
}
}
return emoji;
}

/**
*
* @param {import("discord.js").ChatInputCommandInteraction} interaction
Expand Down Expand Up @@ -103,8 +93,8 @@ module.exports = class PrioritySlashCommand extends SlashCommand {

const priority = interaction.options.getString('priority', true);
let name = interaction.channel.name;
if (ticket.priority) name = name.replace(this.getEmoji(ticket.priority), this.getEmoji(priority));
else name = this.getEmoji(priority) + name;
if (ticket.priority) name = name.replace(getEmoji(ticket.priority), getEmoji(priority));
else name = getEmoji(priority) + name;
await interaction.channel.setName(name);

// don't reassign ticket because the original is used below
Expand Down Expand Up @@ -139,4 +129,6 @@ module.exports = class PrioritySlashCommand extends SlashCommand {
});

}
};
};

module.exports.getEmoji = getEmoji;

0 comments on commit 34b5090

Please sign in to comment.