-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: @gratibot deduct command, liatrio store reward, and removed old…
… account from redemptionAdmins (#442) * feat: adding @gratibot deduct command * fix: linting issues in features/deduction.js * fix: linting issues in features/deduction.js * fix: linting issues in features/deduction.js * fix: removed deactivated account from redemptionAdmins * feat: adding liatrio store as a redeemable reward * Update config.js added usernames to user IDs * Update app.js added a simple response if users use the wrong command * fix: linting fixed in app.js --------- Co-authored-by: Densell Peters III <[email protected]>
- Loading branch information
Showing
6 changed files
with
147 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const deduction = require("../service/deduction"); | ||
const winston = require("../winston"); | ||
const { redemptionAdmins } = require("../config"); | ||
const { userRegex } = require("../regex"); | ||
const { directMention } = require("@slack/bolt"); | ||
const { directMessage, anyOf } = require("../middleware"); | ||
|
||
module.exports = function (app) { | ||
app.message( | ||
"deduct", | ||
anyOf(directMention(), directMessage()), | ||
respondToDeduction | ||
); | ||
}; | ||
|
||
async function respondToDeduction({ message, client }) { | ||
winston.info("@gratibot deduction Called", { | ||
func: "feature.deduction.respondToDeduction", | ||
callingUser: message.user, | ||
slackMessage: message.text, | ||
}); | ||
|
||
const userInfo = await client.users.info({ user: message.user }); | ||
if (!userInfo.ok) { | ||
winston.error("Slack API returned error from users.info", { | ||
func: "feature.deduction.respondToDeduction", | ||
callingUser: message.user, | ||
slackMessage: message.text, | ||
error: userInfo.error, | ||
}); | ||
await client.chat.postEphemeral({ | ||
channel: message.channel, | ||
user: message.user, | ||
text: `Something went wrong while creating your deduction. When retreiving user information from Slack, the API responded with the following error: ${userInfo.error}`, | ||
}); | ||
return; | ||
} | ||
|
||
if (!redemptionAdmins.includes(message.user)) { | ||
await client.chat.postEphemeral({ | ||
channel: message.channel, | ||
user: message.user, | ||
text: `You are not allowed to create deductions.`, | ||
}); | ||
return; | ||
} | ||
|
||
const messageText = message.text.split(" "); | ||
|
||
if ( | ||
messageText.length < 4 || | ||
!userRegex.test(messageText[2]) || | ||
isNaN(+messageText[3]) | ||
) { | ||
await client.chat.postEphemeral({ | ||
channel: message.channel, | ||
user: message.user, | ||
text: `You must specify a user and value to deduct. Example: \`@gratibot deduct @user 5\``, | ||
}); | ||
return; | ||
} | ||
|
||
const user = messageText[2].match(userRegex)[1]; | ||
const value = +messageText[3]; | ||
|
||
if (!(await deduction.isBalanceSufficent(user, value))) { | ||
await client.chat.postEphemeral({ | ||
channel: message.channel, | ||
user: message.user, | ||
text: `<@${user}> does not have a large enough balance to deduct ${value} fistbumps.`, | ||
}); | ||
return; | ||
} | ||
|
||
await deduction.createDeduction(user, value, message.text); | ||
const deductionInfo = await deduction.createDeduction( | ||
user, | ||
value, | ||
message.text | ||
); | ||
|
||
await client.chat.postMessage({ | ||
channel: message.channel, | ||
user: message.user, | ||
text: `A deduction of ${value} fistbumps has been made for <@${user}>. Deduction ID is \`${deductionInfo._id}\``, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var regex = {}; | ||
|
||
regex.userRegex = /<@([^>]+)>/; | ||
regex.deductRegex = /<@([^|>]+)\|/; // For Slash command | ||
regex.groupRegex = /<!subteam\^([a-zA-Z0-9]+)\|@([a-zA-Z0-9]+)>/g; | ||
regex.tagRegex = /#(\S+)/g; | ||
regex.generalEmojiRegex = /:([a-z-_']+):/g; | ||
|
||
module.exports = regex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters