-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #417 from Asartea/add-os-command
OS: Add generic OS command
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}); | ||
}, | ||
}; |