Skip to content

Commit

Permalink
Merge pull request #20 from rpiambulance/dev
Browse files Browse the repository at this point in the history
Fix #18
  • Loading branch information
justetz committed Oct 6, 2019
2 parents 8af30c4 + b8aadde commit 01787cf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
16 changes: 14 additions & 2 deletions handlers/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const approveMessage = (
adminMessageTs,
approver
) => {
postToChannel(channel_id, text, user_id);
postToChannel(channel_id, text, user_id, true);
updateModMessage(
"approved",
channel_id,
Expand All @@ -30,6 +30,18 @@ const approveMessage = (
);
};

const approveNoAt = (channel_id, text, user_id, adminMessageTs, approver) => {
postToChannel(channel_id, text, user_id, false);
updateModMessage(
"approved without at-channel",
channel_id,
text,
user_id,
adminMessageTs,
approver
);
};

const rejectMessage = (channel_id, text, user_id, adminMessageTs, rejector) => {
updateModMessage(
"rejected",
Expand All @@ -52,4 +64,4 @@ const cancelRequest = (channel_id, user_id, ts) => {
});
};

module.exports = { approveMessage, rejectMessage, cancelRequest };
module.exports = { approveMessage, approveNoAt, rejectMessage, cancelRequest };
13 changes: 11 additions & 2 deletions handlers/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ const sendForApproval = async (text, channel_id, user_id, hash) => {
style: "primary",
action_id: `APP_${hash}`
},
{
type: "button",
text: {
type: "plain_text",
text: "Approve without @channel"
},
action_id: `NOAT_${hash}`
},
{
type: "button",
text: {
Expand All @@ -72,7 +80,8 @@ const sendForApproval = async (text, channel_id, user_id, hash) => {
return ts;
};

const postToChannel = (channel_id, text, user_id) => {
const postToChannel = (channel_id, text, user_id, atChannel) => {
const atChannelText = atChannel ? "<!channel>" : "the channel";
postMessage({
token: TOKEN,
channel: channel_id,
Expand All @@ -82,7 +91,7 @@ const postToChannel = (channel_id, text, user_id) => {
type: "section",
text: {
type: "mrkdwn",
text: `<@${user_id}> has sent the following message to <!channel>:\n\n${text}`
text: `<@${user_id}> has sent the following message to ${atChannelText}:\n\n${text}`
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "at-channel",
"version": "0.9.0",
"version": "1.1.0",
"description": "Allows the approval of @channel requests in a slack workspace",
"main": "server.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { isModerator } = require("./utilities/helperFunctions.js");
const { slashChannel } = require("./handlers/slashCommands.js");
const {
approveMessage,
approveNoAt,
rejectMessage,
cancelRequest
} = require("./handlers/buttons.js");
Expand All @@ -21,7 +22,8 @@ app.command(
);

app.action(
/^(APP|REJ)_.*/,
//APP = approved; NOAT = approved without @channel; REJ = reject
/^(APP|NOAT|REJ)_.*/,
async ({ ack, next }) => {
ack();
next();
Expand All @@ -45,6 +47,8 @@ app.action(
.replace(">", "");
if (/^APP_.*/.test(action_id)) {
approveMessage(channel_id, text, user_id, ts, id);
} else if (/^NOAT_.*/.test(action_id)) {
approveNoAt(channel_id, text, user_id, ts, id);
} else if (/^REJ_.*/.test(action_id)) {
rejectMessage(channel_id, text, user_id, ts, id);
}
Expand Down
13 changes: 9 additions & 4 deletions utilities/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ const updateModMessage = (status, channel_id, text, user_id, ts, moderator) => {
});
return;
}

const emoji = status == "approved" ? ":heavy_check_mark:" : ":x:";

const emoji =
status == "approved"
? ":heavy_check_mark:"
: status == "approved without at-channel"
? ":heavy_minus_sign:"
: ":x:";
update({
token: TOKEN,
channel: MOD_CHANNEL_ID,
Expand Down Expand Up @@ -107,9 +112,9 @@ const updateModMessage = (status, channel_id, text, user_id, ts, moderator) => {
});
};

const randomEmoji = (sentiment) => {
const randomEmoji = sentiment => {
let emojis = [];
switch(sentiment){
switch (sentiment) {
case "happy":
emojis = emojisList.happy;
break;
Expand Down

0 comments on commit 01787cf

Please sign in to comment.