Skip to content

Commit

Permalink
Merge pull request #417 from Asartea/add-os-command
Browse files Browse the repository at this point in the history
OS: Add generic OS command
  • Loading branch information
xandora authored Nov 30, 2023
2 parents 9e3abed + e2a2d87 commit 427f208
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
14 changes: 14 additions & 0 deletions botCommands/__snapshots__/os.test.js.snap
Original file line number Diff line number Diff line change
@@ -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. <https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options>",
"title": "Windows",
"url": "https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options",
},
],
}
`;
23 changes: 23 additions & 0 deletions botCommands/os.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const Discord = require("discord.js");
const { registerBotCommand } = require("../botEngine");

const command = {
regex: /(?<!\S)!os(?!\S)/,
cb: () => {
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. <https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options>"
)
.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;
50 changes: 50 additions & 0 deletions botCommands/os.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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([
['so'],
['os'],
['!so'],
['! 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();
});
});
});
22 changes: 22 additions & 0 deletions new-era-commands/slash/os.js
Original file line number Diff line number Diff line change
@@ -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. <https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options>')
.setURL('https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installation-overview#os-options');

await interaction.reply({
content: userId ? `<@${userId}>` : '',
embeds: [osEmbed],
});
},
};

0 comments on commit 427f208

Please sign in to comment.