diff --git a/apps/bot-discord/src/commands/feedbackDislike.js b/apps/bot-discord/src/commands/feedbackDislike.js index 53de94b..469aa36 100644 --- a/apps/bot-discord/src/commands/feedbackDislike.js +++ b/apps/bot-discord/src/commands/feedbackDislike.js @@ -1,3 +1,4 @@ +import { checkForPerms } from '../utils/checkPerms.js'; import trainAISelectMenu from '../utils/trainAISelectMenu.js'; export default { @@ -6,9 +7,7 @@ export default { }, async execute(helper, config, interaction) { if ( - interaction.member.roles.highest.comparePositionTo( - config.discord.trainRole - ) < 0 + checkForPerms(config, interaction.member) ) return interaction.reply({ content: 'You don\'t have the permission to do this.', diff --git a/apps/bot-discord/src/commands/feedbackLike.js b/apps/bot-discord/src/commands/feedbackLike.js index e00f3de..5dd2aa2 100644 --- a/apps/bot-discord/src/commands/feedbackLike.js +++ b/apps/bot-discord/src/commands/feedbackLike.js @@ -1,29 +1,29 @@ +import { checkForPerms } from '../utils/checkPerms.js'; + export default { - data: { - name: 'fb-like' - }, - async execute(helper, config, interaction) { - if ( - interaction.member.roles.highest.comparePositionTo( - config.discord.trainRole - ) < 0 - ) - return interaction.reply({ - content: 'You don\'t have the permission to do this.', - ephemeral: true - }); - // FIXME: somehow get the intent? - // maybe storing in a collection and fetching the msg id with its label? - /* - helper.sendTrainData(interactedMessage, i.values[0]); + data: { + name: 'fb-like' + }, + async execute(helper, config, interaction) { + if ( + checkForPerms(config, interaction.member) + ) + return interaction.reply({ + content: 'You don\'t have the permission to do this.', + ephemeral: true + }); + // FIXME: somehow get the intent? + // maybe storing in a collection and fetching the msg id with its label? + /* + helper.sendTrainData(interactedMessage, i.values[0]); - i.reply({ content: 'Sent training data to server.', ephemeral: true }); + i.reply({ content: 'Sent training data to server.', ephemeral: true }); - interaction.message.edit({ components: [] }); - */ - interaction.reply({ - content: 'Feature currently not available. Please use the dislike button.', - ephemeral: true - }) - } + interaction.message.edit({ components: [] }); + */ + interaction.reply({ + content: 'Feature currently not available. Please use the dislike button.', + ephemeral: true + }); + } }; diff --git a/apps/bot-discord/src/commands/trainMessage.js b/apps/bot-discord/src/commands/trainMessage.js index 7644a78..35ff36a 100644 --- a/apps/bot-discord/src/commands/trainMessage.js +++ b/apps/bot-discord/src/commands/trainMessage.js @@ -1,5 +1,6 @@ import { ContextMenuCommandBuilder, ApplicationCommandType } from 'discord.js'; import trainAISelectMenu from '../utils/trainAISelectMenu.js'; +import { checkForPerms } from '../utils/checkPerms.js'; export default { data: new ContextMenuCommandBuilder() @@ -7,9 +8,7 @@ export default { .setType(ApplicationCommandType.Message), async execute(helper, config, interaction) { if ( - interaction.member.roles.highest.comparePositionTo( - interaction.member.guild.roles.cache.get(config.discord.trainRole) - ) < 0 + checkForPerms(config, interaction.member) ) return interaction.reply({ content: 'You don\'t have the permission to do this.', diff --git a/apps/bot-discord/src/config.example.json b/apps/bot-discord/src/config.example.json index 76cf576..91536aa 100644 --- a/apps/bot-discord/src/config.example.json +++ b/apps/bot-discord/src/config.example.json @@ -1,6 +1,6 @@ { "discord": { - "trainRole": "955220417969262612", + "trainRoles": ["1019903194941362198", "955220417969262612"], "botId": "1038762591805247518", "ignoreRole": "1027874293192863765" }, diff --git a/apps/bot-discord/src/config.json b/apps/bot-discord/src/config.json index 2521b32..774e3e6 100644 --- a/apps/bot-discord/src/config.json +++ b/apps/bot-discord/src/config.json @@ -1,6 +1,6 @@ { "discord": { - "trainRole": "955220417969262612", + "trainRoles": ["1019903194941362198", "955220417969262612"], "botId": "1038762591805247518", "ignoreRole": "1027874293192863765" }, diff --git a/apps/bot-discord/src/index.js b/apps/bot-discord/src/index.js index 27f34f4..945d600 100644 --- a/apps/bot-discord/src/index.js +++ b/apps/bot-discord/src/index.js @@ -79,4 +79,4 @@ for (const file of helperEventFiles) { } } -client.login(process.env.DISCORD_TOKEN); +client.login(process.env.DISCORD_TOKEN); \ No newline at end of file diff --git a/apps/bot-discord/src/utils/checkPerms.js b/apps/bot-discord/src/utils/checkPerms.js new file mode 100644 index 0000000..fd8463a --- /dev/null +++ b/apps/bot-discord/src/utils/checkPerms.js @@ -0,0 +1,8 @@ +export function checkForPerms(config, member) { + for (let role in config.discord.trainRoles) { + if (member.roles.cache.get(role)) { + return true; + } + } + return false; +} \ No newline at end of file