diff --git a/service/apiwrappers.js b/service/apiwrappers.js index 94dbc308..6299d3a8 100644 --- a/service/apiwrappers.js +++ b/service/apiwrappers.js @@ -1,5 +1,4 @@ const { SlackError } = require("./errors"); -const winston = require("../winston"); async function userInfo(client, userId) { const response = await client.users.info({ user: userId }); @@ -14,42 +13,6 @@ async function userInfo(client, userId) { ); } -function winstonInfo(info, func, message) { - if (message.user.id) { - message.user = message.user.id; - } - winston.info(info, { - func: func, - callingUser: message.user, - slackMessage: message.text, - reactionEmoji: message.reaction, - }); -} - -function winstonDebug(info, func, message) { - if (message.reactions) { - message.text = message.reactions; - } - winston.debug(info, { - func: func, - callingUser: message.user, - slackMessage: message.text, - reactionEmoji: message.reaction, - }); -} - -function winstonError(info, func, message, userInfo) { - winston.error(info, { - func: func, - callingUser: message.user, - slackMessage: message.text, - error: userInfo.error, - }); -} - module.exports = { userInfo, - winstonInfo, - winstonDebug, - winstonError, }; diff --git a/service/balance.js b/service/balance.js index c2094ce7..8ec2beb1 100644 --- a/service/balance.js +++ b/service/balance.js @@ -1,7 +1,6 @@ const config = require("../config"); const winston = require("../winston"); const moment = require("moment-timezone"); -const { winstonInfo, winstonError } = require("./apiwrappers"); const recognitionCollection = require("../database/recognitionCollection"); const goldenRecognitionCollection = require("../database/goldenRecognitionCollection"); @@ -63,20 +62,20 @@ async function dailyGratitudeRemaining(user, timezone) { } async function respondToBalance({ message, client }) { - winstonInfo( - "@gratibot balance Called", - "service.balance.respondToBalance", - message - ); + winston.info("@gratibot balance Called", { + func: "service.balance.respondToBalance", + callingUser: message.user, + slackMessage: message.text, + }); const userInfo = await client.users.info({ user: message.user }); if (!userInfo.ok) { - winstonError( - "Slack API returned error from users.info", - "service.balance.respondToBalance", - message, - userInfo - ); + winston.error("Slack API returned error from users.info", { + func: "service.balance.respondToBalance", + callingUser: message.user, + slackMessage: message.text, + error: userInfo.error, + }); await client.chat.postEphemeral({ channel: message.channel, user: message.user, diff --git a/service/deduction.js b/service/deduction.js index 6520219a..568ffbae 100644 --- a/service/deduction.js +++ b/service/deduction.js @@ -5,7 +5,6 @@ const deductionCollection = require("../database/deductionCollection"); const { userRegex } = require("../regex"); const { redemptionAdmins } = require("../config"); const monk = require("monk"); -const { winstonInfo, winstonError } = require("./apiwrappers"); async function createDeduction(user, value, message = "") { let timestamp = new Date(); @@ -59,11 +58,10 @@ async function isBalanceSufficent(user, deductionValue) { } async function respondToRefund({ message, client, admins = redemptionAdmins }) { - winstonInfo( - "@gratibot refund Called", - "service.deduction.respondToRefund", - message - ); + winston.info("@gratibot refund Called", { + callingUser: message.user, + slackMessage: message.text, + }); if (!admins.includes(message.user)) { await sendMessage( @@ -105,20 +103,20 @@ async function respondToRefund({ message, client, admins = redemptionAdmins }) { } async function respondToDeduction({ message, client }) { - winstonInfo( - "@gratibot deduction Called", - "service.deduction.respondToDeduction", - message - ); + winston.info("@gratibot deduction Called", { + func: "service.deduction.respondToDeduction", + callingUser: message.user, + slackMessage: message.text, + }); const userInfo = await client.users.info({ user: message.user }); if (!userInfo.ok) { - winstonError( - "Slack API returned error from users.info", - "service.deduction.respondToDeduction", - message, - userInfo - ); + winston.error("Slack API returned error from users.info", { + func: "service.deduction.respondToDeduction", + callingUser: message.user, + slackMessage: message.text, + error: userInfo.error, + }); await sendEphemeralMessage( client, message.channel, diff --git a/service/golden-recognition.js b/service/golden-recognition.js index 6bbf9535..1bdc872a 100644 --- a/service/golden-recognition.js +++ b/service/golden-recognition.js @@ -1,6 +1,7 @@ +const winston = require("../winston"); const config = require("../config"); const goldenRecognitionCollection = require("../database/goldenRecognitionCollection"); -const { userInfo, winstonInfo } = require("./apiwrappers"); +const { userInfo } = require("./apiwrappers"); const { handleAllErrors, sendNotificationToReceivers, @@ -49,11 +50,11 @@ async function giverGoldenSlackNotification(gratitude) { } async function respondToGoldenRecognitionMessage({ message, client }) { - winstonInfo( - `Heard reference to ${goldenRecognizeEmoji}`, - "service.recognition.respondToGoldenRecognitionMessage", - message - ); + winston.info(`Heard reference to ${goldenRecognizeEmoji}`, { + func: "service.recognition.respondToGoldenRecognitionMessage", + callingUser: message.user, + slackMessage: message.text, + }); let allUsers = []; let gratitude; try { diff --git a/service/help.js b/service/help.js index b85570b3..bbd4a749 100644 --- a/service/help.js +++ b/service/help.js @@ -5,7 +5,6 @@ const { goldenRecognizeEmoji, } = require("../config"); const winston = require("../winston"); -const { winstonInfo } = require("./apiwrappers"); const helpMarkdown = ` :wave: Hi there! Let's take a look at what I can do! @@ -95,8 +94,11 @@ Upon receiving the golden fistbump, the user will receive 20 fistbumps and will `; async function respondToHelp({ message, client }) { - winstonInfo("@gratibot help Called", "feature.help.respondToHelp", message); - + winston.info(`@gratibot help Called`, { + func: "feature.help.respondToHelp", + callingUser: message.user, + slackMessage: message.text, + }); await client.chat.postEphemeral({ channel: message.channel, user: message.user, @@ -118,11 +120,11 @@ const thunderfuryResponse = [ ].join(" "); async function respondToEasterEgg({ message, say }) { - winstonInfo( - "heard reference to thunderfury", - "feature.help.respondToEasterEgg", - message - ); + winston.info(`Heard reference to thunderfury`, { + func: "feature.help.respondToEasterEgg", + callingUser: message.user, + slackMessage: message.text, + }); await say(thunderfuryResponse); diff --git a/service/leaderboard.js b/service/leaderboard.js index d6c80cfb..d40ef3da 100644 --- a/service/leaderboard.js +++ b/service/leaderboard.js @@ -1,7 +1,6 @@ const winston = require("../winston"); const recognition = require("./recognition"); const { goldenFistbumpHolder } = require("./golden-recognition"); -const { winstonInfo } = require("./apiwrappers"); const rank = [ "1st", @@ -276,11 +275,11 @@ function convertToScores(leaderboardData) { * this call. */ async function respondToLeaderboard({ message, client }) { - winstonInfo( - "@gratibot leaderboard Called", - "service.leaderboard.respondToLeaderboard", - message - ); + winston.info("@gratibot leaderboard Called", { + func: "service.leaderboard.respondToLeaderboard", + callingUser: message.user, + slackMessage: message.text, + }); await client.chat.postEphemeral({ channel: message.channel, user: message.user, @@ -302,11 +301,10 @@ async function respondToLeaderboard({ message, client }) { */ async function updateLeaderboardResponse({ ack, body, action, respond }) { await ack(); - winstonInfo( - "Gratibot interactive leaderboard button clicked", - "service.leaderboard.updateLeaderboardResponse", - body - ); + winston.info("Gratibot interactive leaderboard button clicked", { + func: "service.leaderboard.updateLeaderboardResponse", + callingUser: body.user.id, + }); await respond({ blocks: await createLeaderboardBlocks(action.value), diff --git a/service/metrics.js b/service/metrics.js index 8a4f3001..d9ba54c8 100644 --- a/service/metrics.js +++ b/service/metrics.js @@ -2,7 +2,6 @@ const winston = require("../winston"); const moment = require("moment-timezone"); const recognition = require("./recognition"); -const { winstonInfo } = require("./apiwrappers"); async function createMetricsBlocks(timeRange) { let blocks = []; @@ -182,11 +181,11 @@ function aggregateData(response, timeRange) { } async function respondToMetrics({ message, client }) { - winstonInfo( - "@gratibot metrics Called", - "service.metrics.respondToMetrics", - message - ); + winston.info("@gratibot metrics Called", { + func: "service.metrics.respondToMetrics", + callingUser: message.user, + slackMessage: message.text, + }); await client.chat.postEphemeral({ channel: message.channel, user: message.user, @@ -202,11 +201,10 @@ async function respondToMetrics({ message, client }) { async function updateMetricsResponse({ ack, body, action, respond }) { await ack(); - winstonInfo( - "Gratibot interactive metrics button clicked", - "service.metrics.updateMetricsResponse", - body - ); + winston.info("Gratibot interactive metrics button clicked", { + func: "service.metrics.updateMetricsResponse", + callingUser: body.user.id, + }); await respond({ blocks: await createMetricsBlocks(action.value), diff --git a/service/recognition.js b/service/recognition.js index 88df3ba8..44832433 100644 --- a/service/recognition.js +++ b/service/recognition.js @@ -5,7 +5,7 @@ const goldenRecognitionCollection = require("../database/goldenRecognitionCollec const balance = require("./balance"); const { SlackError, GratitudeError } = require("./errors"); const winston = require("../winston"); -const { userInfo, winstonInfo, winstonDebug } = require("./apiwrappers"); +const { userInfo } = require("./apiwrappers"); const { handleAllErrors, sendNotificationToReceivers, @@ -330,18 +330,21 @@ async function giverSlackNotification(gratitude) { } async function respondToRecognitionMessage({ message, client }) { - winstonInfo( - `Heard reference to ${recognizeEmoji}`, - "service.recognition.respondToRecognitionMessage", - message - ); + winston.info(`Heard reference to ${recognizeEmoji}`, { + func: "service.recognition.respondToRecognitionMessage", + callingUser: message.user, + slackMessage: message.text, + }); try { const gratitude = await buildGratitudeObject({ message, client }); await validateAndSendGratitude(gratitude); - winstonDebug( + winston.debug( `validated and stored message recognitions from ${gratitude.giver}`, - "service.recognition.respondToRecognitionMessage", - message + { + func: "service.recognition.respondToRecognitionMessage", + callingUser: message.user, + slackMessage: message.text, + } ); return Promise.all([ @@ -355,11 +358,11 @@ async function respondToRecognitionMessage({ message, client }) { } async function respondToRecognitionReaction({ event, client }) { - winstonInfo( - `Saw a reaction containing ${reactionEmoji}`, - "service.recognition.respondToRecognitionReaction", - event - ); + winston.info(`Saw a reaction containing ${reactionEmoji}`, { + func: "service.recognition.respondToRecognitionReaction", + callingUser: event.user, + reactionEmoji: event.reaction, + }); try { event.channel = event.item.channel; const { gratitude, originalMessage } = await buildGratitudeFromReaction({ @@ -372,10 +375,13 @@ async function respondToRecognitionReaction({ event, client }) { } await validateAndSendGratitude(gratitude); - winstonDebug( - `validated and stored message recognitions from ${gratitude.giver}`, - "service.recognition.respondToRecognitionReaction", - event + winston.debug( + `validated and stored reaction recognitions from ${gratitude.giver}`, + { + func: "service.recognition.respondToRecognitionReaction", + callingUser: event.user, + slackMessage: event.reactions, + } ); return Promise.all([ diff --git a/service/redeem.js b/service/redeem.js index c7090350..c3cfe2dd 100644 --- a/service/redeem.js +++ b/service/redeem.js @@ -1,11 +1,10 @@ const config = require("../config"); const fs = require("fs"); +const winston = require("../winston"); const balance = require("./balance"); const deduction = require("./deduction"); -const { winstonInfo } = require("./apiwrappers"); - const path = require("path"); // TODO: Long term this should be sourced from DB let rawdata = fs.readFileSync(path.resolve(__dirname, "../rewards.json")); @@ -132,12 +131,10 @@ function getSelectedItemDetails(selectedItem) { } async function respondToRedeem({ message, client }) { - winstonInfo( - "@gratibot redeem Called", - "service.redeem.respondToRedeem", - message - ); - + winston.info("@gratibot redeem Called", { + callingUser: message.user, + slackMessage: message.text, + }); const currentBalance = await balance.currentBalance(message.user); await client.chat.postEphemeral({ channel: message.channel,