Repository: TheOdinProject/odin-bot-v2
Pull request #373 (2023-07-31 21:23:38)

move legacy !question command to its own module
<!-- Thank you for taking the time to contribute to The Odin Project. In order to get this pull request (PR) merged in a reasonable amount of time, you must complete this entire template. -->

## Because
<!-- Summarize the purpose or reasons for this PR, e.g. what problem it solves or what benefit it provides. -->
We are slowly but surely updating our commands to slash commands and I'm doing some bot housekeeping. The `!question` command was decided on in the past as a great one to keep in the legacy format as well. It works nicely when typed in a sentence like:
> Hi there! I really think people would be way better equipped to help you out if you format your `!question` according to the below bot output. 


## This PR
<!-- A bullet point list of one or more items describing the specific changes. -->
- moves the `!question` command out of the `simpleCommands` file into their own `question-legacy` file
- adds a separate test file for the `!question` command and removes the test from the `simpleCommands.test.js`
- adds a separate snapshot file for the `!question` cb and removes it from the `simpleCommands` snapshot file.

## Issue
<!--
If this PR closes an open issue in this repo, replace the XXXXX below with the issue number, e.g. Closes #2013.

If this PR closes an open issue in another TOP repo, replace the #XXXXX with the URL of the issue, e.g. Closes https://github.com/TheOdinProject/curriculum/issues/XXXXX

If this PR does not close, but is related to another issue or PR, you can link it as above without the 'Closes' keyword, e.g. 'Related to #2013'.
-->
Closes #XXXXX

## Additional Information
<!-- Any other information about this PR, such as a link to a Discord discussion. -->


## Pull Request Requirements
<!-- Replace the whitespace between the square brackets with an 'x', e.g. [x]. After you create the PR, they will become checkboxes that you can click on. -->
-   [x] I have thoroughly read and understand [The Odin Project Contributing Guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md)

-   [x] The title of this PR follows the `location of change: brief description of change` format, e.g. `Callbacks command: Update verbiage`
-   [x] The `Because` section summarizes the reason for this PR
-   [x] The `This PR` section has a bullet point list describing the changes in this PR
-   [x] If this PR addresses an open issue, it is linked in the `Issue` section
-   [x] If this PR adds new features or functionality, I have added new tests
-   [x] If applicable, I have ensured all tests related to any command files included in this PR pass, and/or all snapshots are up to date



Patch:
diff --git a/README.md b/README.md
index dae1368..61f0df3 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,15 @@
-# Odin Bot - Discord Bot for The Odin Project
+# ODIN BOTTTTTTTTTTTTTTTTTT
 
-Welcome to the Odin Bot repository! This is the codebase that powers Odin's right-hand bot, which is used by the tens of thousands of dedicated Odinites in the [Discord community of The Odin Project](https://discord.gg/fbFCkYabZB). 
+here lies the code that runs Odin's right hand bot... 
 
-[The Odin Project](https://www.theodinproject.com) is an open-source curriculum for learning full-stack web development. This bot plays a crucial role in our Discord server by displaying helpful information, driving positive engagement through the points system, and incorporating various other nifty features.
-
-## Tech Stack
-
-[![Build Status](https://circleci.com/gh/TheOdinProject/theodinproject.svg?style=svg)](https://app.circleci.com/pipelines/github/TheOdinProject/odin-bot-v2)
-
-This bot has been built with NodeJS and [the DiscordJS module](https://discord.js.org/#/docs/main/stable/general/welcome).
+This bot is used in a Discord server for [theodinproject.com](https://www.theodinproject.com), an open source web development bootcamp, and is used by tens of thousands of Odinites. This bot has been built with NodeJS and [DiscordJS](https://discord.js.org/#/docs/main/stable/general/welcome).
 
+Follow [this link](https://discord.gg/fbFCkYabZB) to join our Discord server!
 
 ## Contributing
+[![Build Status](https://circleci.com/gh/TheOdinProject/theodinproject.svg?style=svg)](https://app.circleci.com/pipelines/github/TheOdinProject/odin-bot-v2)
 
-We're thrilled that you're interested in contributing to the Odin Bot! Our bot depends on open source contributions to grow, improve, and thrive. Whether you're a seasoned pro or just starting out, we welcome all kinds of contributions!
+Thank you for your interest in contributing to the Odin Bot. The Odin Project depends on open source contributions to grow, improve, and thrive. We welcome contributions from beginners and experienced developers alike.
 
-For more information on how to get started, we have a really helpful [wiki guide for setting up the Odin Bot](https://github.com/TheOdinProject/odin-bot-v2/wiki/Getting-Started) and please also refer to [our TOP contributing guide](https://github.com/TheOdinProject/odin-bot-v2/wiki/Contributing-Guide).
+To find out more about how you can contribute, please read our [getting started](https://github.com/TheOdinProject/odin-bot-v2/wiki/Getting-Started) and [contributing guide](https://github.com/TheOdinProject/odin-bot-v2/wiki/Contributing-Guide).
 
-Let's have a blast building and improving the Odin Bot together! We can't wait to see your awesome contributions!
\ No newline at end of file
diff --git a/botCommands/question-legacy.js b/botCommands/question-legacy.js
new file mode 100644
index 0000000..bf024cd
--- /dev/null
+++ b/botCommands/question-legacy.js
@@ -0,0 +1,28 @@
+const Discord = require('discord.js');
+const { registerBotCommand } = require('../botEngine');
+
+const question = {
+  regex: /(?<!\S)!question(?!\S)/,
+  cb: () => {
+    const questionEmbed = new Discord.EmbedBuilder()
+      .setColor('#cc9543')
+      .setTitle('Asking Great Questions')
+      .setDescription(`
+Asking context-rich questions makes it easy to receive help, and makes it easy for others to help you quickly! Great engineers ask great questions, and the prompt below is an invitation to improve your skills and set yourself up for success in the workplace. 
+
+**Project/Exercise:**
+**Lesson link:**
+**Code:** [code sandbox like replit or codepen]
+**Issue/Problem:** [screenshots if applicable]
+**What I expected:** 
+**What I've tried:** 
+
+For even more context around on how to hone your question-asking skills, give this a read: https://www.theodinproject.com/guides/community/how_to_ask
+              `);
+
+    return { embeds: [questionEmbed] };
+  },
+};
+registerBotCommand(question.regex, question.cb);
+
+module.exports = question;
diff --git a/botCommands/simpleCommands.js b/botCommands/simpleCommands.js
index 16a0d00..b671195 100644
--- a/botCommands/simpleCommands.js
+++ b/botCommands/simpleCommands.js
@@ -28,30 +28,6 @@ const fu = {
 };
 registerBotCommand(fu.regex, fu.cb);
 
-const question = {
-  regex: /(?<!\S)!question(?!\S)/,
-  cb: () => {
-    const questionEmbed = new Discord.EmbedBuilder()
-      .setColor('#cc9543')
-      .setTitle('Asking Great Questions')
-      .setDescription(`
-Asking context-rich questions makes it easy to receive help, and makes it easy for others to help you quickly! Great engineers ask great questions, and the prompt below is an invitation to improve your skills and set yourself up for success in the workplace. 
-
-**Project/Exercise:**
-**Lesson link:**
-**Code:** [code sandbox like replit or codepen]
-**Issue/Problem:** [screenshots if applicable]
-**What I expected:** 
-**What I've tried:** 
-
-For even more context around on how to hone your question-asking skills, give this a read: https://www.theodinproject.com/guides/community/how_to_ask
-              `);
-
-    return { embeds: [questionEmbed] };
-  },
-};
-registerBotCommand(question.regex, question.cb);
-
 const data = {
   regex: /(?<!\S)!data(?!\S)/,
   cb: () => {
@@ -126,7 +102,6 @@ module.exports = {
   smart,
   lenny,
   fu,
-  question,
   data,
   google,
   dab,


Test patch:
diff --git a/botCommands/__snapshots__/question-legacy.test.js.snap b/botCommands/__snapshots__/question-legacy.test.js.snap
new file mode 100644
index 0000000..cc793f1
--- /dev/null
+++ b/botCommands/__snapshots__/question-legacy.test.js.snap
@@ -0,0 +1,24 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`!question callback returns correct output 1`] = `
+{
+  "embeds": [
+    {
+      "color": 13407555,
+      "description": "
+Asking context-rich questions makes it easy to receive help, and makes it easy for others to help you quickly! Great engineers ask great questions, and the prompt below is an invitation to improve your skills and set yourself up for success in the workplace. 
+
+**Project/Exercise:**
+**Lesson link:**
+**Code:** [code sandbox like replit or codepen]
+**Issue/Problem:** [screenshots if applicable]
+**What I expected:** 
+**What I've tried:** 
+
+For even more context around on how to hone your question-asking skills, give this a read: https://www.theodinproject.com/guides/community/how_to_ask
+              ",
+      "title": "Asking Great Questions",
+    },
+  ],
+}
+`;
diff --git a/botCommands/__snapshots__/simpleCommands.test.js.snap b/botCommands/__snapshots__/simpleCommands.test.js.snap
index b722080..571186d 100644
--- a/botCommands/__snapshots__/simpleCommands.test.js.snap
+++ b/botCommands/__snapshots__/simpleCommands.test.js.snap
@@ -43,29 +43,6 @@ exports[`!lenny callback returns correct output 1`] = `"( ͡° ͜ʖ ͡°)"`;
 
 exports[`!motivate callback returns correct output 1`] = `"Don't give up! https://www.youtube.com/watch?v=KxGRhd_iWuE"`;
 
-exports[`!question callback returns correct output 1`] = `
-{
-  "embeds": [
-    {
-      "color": 13407555,
-      "description": "
-Asking context-rich questions makes it easy to receive help, and makes it easy for others to help you quickly! Great engineers ask great questions, and the prompt below is an invitation to improve your skills and set yourself up for success in the workplace. 
-
-**Project/Exercise:**
-**Lesson link:**
-**Code:** [code sandbox like replit or codepen]
-**Issue/Problem:** [screenshots if applicable]
-**What I expected:** 
-**What I've tried:** 
-
-For even more context around on how to hone your question-asking skills, give this a read: https://www.theodinproject.com/guides/community/how_to_ask
-              ",
-      "title": "Asking Great Questions",
-    },
-  ],
-}
-`;
-
 exports[`!smart callback returns correct output 1`] = `"f(ಠ‿↼)z"`;
 
 exports[`!xy callback returns correct output 1`] = `"What problem are you *really* trying to solve? Check out this article to help others better understand your question: <https://xyproblem.info/>"`;
diff --git a/botCommands/question-legacy.test.js b/botCommands/question-legacy.test.js
new file mode 100644
index 0000000..842dd64
--- /dev/null
+++ b/botCommands/question-legacy.test.js
@@ -0,0 +1,63 @@
+const question = require('./question-legacy');
+
+describe('!question', () => {
+  describe('regex', () => {
+    it.each([
+      ['!question'],
+      [' !question'],
+      ['!question @odin-bot'],
+      ['@odin-bot !question'],
+    ])('correct strings trigger the callback', (string) => {
+      expect(question.regex.test(string)).toBeTruthy();
+    });
+
+    it.each([
+      ['!quest'],
+      ['question'],
+      ['!questio'],
+      ['!questions'],
+      ['```function("!question", () => {}```'],
+      ['!questiona'],
+      [''],
+      [' '],
+      [' !'],
+      ['@odin-bot ! question'],
+      ['!ques&tion'],
+      ['!quest^ion'],
+      ['!question!'],
+      ['@odin-bot! question'],
+      ['https:!!question.com'],
+    ])("'%s' does not trigger the callback", (string) => {
+      expect(question.regex.test(string)).toBeFalsy();
+    });
+
+    it.each([
+      ['Check this out! !question'],
+      ["Don't worry about !question"],
+      ['Hey @odin-bot, !question'],
+      ['!@odin-bot ^ !me !question !tests$*'],
+    ])("'%s' - command can be anywhere in the string", (string) => {
+      expect(question.regex.test(string)).toBeTruthy();
+    });
+
+    it.each([
+      ['@user!question'],
+      ["it's about!question"],
+      ['!questionisanillusion'],
+      ['!question!'],
+      ['!question*'],
+      ['!question...'],
+    ])(
+      "'%s' - command should be its own word!group - no leading or trailing characters",
+      (string) => {
+        expect(question.regex.test(string)).toBeFalsy();
+      },
+    );
+  });
+
+  describe('callback', () => {
+    it('returns correct output', () => {
+      expect(question.cb()).toMatchSnapshot();
+    });
+  });
+});
diff --git a/botCommands/simpleCommands.test.js b/botCommands/simpleCommands.test.js
index 38f37e8..5e85160 100644
--- a/botCommands/simpleCommands.test.js
+++ b/botCommands/simpleCommands.test.js
@@ -247,68 +247,6 @@ describe('!fu', () => {
   });
 });
 
-describe('!question', () => {
-  describe('regex', () => {
-    it.each([
-      ['!question'],
-      [' !question'],
-      ['!question @odin-bot'],
-      ['@odin-bot !question'],
-    ])('correct strings trigger the callback', (string) => {
-      expect(commands.question.regex.test(string)).toBeTruthy();
-    });
-
-    it.each([
-      ['!quest'],
-      ['question'],
-      ['!questio'],
-      ['!questions'],
-      ['```function("!question", () => {}```'],
-      ['!questiona'],
-      [''],
-      [' '],
-      [' !'],
-      ['@odin-bot ! question'],
-      ['!ques&tion'],
-      ['!quest^ion'],
-      ['!question!'],
-      ['@odin-bot! question'],
-      ['https:!!question.com'],
-    ])("'%s' does not trigger the callback", (string) => {
-      expect(commands.question.regex.test(string)).toBeFalsy();
-    });
-
-    it.each([
-      ['Check this out! !question'],
-      ["Don't worry about !question"],
-      ['Hey @odin-bot, !question'],
-      ['!@odin-bot ^ !me !question !tests$*'],
-    ])("'%s' - command can be anywhere in the string", (string) => {
-      expect(commands.question.regex.test(string)).toBeTruthy();
-    });
-
-    it.each([
-      ['@user!question'],
-      ["it's about!question"],
-      ['!questionisanillusion'],
-      ['!question!'],
-      ['!question*'],
-      ['!question...'],
-    ])(
-      "'%s' - command should be its own word!group - no leading or trailing characters",
-      (string) => {
-        expect(commands.question.regex.test(string)).toBeFalsy();
-      },
-    );
-  });
-
-  describe('callback', () => {
-    it('returns correct output', () => {
-      expect(commands.question.cb()).toMatchSnapshot();
-    });
-  });
-});
-
 describe('!data', () => {
   describe('regex', () => {
     it.each([['!data'], [' !data'], ['!data @odin-bot'], ['@odin-bot !data']])(