From c1dbdda28ea897c73165ae1d4b897b712928bae9 Mon Sep 17 00:00:00 2001 From: Asartea <76259120+Asartea@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:33:44 +0200 Subject: [PATCH 1/2] Add generic OS command --- botCommands/__snapshots__/os.test.js.snap | 14 ++++++ botCommands/os.js | 23 ++++++++++ botCommands/os.test.js | 52 +++++++++++++++++++++++ new-era-commands/slash/os.js | 22 ++++++++++ 4 files changed, 111 insertions(+) create mode 100644 botCommands/__snapshots__/os.test.js.snap create mode 100644 botCommands/os.js create mode 100644 botCommands/os.test.js create mode 100644 new-era-commands/slash/os.js diff --git a/botCommands/__snapshots__/os.test.js.snap b/botCommands/__snapshots__/os.test.js.snap new file mode 100644 index 00000000..8cf5aa1e --- /dev/null +++ b/botCommands/__snapshots__/os.test.js.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`!os callback returns correct output 1`] = ` +{ + "embeds": [ + { + "color": 13407555, + "description": "**The Odin Project does not support Windows or any other OS outside of our recommendations**. We are happy to assist with any questions about installing a VM, using WSL, or dual booting Linux. ", + "title": "Windows", + "url": "https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options", + }, + ], +} +`; diff --git a/botCommands/os.js b/botCommands/os.js new file mode 100644 index 00000000..b80f99a9 --- /dev/null +++ b/botCommands/os.js @@ -0,0 +1,23 @@ +const Discord = require("discord.js"); +const { registerBotCommand } = require("../botEngine"); + +const command = { + regex: /(? { + const osEmbed = new Discord.EmbedBuilder() + .setColor("#cc9543") + .setTitle("Windows") + .setDescription( + "**The Odin Project does not support Windows or any other OS outside of our recommendations**. We are happy to assist with any questions about installing a VM, using WSL, or dual booting Linux. " + ) + .setURL( + "https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options" + ); + + return { embeds: [osEmbed] }; + }, +}; + +registerBotCommand(command.regex, command.cb); + +module.exports = command; diff --git a/botCommands/os.test.js b/botCommands/os.test.js new file mode 100644 index 00000000..2483cea2 --- /dev/null +++ b/botCommands/os.test.js @@ -0,0 +1,52 @@ +const command = require('./os'); + +describe('!os', () => { + describe('regex', () => { + it.each([ + ['!os'], + [' !os'], + ['!os @odin-bot'], + ['@odin-bot !os'], + ])('correct strings trigger the callback', (string) => { + expect(command.regex.test(string)).toBeTruthy(); + }); + + it.each([ + ['wndows'], + ['os'], + ['window'], + ['!wndows'], + ['!window'], + ['! os'], + ['!aos'], + ])("'%s' does not trigger the callback", (string) => { + expect(command.regex.test(string)).toBeFalsy(); + }); + + it.each([ + ['Check this out! !os'], + ['Don\'t worry about !os'], + ['Hey @odin-bot, !os'], + ['!@odin-bot ^ !me !os !tests$*'], + ])("'%s' - command can be anywhere in the string", (string) => { + expect(command.regex.test(string)).toBeTruthy(); + }); + + it.each([ + ['@user!os'], + ['it\'s about!os'], + ['!osanillusion'], + ['!os!'], + ['!os*'], + ['!os...'], + ])("'%s' - command should be its own word!group - no leading or trailing characters", (string) => { + expect(command.regex.test(string)).toBeFalsy(); + }); + }); + + describe('callback', () => { + it('returns correct output', () => { + expect(command.cb()).toMatchSnapshot(); + }); + }); +}); diff --git a/new-era-commands/slash/os.js b/new-era-commands/slash/os.js new file mode 100644 index 00000000..f189511e --- /dev/null +++ b/new-era-commands/slash/os.js @@ -0,0 +1,22 @@ +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('os') + .setDescription('Using other OS\'s') + .addUserOption((option) => option.setName('user').setDescription('user to ping')), + execute: async (interaction) => { + const userId = interaction.options.getUser('user')?.id; + + const osEmbed = new EmbedBuilder() + .setColor('#cc9543') + .setTitle('Windows') + .setDescription('**The Odin Project does not support Windows or any other OS outside of our recommendations**. We are happy to assist with any questions about installing a VM, using WSL, or dual booting Linux. ') + .setURL('https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options'); + + await interaction.reply({ + content: userId ? `<@${userId}>` : '', + embeds: [osEmbed], + }); + }, +}; From e2a2d8731ee71c4ea1a9f3891436d14c46c121d8 Mon Sep 17 00:00:00 2001 From: Asartea <76259120+Asartea@users.noreply.github.com> Date: Fri, 29 Sep 2023 08:47:14 +0200 Subject: [PATCH 2/2] Update tests --- botCommands/os.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/botCommands/os.test.js b/botCommands/os.test.js index 2483cea2..dc3d108b 100644 --- a/botCommands/os.test.js +++ b/botCommands/os.test.js @@ -12,11 +12,9 @@ describe('!os', () => { }); it.each([ - ['wndows'], + ['so'], ['os'], - ['window'], - ['!wndows'], - ['!window'], + ['!so'], ['! os'], ['!aos'], ])("'%s' does not trigger the callback", (string) => {