Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebrown201 committed Apr 15, 2020
1 parent 82d464d commit 69281a7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You can change the status throughout the day by reacting with the appropriate em

# Adding this to your channel

Invite the app to your public or private channel.
Invite the app to your public or private channel. For a private channel you will have to manually type out the channel name as auto complete will not be available e.g #<private channel name>

```
/invite @channel_status_notifi
Expand Down
6 changes: 6 additions & 0 deletions data/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
MESSAGE: {
ending:
"\n _You can change your status throughout the day by adding and removing the relevent emoji as a reaction to this message. This does not update your status you will have to do that manually as well._"
}
};
12 changes: 6 additions & 6 deletions data/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ module.exports = {
emoji: [":ill:", ":face_with_head_bandage:", ":face_with_thermometer:"],
defaultEmoji: "ill",
type: "ill",
message: ":ill: *Off sick:* \n"
message: ":ill: *Off sick:*"
},
{
keywords: ["ooo", "office", "out", "busy", "conference", "training"],
emoji: [":no_entry_sign:"],
defaultEmoji: "no_entry_sign",
type: "ooo",
message: ":no_entry_sign: *Out of office:* \n"
message: ":no_entry_sign: *Out of office:*"
},
{
keywords: ["home", "wfh", "working", "work"],
emoji: [":house:", ":house_with_garden:", ":computer:", ":wfh:"],
defaultEmoji: "house",
type: "wfh",
message: ":house_with_garden: *WFH:* \n"
message: ":house_with_garden: *WFH:*"
},
{
keywords: ["birthday", "cake", ":cake:"],
emoji: [":birthday:", ":cake:", ":cupcake:"],
defaultEmoji: "birthday",
type: "cake",
message: "`:cake: *Birthday:* \n"
message: ":cake: *Birthday:*"
},
{
keywords: ["mat", "maternity", "pat", "paternity", "parental"],
emoji: [":baby:", ":baby_bottle:", ":pregnant_woman:"],
defaultEmoji: "baby",
type: "parent",
message: ":baby: *On parental leave:* \n"
message: ":baby: *On parental leave:*"
},
{
keywords: [
Expand All @@ -52,7 +52,7 @@ module.exports = {
emoji: [":palm_tree:", ":airplane:", ":desert_island", ":sunny:"],
defaultEmoji: "palm_tree",
type: "holiday",
message: ":palm_tree: *On holiday:* \n"
message: ":palm_tree: *On holiday:*"
},
{
keywords: [
Expand Down
16 changes: 5 additions & 11 deletions emojiReact.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ const { WebClient, ErrorCode } = require("@slack/web-api");
const web = new WebClient(process.env.SLACK_TOKEN);

const { AWAY_TYPES } = require("./data/types.js");
const { MESSAGE } = require("./data/message.js");

exports.emojiReact = async function(event, context) {
try {
console.log("triggered");
const { item, reaction, user, eventType } = JSON.parse(
event.Records[0].Sns.Message
);
const { type, message, defaultEmoji } = getReactionType(reaction);

console.log("type", type);
console.log("reaction", reaction);
console.log("defaultEmoji", defaultEmoji);
console.log("item", item);

if (!type) {
return;
}
Expand All @@ -33,12 +28,9 @@ exports.emojiReact = async function(event, context) {
if (eventType === "reaction_removed") {
const splitViaStatus = messageDetails.text.split(message);
const firstPart = splitViaStatus;
console.log(firstPart);
let lastPart = splitViaStatus[1].split("\n");
const originalNames = lastPart[1];
console.log("originalNames", originalNames);
if (!originalNames.includes(name)) {
console.log("ORIGINAL NAMEEEEEEEE");
return;
}
formattedMessage = removeName({ name, text: messageDetails.text });
Expand Down Expand Up @@ -101,7 +93,10 @@ function addName({ text, name, message, type }) {
let finalMessage;

if (!text.includes(message)) {
finalMessage = text += `${message} \n ${name} \n\n`;
console.log("on herererere");
const textSplit = text.split(MESSAGE.ending);
console.log("textSplit", textSplit);
finalMessage = textSplit[0] += `\n ${message} \n ${name} \n ${MESSAGE.ending}`;
} else {
finalMessage = addNameToMessage({ text, name, message });
}
Expand All @@ -111,7 +106,6 @@ function addName({ text, name, message, type }) {
function addNameToMessage({ text, name, message }) {
const splitViaStatus = text.split(message);
const firstPart = splitViaStatus[0];
console.log(firstPart);
let lastPart = splitViaStatus[1].split("\n");
const originalNames = lastPart[1];
let newNames;
Expand Down
14 changes: 7 additions & 7 deletions post.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
if (process.env.NODE_ENV !== "production") require("dotenv").config();
const { WebClient, ErrorCode } = require("@slack/web-api");
const { AWAY_TYPES } = require("./data/types.js");
const { MESSAGE } = require("./data/message.js");

const web = new WebClient(process.env.SLACK_TOKEN);

Expand Down Expand Up @@ -82,8 +84,6 @@ async function getStatuses(members) {
return results;
}

const { AWAY_TYPES } = require("./data/types.js");

function checkStatus(profile) {
let status = "";

Expand Down Expand Up @@ -151,19 +151,19 @@ function prepMessage(statuses) {
});
});

message +=
"\n _You can change your status throughout the day by adding and removing the relevent emoji as a reaction to this message._";

message += MESSAGE.ending;
return message;
}

function addStatus({ statuses, statusType }) {
message = "";
message += AWAY_TYPES.find(typeObj => typeObj.type === statusType).message;
if (statuses.length > 0) {
message += `${
AWAY_TYPES.find(typeObj => typeObj.type === statusType).message
}\n`;
message += `${statuses.join(", ")}`;
message += `\n\n`;
}
message += `\n\n`;

return message;
}
Expand Down

0 comments on commit 69281a7

Please sign in to comment.