Skip to content

Commit

Permalink
disallow mods from approving their own requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddbruce committed May 5, 2019
1 parent 73c7f54 commit 3946ac7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions utilities/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const MOD_USERGROUP_ID = process.env.MOD_USERGROUP_ID;
const isModerator = async ({
body: {
user: { id },
channel: { id: channelId }
channel: { id: channelId },
message: { blocks }
},
next
}) => {
Expand All @@ -33,7 +34,20 @@ const isModerator = async ({
token: USER_TOKEN,
usergroup: MOD_USERGROUP_ID
});
if (modUsers.includes(id)) return next();
const original_poster = /<@(.*?)[a-zA-Z0-9]{7,10}>/
.exec(blocks[0].text.text)[0]
.replace("<@", "")
.replace(">", "");
if (modUsers.includes(id) && id != original_poster) return next();
if (id == original_poster) {
return postEphemeral({
token: TOKEN,
channel: channelId,
user: id,
text:
":cry: Sorry! Moderators cannot approve or reject their own requests."
});
}
return postEphemeral({
token: TOKEN,
channel: channelId,
Expand Down

0 comments on commit 3946ac7

Please sign in to comment.