diff --git a/config.js b/config.js index a39fa25d..186530fa 100644 --- a/config.js +++ b/config.js @@ -6,13 +6,14 @@ config.mongo_url = process.env.MONGO_URL || "mongodb://mongodb:27017/gratibot"; config.logLevel = process.env.LOG_LEVEL || "info"; config.recognizeEmoji = - _.escapeRegExp(process.env.RECOGNIZE_EMOJI) || ":fistbump:"; + _.escapeRegExp(process.env.RECOGNIZE_EMOJI) || ":toot:"; config.goldenRecognizeEmoji = process.env.GOLDEN_RECOGNIZE_EMOJI || ":goldenfistbump:"; config.goldenRecognizeChannel = process.env.GOLDEN_RECOGNIZE_CHANNEL || "liatrio"; -config.reactionEmoji = process.env.REACTION_EMOJI || ":nail_care:"; +config.reactionEmoji = process.env.REACTION_EMOJI || ":toot:"; config.maximum = process.env.GRATIBOT_LIMIT || 5; +config.firstFridayMaximum = process.env.GRATIBOT_FIRST_FRIDAY_LIMIT || 10; config.minimumMessageLength = 20; config.botName = process.env.BOT_NAME || "gratibot"; config.slashCommand = process.env.SLASH_COMMAND || "/gratibot"; @@ -23,7 +24,6 @@ config.usersExemptFromMaximum = process.env.EXEMPT_USERS?.split(",") || [ "U04KTAJRS5T", // Mike Denton "U0K32MUSF", // Robert Kelly "U05HA77CE5S", //Ryan McClish - "U071G57GRMW", //Rich Montbriand ]; config.initialGoldenRecognitionHolder = @@ -32,4 +32,15 @@ config.redemptionAdmins = process.env.REDEMPTION_ADMINS?.split(",") || [ "U04666K57CP", // Danielle Johnson ]; +config.firstFridayAdmins = process.env.FIRST_FRIDAY_ADMINS?.split(",") || [ + "U037FL37G", // Chris Blackburn + "U8T585Y8J", // Jeremy Hayes + "U04KTAJRS5T", // Mike Denton + "U0K32MUSF", // Robert Kelly + "U05HA77CE5S", //Ryan McClish + "U054SKX2V4L", // Leo Pineiro +]; + +config.firstFridayEnabled = false; + module.exports = config; diff --git a/features/first-friday.js b/features/first-friday.js new file mode 100644 index 00000000..2b7b818c --- /dev/null +++ b/features/first-friday.js @@ -0,0 +1,36 @@ +const winston = require("../winston"); +const config = require("../config"); +const { directMention } = require("@slack/bolt"); +const { directMessage, anyOf } = require("../middleware"); + +async function respondToFirstFriday({ message, client }) { + winston.info("@gratibot liatrio love Called", { + callingUser: message.user, + slackMessage: message.text, + }); + + if (!config.firstFridayAdmins.includes(message.user)) { + await client.chat.postEphemeral({ + channel: message.channel, + user: message.user, + text: "Only authorized admins can toggle First Friday mode", + }); + return; + } + + config.firstFridayEnabled = !config.firstFridayEnabled; + const status = config.firstFridayEnabled ? "enabled" : "disabled"; + + await client.chat.postMessage({ + channel: message.channel, + text: `First Friday mode has been ${status}`, + }); +} + +module.exports = function (app) { + app.message( + "liatrio love", + anyOf(directMention, directMessage()), + respondToFirstFriday, + ); +}; diff --git a/service/balance.js b/service/balance.js index f572019f..3b2e91bf 100644 --- a/service/balance.js +++ b/service/balance.js @@ -34,14 +34,14 @@ async function lifetimeSpendings(user) { } async function dailyGratitudeRemaining(user, timezone) { - if (config.usersExemptFromMaximum.includes(user)) { - winston.debug("current user is exempt from limits!", { - func: "service.balance.dailyGratitudeRemaining", - callingUser: user, - }); - return Infinity; - } - const midnight = moment(Date.now()).tz(timezone).startOf("day"); + const userDate = moment(Date.now()).tz(timezone); + const midnight = userDate.startOf("day"); + + // Check if it's either manually enabled or it's the first Friday + const isFirstFriday = config.firstFridayEnabled || + (userDate.day() === 5 && // Friday is 5 in moment.js + userDate.date() <= 7); // First week of the month + const recognitionGivenToday = await recognitionCollection.count({ recognizer: user, timestamp: { @@ -49,16 +49,20 @@ async function dailyGratitudeRemaining(user, timezone) { }, }); + const dailyLimit = isFirstFriday ? config.firstFridayMaximum : config.maximum; + winston.debug( - `${user} has [${config.maximum - recognitionGivenToday}] recognitions left`, + `${user} has [${dailyLimit - recognitionGivenToday}] recognitions left`, { func: "service.balance.dailyGratitudeRemaining", callingUser: user, timezone: timezone, + isFirstFriday: isFirstFriday, + firstFridayEnabled: config.firstFridayEnabled, }, ); - return config.maximum - recognitionGivenToday; + return dailyLimit - recognitionGivenToday; } module.exports = { diff --git a/slack_app_manifest.yml b/slack_app_manifest.yml index 80083da9..003057e7 100644 --- a/slack_app_manifest.yml +++ b/slack_app_manifest.yml @@ -1,49 +1,63 @@ -_metadata: - major_version: 1 - minor_version: 1 -display_information: - name: ${botName} - description: Recognize your peers for their awesome work! - background_color: "#458562" -features: - app_home: - home_tab_enabled: false - messages_tab_enabled: true - messages_tab_read_only_enabled: false - bot_user: - display_name: ${botName} - always_online: true -oauth_config: - scopes: - bot: - - app_mentions:read - - channels:history - - channels:read - - channels:join - - chat:write - - groups:history - - groups:read - - im:history - - im:read - - im:write - - mpim:history - - mpim:read - - mpim:write - - reactions:read - - reactions:write - - usergroups:read - - users:read -settings: - event_subscriptions: - bot_events: - - app_mention - - channel_created - - message.channels - - message.groups - - message.im - - message.mpim - - reaction_added - interactivity: - is_enabled: true - org_deploy_enabled: false - socket_mode_enabled: true +{ + "_metadata": { + "major_version": 1, + "minor_version": 1 + }, + "display_information": { + "name": "gratibot", + "description": "Recognize your peers for their awesome work!", + "background_color": "#458562" + }, + "features": { + "app_home": { + "home_tab_enabled": false, + "messages_tab_enabled": true, + "messages_tab_read_only_enabled": false + }, + "bot_user": { + "display_name": "gratibot", + "always_online": true + } + }, + "oauth_config": { + "scopes": { + "bot": [ + "app_mentions:read", + "channels:history", + "channels:read", + "channels:join", + "chat:write", + "groups:history", + "groups:read", + "im:history", + "im:read", + "im:write", + "mpim:history", + "mpim:read", + "mpim:write", + "reactions:read", + "reactions:write", + "usergroups:read", + "users:read" + ] + } + }, + "settings": { + "event_subscriptions": { + "bot_events": [ + "app_mention", + "channel_created", + "message.channels", + "message.groups", + "message.im", + "message.mpim", + "reaction_added" + ] + }, + "interactivity": { + "is_enabled": true + }, + "org_deploy_enabled": false, + "socket_mode_enabled": true + } +}