Remove whitelist + make changes to work with Identity Vault
This commit is contained in:
parent
0cbd345b5b
commit
702e3e966e
1 changed files with 27 additions and 43 deletions
70
index.ts
70
index.ts
|
@ -8,20 +8,6 @@ const app = new App({
|
|||
signingSecret: process.env.SLACK_SIGNING_SECRET,
|
||||
});
|
||||
|
||||
const whitelist: string[] = (() => {
|
||||
try {
|
||||
return require('./whitelist.json')
|
||||
} catch (e) {
|
||||
return []
|
||||
}
|
||||
})();
|
||||
|
||||
function checkUserOk(user: UsersInfoResponse['user']) {
|
||||
if (whitelist.includes(user!.id!)) return true
|
||||
|
||||
return user!.is_admin || user!.is_owner || user!.is_primary_owner
|
||||
}
|
||||
|
||||
const eligibilityCmd = async (ctx: any) => {
|
||||
await ctx.ack();
|
||||
|
||||
|
@ -33,12 +19,8 @@ const eligibilityCmd = async (ctx: any) => {
|
|||
const iUser = await ctx.client.users.info({ user: ctx.context.userId! });
|
||||
|
||||
if ((match = text.match(/\<\@(.+)\|(.+)>/))) {
|
||||
if (!checkUserOk(iUser.user!)) {
|
||||
matchedBy = "not allowed"
|
||||
} else {
|
||||
userId = match[1];
|
||||
matchedBy = "user mention"
|
||||
}
|
||||
userId = match[1];
|
||||
matchedBy = "user mention"
|
||||
} else if (text)
|
||||
matchedBy = "invalid input"
|
||||
|
||||
|
@ -52,30 +34,29 @@ const eligibilityCmd = async (ctx: any) => {
|
|||
redirect: "follow"
|
||||
}).then(res => res.json())
|
||||
|
||||
if (res === `User ${userId} not found!`)
|
||||
if (res.status === "not_found")
|
||||
return await ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
text: `${matchedBy !== "user mention" ? "You aren't" : `<@${userId}> isn't`} verified and therefore aren't eligible for rewards from your program.${matchedBy !== "user mention" ? `\nCheck out the <https://forms.hackclub.com/eligibility?slack_id=${userId}|eligiblity form> to verify.` : ""}${matchedBy == "not allowed" ? " (Only whitelisted users can check other people's verification statuses.)" : ""}`,
|
||||
text: `${matchedBy !== "user mention" ? "You aren't" : `<@${userId}> isn't`} verified. ${matchedBy !== "user mention" ? `\nCheck out the <https://identity.hackclub.com/onboarding/welcome}|identity vault> to verify.` : ""}`,
|
||||
unfurl_links: true
|
||||
})
|
||||
|
||||
else if (res.status === "Insufficient") {
|
||||
else if (res.status === "needs_submission") {
|
||||
return await ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
text: `${matchedBy !== "user mention" ? "You" : `<@${userId}>`} provided insufficient evidence that ${matchedBy !== "user mention" ? "you" : "they"} are a student.${matchedBy !== "user mention" ? `\nCheck out the <https://forms.hackclub.com/eligibility?slack_id=${userId}|eligiblity form> to re-verify.` : ""}${matchedBy == "not allowed" ? " (Only whitelisted users can check other people's verification statuses.)" : ""}`,
|
||||
text: `${matchedBy !== "user mention" ? "You" : `<@${userId}>`} provided insufficient evidence of who ${matchedBy !== "user mention" ? "you" : "they"} are.${matchedBy !== "user mention" ? `\nCheck out the <https://identity.hackclub.com/onboarding/welcome}|identity vault> to re-verify.` : ""}`,
|
||||
unfurl_links: true
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
else if (res.status === "Unknown") {
|
||||
else if (res.status === "pending") {
|
||||
return await ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
text: `${matchedBy !== "user mention" ? "Your verification" : `<@${userId}>'s verification`} has not been accepted yet.${matchedBy == "not allowed" ? " (Only whitelisted users can check other people's verification statuses.)" : ""}`,
|
||||
unfurl_links: true
|
||||
})
|
||||
text: `${matchedBy !== "user mention" ? "Your verification" : `<@${userId}>'s verification`} has not been accepted yet.`,
|
||||
})
|
||||
}
|
||||
|
||||
else if (res.status === "Ineligible") {
|
||||
else if (res.status === "rejected") {
|
||||
if (matchedBy === "user mention") {
|
||||
return await ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
|
@ -84,11 +65,15 @@ const eligibilityCmd = async (ctx: any) => {
|
|||
} else {
|
||||
return await ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
text: `Your verification has been denied. If you believe this to be a mistake, please contact an admin of the program you are applying for.${matchedBy == "not allowed" ? " (Only whitelisted users can check other people's verification statuses.)" : ""},`
|
||||
text: `Your verification has been denied. If you believe this to be a mistake, please send a message in <#C092833JXKK>.`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The sanctioned country status seems to have been deprecated in the Identity Vault.
|
||||
* However, this piece of code is being kept for documentation purposes.
|
||||
|
||||
else if (res.status === "Sanctioned country") {
|
||||
if (matchedBy === "user mention") {
|
||||
return await ctx.respond({
|
||||
|
@ -100,22 +85,21 @@ const eligibilityCmd = async (ctx: any) => {
|
|||
response_type: 'ephemeral',
|
||||
text: `You live in a country that cannot have packages delivered to due to sanctions.${matchedBy == "not allowed" ? " (Only whitelisted users can check other people's verification statuses.)" : ""},`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
else {
|
||||
else if (res.status === "verified_eligible") {
|
||||
return await ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
text: `${matchedBy !== "user mention" ? "You have verified your" : `<@${userId}> has verified their`} student status, and ${matchedBy !== "user mention" ? "are" : "is"} ${res.status}.${matchedBy == "not allowed" ? " (Only whitelisted users can check other people's verification statuses.)" : ""}`,
|
||||
blocks: [
|
||||
{
|
||||
type: 'section',
|
||||
text: {
|
||||
type: 'mrkdwn',
|
||||
text: `${matchedBy !== "user mention" ? "You have verified your" : `<@${userId}> has verified their`} student status, and ${matchedBy !== "user mention" ? "are" : "is"} *${res.status}*.${matchedBy == "not allowed" ? " (Only whitelisted users can check other people's verification statuses.)" : ""}`
|
||||
}
|
||||
}
|
||||
]
|
||||
text: `${matchedBy !== "user mention" ? "You have verified your" : `<@${userId}> has verified their`} identity, and ${matchedBy !== "user mention" ? "are" : "is"} eligible for YSWS prizes.`,
|
||||
})
|
||||
}
|
||||
|
||||
else if (res.status === "verified_but_over_18") {
|
||||
return await ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
text: `${matchedBy !== "user mention" ? "You have verified your" : `<@${userId}> has verified their`} identity, but since ${matchedBy !== "user mention" ? "you're" : "they're"} over 18, ${matchedBy !== "user mention" ? "you're" : "they're"} ineligible for YSWS prizes.`,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue