Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: refactoring gratibot features #446

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
22ac7ee
feat: rework balance, help, join and refund
zjorge96 Oct 24, 2023
116c277
Merge branch 'refactoring-features'
zjorge96 Oct 24, 2023
e6fc1a2
fix: updated GoldenGratitude error name
zjorge96 Oct 24, 2023
e932dbf
feat: rework deduction, golden-recognize, leaderboard, recognize and …
zjorge96 Oct 24, 2023
78060a8
feat: rework metrics
zjorge96 Oct 25, 2023
73579e8
feat: adding features.js and slash.js
zjorge96 Oct 25, 2023
a4f4ff8
feat: updated most broken tests and removed features folder
zjorge96 Oct 27, 2023
f655433
Merge branch 'main' of github.com:liatrio/gratibot
zjorge96 Oct 27, 2023
a6c5e8e
fix: remove feature/deduction.js
zjorge96 Oct 27, 2023
95d51a7
fix: reducing function and cognitive complexity size
zjorge96 Nov 1, 2023
076e0b3
fix: adding winston info wrapper for code climate errors
zjorge96 Nov 1, 2023
31fdb10
fix: adding winston info wrapper for code climate errors
zjorge96 Nov 1, 2023
4896096
fix: adding winston error and debug wrapper for code climate errors
zjorge96 Nov 1, 2023
abee821
fix: adding codeclimate yml for unavoidable duplicates
zjorge96 Nov 1, 2023
505ff33
fix: reducing lines in module.exports
zjorge96 Nov 1, 2023
1ba3659
fix: removing winston wrapper functions
zjorge96 Nov 1, 2023
9e7c8e8
fix: updating tests
zjorge96 Nov 1, 2023
a6e41f1
fix: updated duplication threshold for code climate winston issues
zjorge96 Nov 1, 2023
3a4e645
fix: features recognition call and thunderfury dupllicate bot error
zjorge96 Nov 1, 2023
a706b4e
Merge branch 'main' of github.com:liatrio/gratibot
zjorge96 Nov 1, 2023
f0cedd8
Merge branch 'main' into refactoring-features
zjorge96 Nov 1, 2023
12a204c
fix: added semi-colons and removed slash command
zjorge96 Nov 1, 2023
3041c1c
test: leaderboard and deduction test error fix
zjorge96 Nov 13, 2023
96b7804
fix: fix messageutil lint
zjorge96 Nov 13, 2023
ee2993c
test: added help tests
zjorge96 Nov 13, 2023
ddc6754
test: lint help tests
zjorge96 Nov 13, 2023
13d6664
Merge branch 'main' of github.com:liatrio/gratibot into refactoring-f…
Pactionly Jan 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins:
duplication:
enabled: true
config:
languages:
javascript:
mass_threshold: 130
152 changes: 1 addition & 151 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ const { App } = require("@slack/bolt");
const express = require("express");
const webserver = express();
const winston = require("./winston");
const {
recognizeEmoji,
maximum,
reactionEmoji,
goldenRecognizeEmoji,
slashCommand,
} = require("./config");

const app = new App({
token: process.env.BOT_USER_OAUTH_ACCESS_TOKEN,
Expand Down Expand Up @@ -65,154 +58,11 @@ webserver.get("/health", async (req, res) => {
winston.debug("Health check passed");
});

var normalizedPath = require("path").join(__dirname, "features");
require("fs")
.readdirSync(normalizedPath)
.forEach(function (file) {
require("./features/" + file)(app);
});

/// ////////////////////////////////////////////////////////////
// Slash Command Logic //
/// ////////////////////////////////////////////////////////////

function parseCommand(command) {
const parsed = {
// Default values for each parameter
valid: false, // indicates if a command is valid
command: "", // holds the type of command
user: "", // holds the value for the user that will be targeted
};

const raw = command.text.split(" "); // raw command as an array
parsed.command = raw[0];

switch (raw[0]) {
case "help":
parsed.valid = true; // command is valid, but doesn't require any additional info
break;
}

// if none of the above cases are true, parsed.valid will stay false

return parsed;
}

app.command(slashCommand, async ({ command, ack, respond }) => {
await ack();
const userCommand = parseCommand(command);

switch (userCommand.command) {
case "help":
await respond(helpMarkdown);
break;
default:
await respond(errorMarkdown);
}
});
require("./features")(app);

(async () => {
await app.start(3000);
webserver.listen(process.env.PORT || 3000);

winston.info("⚡️ Bolt app is running!");
})();

/// ////////////////////////////////////////////////////////////
// Variables //
/// ////////////////////////////////////////////////////////////

const errorMarkdown = `
:well: Command does not exist.
Here is a list of commands that actually work:

/gratibot help: talks about what Gratibot can do!
`;

// Text is rendered into help command
const helpMarkdown = `
:wave: Hi there! Let's take a look at what I can do!




*Give Recognition*

You can give up to ${maximum} recognitions per day.

First, make sure I have been invited to the channel you want to recognize \
someone in. Then, write a brief message describing what someone did, \
\`@mention\` them and include the ${recognizeEmoji} emoji...I'll take it from there!

> Thanks @alice for helping me fix my pom.xml ${recognizeEmoji}

Recognize multiple people at once!

> @bob and @alice crushed that showcase! ${recognizeEmoji}

Use \`#tags\` to call out specific Liatrio values!

> I love the #energy in your Terraform demo @alice! ${recognizeEmoji}

The more emojis you add, the more recognition they get!

> @alice just pushed the cleanest code I've ever seen! ${recognizeEmoji} ${recognizeEmoji} ${recognizeEmoji}

Use multipliers to give more recognition!

> @alice presented an amazing demo at a conference! ${recognizeEmoji} x2

or

> @alice presented an amazing demo at a conference! x2 ${recognizeEmoji}

If someone else has given a ${recognizeEmoji} to someone, and you'd like to \
give one of your own for the same reason, you can react to the message with \
a ${reactionEmoji}. Gratibot will record your shout-out as though you sent \
the same message that you reacted to.

*Redeeming*


Send me a direct message with 'redeem' and I'll give you the options for prizes to redeem! Once you've selcted an item then I'll start a MPIM with the redemption admins to promote the dialog to acknowledge and receive your item.

Refunds can be given via the 'refund' command if the item redeem can't be fulfilled for whatever reason. Only redemption admins can give refunds. Deduction ID is sent as part of the MPIM when an item is redeemed

> @gratibot refund DEDUCTIONID


*View Balance*

Send me a direct message with 'balance' and I'll let you know how many \
recognitions you have left to give and how many you have received.

> You have received 0 ${recognizeEmoji} and you have ${maximum} ${recognizeEmoji} remaining to \
give away today




*View Leaderboard*

Send me a direct message with 'leaderboard' and I'll show you who is giving \
and receiving the most recognition. I'll also show who currently holds the :goldenfistbump:!




*View Metrics*

Send me a direct message with 'metrics' and I'll show you how many times \
people have given recognitions over the last month.


*Give Golden Recognition*

The golden fistbump ${goldenRecognizeEmoji} is a special recognition that can only be held by one user at a time. Only the current holder of the golden recognition can give the golden recognition.

Giving a golden fistbump is the same as giving a normal fistbump

> Thanks @alice for helping fix the prod issues! ${goldenRecognizeEmoji}

Upon receiving the golden fistbump, the user will receive 20 fistbumps and will have a 2X multiplier applied to all incoming fistbumps while the golden fistbump is held.
`;
61 changes: 61 additions & 0 deletions features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const config = require("./config");
const balance = require("./service/balance");
const deduction = require("./service/deduction");
const help = require("./service/help");
const join = require("./service/join");
const leaderboard = require("./service/leaderboard");
const metrics = require("./service/metrics");
const recognition = require("./service/recognition");
const redeem = require("./service/redeem");
const {
respondToGoldenRecognitionMessage,
} = require("./service/golden-recognition");
const { directMention } = require("@slack/bolt");
const { directMessage, anyOf, reactionMatches } = require("./middleware");

const { goldenRecognizeEmoji, reactionEmoji, recognizeEmoji } = config;

function appMessage(app, message, ...func) {
app.message(message, anyOf(directMention(), directMessage()), ...func);
}

module.exports = function (app) {
// Balance
appMessage(app, "balance", balance.respondToBalance);

// Deduction
appMessage(app, "deduct", deduction.respondToDeduction);

// Golden Recognition
app.message(goldenRecognizeEmoji, respondToGoldenRecognitionMessage);

// Help
appMessage(app, "help", help.respondToHelp);
app.message(/(thunderfury|Thunderfury)/, help.respondToEasterEgg);

// Auto Join
app.event("channel_created", join.joinPublicChannel);

// Leaderboard
appMessage(app, "leaderboard", leaderboard.respondToLeaderboard);
app.action(/leaderboard-\d+/, leaderboard.updateLeaderboardResponse);

// Metrics
appMessage(app, "metrics", metrics.respondToMetrics);
app.action(/metrics-\d+/, metrics.updateMetricsResponse);

// Recognition
app.message(recognizeEmoji, recognition.respondToRecognitionMessage);
app.event(
"reaction_added",
reactionMatches(reactionEmoji),
recognition.respondToRecognitionReaction
);

// Redeem
appMessage(app, "redeem", redeem.respondToRedeem);
app.action({ action_id: "redeem" }, redeem.redeemItem);

// Refund
appMessage(app, "refund", deduction.respondToRefund);
};
62 changes: 0 additions & 62 deletions features/balance.js

This file was deleted.

86 changes: 0 additions & 86 deletions features/deduction.js

This file was deleted.

Loading
Loading