Repository: TheOdinProject/odin-bot-v2
Pull request #164 (2021-04-05 23:46:34)

Fix: mobile identation for code command
<!-- 
Thanks for your interest in The Odin Project's Odin Bot. In order to get PRs closed in a reasonable amount of time, we request that you include a baseline of information about the changes you are proposing. Please answer the following triage questions:
-->

 - [x] You have read the [Odin Bot README/Contributing Guide](https://github.com/TheOdinProject/odin-bot-v2/blob/master/README.md).

#### 1.Describe the changes made:

Fix mobile indentation for code command.

before:
![before](https://user-images.githubusercontent.com/36450233/113639578-23795080-9682-11eb-96a1-85ff006cae97.jpg)

after:
![resized-after](https://user-images.githubusercontent.com/36450233/113639557-178d8e80-9682-11eb-99b3-19e1a686b289.jpg)

#### 2. If this PR modifies a command, please provide a screenshot of the passing tests below. NOTE: Your PR will not be merged if you have any failing test cases. 

![tests-code](https://user-images.githubusercontent.com/36450233/113639613-3ab83e00-9682-11eb-9432-1d1abf87f36e.png)


#### 3. If this PR is related to an open issue please reference it with the `#` operator and the issue number below:

#XXXXX



Patch:
diff --git a/botCommands/help.js b/botCommands/help.js
index a653dd2..c0a3afb 100644
--- a/botCommands/help.js
+++ b/botCommands/help.js
@@ -34,17 +34,18 @@ const code = {
       .setDescription(
         !users ? 'Hey, here\'s some helpful tips on sharing your code with others!' : `Hey, ${users.trim()}, here's some helpful tips on sharing your code with others!`,
       )
+      // weird formating is needer to avoid identation on mobile
       .addField(
         'Sharing Code on Discord',
         `To write multiple lines of code with language syntax highlighting, use three backticks (<https://i.stack.imgur.com/ETTnT.jpg>), followed by the language.
       
-      \\\`\\\`\\\`js
-      [Put your JavaScript Code here!]
-      \\\`\\\`\\\`
+\\\`\\\`\\\`js
+[Put your JavaScript Code here!]
+\\\`\\\`\\\`
 
-      For \`inline code\` use one backtick (no syntax highlighting):
+For \`inline code\` use one backtick (no syntax highlighting):
 
-      \\\`Code here!\\\`
+\\\`Code here!\\\`
       `,
       )
       .addField(
diff --git a/botCommands/simpleCommands.js b/botCommands/simpleCommands.js
index 0eb18b6..93742aa 100644
--- a/botCommands/simpleCommands.js
+++ b/botCommands/simpleCommands.js
@@ -47,6 +47,25 @@ const data = {
 };
 registerBotCommand(data.regex, data.cb);
 
+// registerBotCommand(/\/sexpresso/, () => `https://i.gifer.com/8EC5.gif`);
+
+const sexpresso = {
+  regex: /(?<!\S)\/sexpresso(?!\S)/,
+  cb: () => 'https://tenor.com/view/mac-spilling-coffee-starbucks-gif-6241590',
+};
+registerBotCommand(sexpresso.regex, sexpresso.cb);
+
+const peen = {
+  regex: /(?<!\S)\/peen(?!\S)/,
+  cb: ({ author }) => {
+    if (author.id === 418918922507780096) {
+      return 'https://media.giphy.com/media/K5IEMtDZHxQZy/giphy.gif';
+    }
+    return null;
+  },
+};
+registerBotCommand(peen.regex, peen.cb);
+
 const google = {
   regex: /\B\/google\s+.+/,
   cb: ({ content }) => {
@@ -112,6 +131,8 @@ module.exports = {
   fu,
   question,
   data,
+  sexpresso,
+  peen,
   google,
   fg,
   dab,


Test patch:
diff --git a/botCommands/__snapshots__/help.test.js.snap b/botCommands/__snapshots__/help.test.js.snap
index 97c0f7d..e35a173 100644
--- a/botCommands/__snapshots__/help.test.js.snap
+++ b/botCommands/__snapshots__/help.test.js.snap
@@ -11,13 +11,13 @@ Object {
       "name": "Sharing Code on Discord",
       "value": "To write multiple lines of code with language syntax highlighting, use three backticks (<https://i.stack.imgur.com/ETTnT.jpg>), followed by the language.
       
-      \\\\\`\\\\\`\\\\\`js
-      [Put your JavaScript Code here!]
-      \\\\\`\\\\\`\\\\\`
+\\\\\`\\\\\`\\\\\`js
+[Put your JavaScript Code here!]
+\\\\\`\\\\\`\\\\\`
 
-      For \`inline code\` use one backtick (no syntax highlighting):
+For \`inline code\` use one backtick (no syntax highlighting):
 
-      \\\\\`Code here!\\\\\`
+\\\\\`Code here!\\\\\`
       ",
     },
     Object {
@@ -57,13 +57,13 @@ Object {
       "name": "Sharing Code on Discord",
       "value": "To write multiple lines of code with language syntax highlighting, use three backticks (<https://i.stack.imgur.com/ETTnT.jpg>), followed by the language.
       
-      \\\\\`\\\\\`\\\\\`js
-      [Put your JavaScript Code here!]
-      \\\\\`\\\\\`\\\\\`
+\\\\\`\\\\\`\\\\\`js
+[Put your JavaScript Code here!]
+\\\\\`\\\\\`\\\\\`
 
-      For \`inline code\` use one backtick (no syntax highlighting):
+For \`inline code\` use one backtick (no syntax highlighting):
 
-      \\\\\`Code here!\\\\\`
+\\\\\`Code here!\\\\\`
       ",
     },
     Object {
@@ -103,13 +103,13 @@ Object {
       "name": "Sharing Code on Discord",
       "value": "To write multiple lines of code with language syntax highlighting, use three backticks (<https://i.stack.imgur.com/ETTnT.jpg>), followed by the language.
       
-      \\\\\`\\\\\`\\\\\`js
-      [Put your JavaScript Code here!]
-      \\\\\`\\\\\`\\\\\`
+\\\\\`\\\\\`\\\\\`js
+[Put your JavaScript Code here!]
+\\\\\`\\\\\`\\\\\`
 
-      For \`inline code\` use one backtick (no syntax highlighting):
+For \`inline code\` use one backtick (no syntax highlighting):
 
-      \\\\\`Code here!\\\\\`
+\\\\\`Code here!\\\\\`
       ",
     },
     Object {
@@ -149,13 +149,13 @@ Object {
       "name": "Sharing Code on Discord",
       "value": "To write multiple lines of code with language syntax highlighting, use three backticks (<https://i.stack.imgur.com/ETTnT.jpg>), followed by the language.
       
-      \\\\\`\\\\\`\\\\\`js
-      [Put your JavaScript Code here!]
-      \\\\\`\\\\\`\\\\\`
+\\\\\`\\\\\`\\\\\`js
+[Put your JavaScript Code here!]
+\\\\\`\\\\\`\\\\\`
 
-      For \`inline code\` use one backtick (no syntax highlighting):
+For \`inline code\` use one backtick (no syntax highlighting):
 
-      \\\\\`Code here!\\\\\`
+\\\\\`Code here!\\\\\`
       ",
     },
     Object {
diff --git a/botCommands/__snapshots__/simpleCommands.test.js.snap b/botCommands/__snapshots__/simpleCommands.test.js.snap
index 3ab1c68..286a21a 100644
--- a/botCommands/__snapshots__/simpleCommands.test.js.snap
+++ b/botCommands/__snapshots__/simpleCommands.test.js.snap
@@ -20,6 +20,8 @@ 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[`/peen callback returns correct output 1`] = `"https://media.giphy.com/media/K5IEMtDZHxQZy/giphy.gif"`;
+
 exports[`/question callback returns correct output 1`] = `
 Object {
   "author": null,
@@ -36,6 +38,8 @@ Object {
 }
 `;
 
+exports[`/sexpresso callback returns correct output 1`] = `"https://tenor.com/view/mac-spilling-coffee-starbucks-gif-6241590"`;
+
 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/simpleCommands.test.js b/botCommands/simpleCommands.test.js
index e45be46..6a17f7c 100644
--- a/botCommands/simpleCommands.test.js
+++ b/botCommands/simpleCommands.test.js
@@ -369,6 +369,134 @@ describe('/data', () => {
   });
 });
 
+describe('/sexpresso', () => {
+  describe('regex', () => {
+    it.each([
+      ['/sexpresso'],
+      [' /sexpresso'],
+      ['/sexpresso @odin-bot'],
+      ['@odin-bot /sexpresso'],
+    ])('correct strings trigger the callback', (string) => {
+      expect(commands.sexpresso.regex.test(string)).toBeTruthy();
+    });
+
+    it.each([
+      ['/sexpress'],
+      ['sexpresso'],
+      ['/sexpreso'],
+      ['/sexpressos'],
+      ['```function("/sexpresso", () => {}```'],
+      ['/s'],
+      [''],
+      [' '],
+      [' /'],
+      ['@odin-bot / sexpresso'],
+      ['/sexp&resso'],
+      ['/sexpress^o'],
+      ['/sexpresso!'],
+      ['@odin-bot/ sexpresso'],
+      ['https://sexpresso.com'],
+    ])("'%s' does not trigger the callback", (string) => {
+      expect(commands.sexpresso.regex.test(string)).toBeFalsy();
+    });
+
+    it.each([
+      ['Check this out! /sexpresso'],
+      ["Don't worry about /sexpresso"],
+      ['Hey @odin-bot, /sexpresso'],
+      ['/@odin-bot ^ /me /sexpresso /tests$*'],
+    ])("'%s' - command can be anywhere in the string", (string) => {
+      expect(commands.sexpresso.regex.test(string)).toBeTruthy();
+    });
+
+    it.each([
+      ['@user/sexpresso'],
+      ["it's about/sexpresso"],
+      ['/sespressoisanillusion'],
+      ['/sexpresso/'],
+      ['/sexpresso*'],
+      ['/sexpresso...'],
+    ])(
+      "'%s' - command should be its own word/group - no leading or trailing characters",
+      (string) => {
+        expect(commands.sexpresso.regex.test(string)).toBeFalsy();
+      },
+    );
+  });
+
+  describe('callback', () => {
+    it('returns correct output', () => {
+      expect(commands.sexpresso.cb()).toMatchSnapshot();
+    });
+  });
+});
+
+describe('/peen', () => {
+  describe('regex', () => {
+    it.each([['/peen'], [' /peen'], ['/peen @odin-bot'], ['@odin-bot /peen']])(
+      'correct strings trigger the callback',
+      (string) => {
+        expect(commands.peen.regex.test(string)).toBeTruthy();
+      },
+    );
+
+    it.each([
+      ['/pen'],
+      ['peen'],
+      ['/pee'],
+      ['/peens'],
+      ['```function("/peen", () => {}```'],
+      ['/peena'],
+      [''],
+      [' '],
+      [' /'],
+      ['@odin-bot / peen'],
+      ['/pe&en'],
+      ['/pe^en'],
+      ['/peen!'],
+      ['@odin-bot/ peen'],
+      ['https://peen.com'],
+    ])("'%s' does not trigger the callback", (string) => {
+      expect(commands.peen.regex.test(string)).toBeFalsy();
+    });
+
+    it.each([
+      ['Check this out! /peen'],
+      ["Don't worry about /peen"],
+      ['Hey @odin-bot, /peen'],
+      ['/@odin-bot ^ /me /peen /tests$*'],
+    ])("'%s' - command can be anywhere in the string", (string) => {
+      expect(commands.peen.regex.test(string)).toBeTruthy();
+    });
+
+    it.each([
+      ['@user/peen'],
+      ["it's about/peen"],
+      ['/peenisanillusion'],
+      ['/peen/'],
+      ['/peen*'],
+      ['/peen...'],
+    ])(
+      "'%s' - command should be its own word/group - no leading or trailing characters",
+      (string) => {
+        expect(commands.peen.regex.test(string)).toBeFalsy();
+      },
+    );
+  });
+
+  describe('callback', () => {
+    it('returns correct output', () => {
+      expect(
+        commands.peen.cb({
+          author: {
+            id: 418918922507780096,
+          },
+        }),
+      ).toMatchSnapshot();
+    });
+  });
+});
+
 describe('/google', () => {
   describe('regex', () => {
     it.each([