Skip to content

Commit

Permalink
Inspiration Update (#349)
Browse files Browse the repository at this point in the history
* Create inspiration.js

A script that triggers SlackerBot to publish an inspirational quote whenever someone mentions words like 'inspire', 'inspiration', or, 'motivate'.

* Delete Parsers/inspiration.js

* Create Inspiration.js

A script that triggers SlackerBot to publish an inspirational quote whenever someone mentions the words 'inspire', 'inspiration', or 'motivation'.

* Update Inspiration.js

The revised code ensures that responses are triggered only by bang commands (!inspire or !inspiration). This update addresses the concern of over-triggering associated with previously used trigger words.

* Update Inspiration.js

I've modified my code to only check for one regex pattern, specifically '!inspiration'. A match executes the block of code that fetches an inspirational quote from the API and sends it back as a chat response.
  • Loading branch information
ariyadmir authored Oct 3, 2024
1 parent 1c8e637 commit 1b5a10e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Parsers/Inspiration.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/*
activation_example:!inspire
regex:\b!inspire\b|\b!inspiration\b
activation_example:!inspiration
regex:!inspiration
flags:gmi
*/

var quote = new sn_ws.RESTMessageV2();
quote.setEndpoint('https://zenquotes.io/api/random');
quote.setHttpMethod('GET');
var input = current.text.trim();
if (/!inspiration/i.test(input)) {
var quote = new sn_ws.RESTMessageV2();
quote.setEndpoint('https://zenquotes.io/api/random');
quote.setHttpMethod('GET');

var chatResponse = quote.execute();
var chatResponseBody = JSON.parse(chatResponse.getBody());
var quoteText = chatResponseBody[0].q;
var author = chatResponseBody[0].a;
var chatResponse = quote.execute();
var chatResponseBody = JSON.parse(chatResponse.getBody());

if (chatResponseBody && chatResponseBody.length > 0) {
var quoteText = chatResponseBody[0].q;
var author = chatResponseBody[0].a;

new x_snc_slackerbot.Slacker().send_chat(current, 'A dose of inspiration for you!:\n "' + quoteText + '" - ' + author, false);
}
}

new x_snc_slackerbot.Slacker().send_chat(current, 'A dose of inspiration for you!:\n "' + quoteText + '" - ' + author, false);

0 comments on commit 1b5a10e

Please sign in to comment.