Compare commits

..

1 commit

Author SHA1 Message Date
72d43d1cd0
Update dependency @slack/web-api to v7.8.0 2024-12-08 20:00:13 +00:00
2 changed files with 58 additions and 38 deletions

View file

@ -8,6 +8,20 @@ const app = new App({
signingSecret: process.env.SLACK_SIGNING_SECRET, 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) => { const eligibilityCmd = async (ctx: any) => {
await ctx.ack(); await ctx.ack();
@ -16,43 +30,52 @@ const eligibilityCmd = async (ctx: any) => {
let userId = ctx.context.userId; let userId = ctx.context.userId;
let matchedBy = "no input" let matchedBy = "no input"
const iUser = await ctx.client.users.info({ user: ctx.context.userId! });
if ((match = text.match(/\<\@(.+)\|(.+)>/))) { if ((match = text.match(/\<\@(.+)\|(.+)>/))) {
userId = match[1]; if (!checkUserOk(iUser.user!)) {
matchedBy = "user mention" matchedBy = "not allowed"
} else {
userId = match[1];
matchedBy = "user mention"
}
} else if (text) } else if (text)
matchedBy = "invalid input" matchedBy = "invalid input"
const res = await fetch("https://identity.hackclub.com/api/external/check?slack_id=" + userId, { const res = await fetch("https://verify.hackclub.dev/api/status", {
headers: { method: "POST",
'User-Agent': 'HackClubEligibilityBot/1.0 (ran by Loop / dainfloop)' headers: { 'content-type': 'application/json' },
}, body: JSON.stringify({
"slack_id": userId
}),
redirect: "follow" redirect: "follow"
}).then(res => res.json()) }).then(res => res.json())
if (res.result === "not_found") if (res === `User ${userId} not found!`)
return await ctx.respond({ return await ctx.respond({
response_type: 'ephemeral', response_type: 'ephemeral',
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.` : ""}`, 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.)" : ""}`,
unfurl_links: true unfurl_links: true
}) })
else if (res.result === "needs_submission") { else if (res.status === "Insufficient") {
return await ctx.respond({ return await ctx.respond({
response_type: 'ephemeral', response_type: 'ephemeral',
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.` : ""}`, 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.)" : ""}`,
unfurl_links: true unfurl_links: true
}) })
} }
else if (res.result === "pending") { else if (res.status === "Unknown") {
return await ctx.respond({ return await ctx.respond({
response_type: 'ephemeral', response_type: 'ephemeral',
text: `${matchedBy !== "user mention" ? "Your verification" : `<@${userId}>'s verification`} has not been accepted yet.`, 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
}) })
} }
else if (res.result === "rejected") { else if (res.status === "Ineligible") {
if (matchedBy === "user mention") { if (matchedBy === "user mention") {
return await ctx.respond({ return await ctx.respond({
response_type: 'ephemeral', response_type: 'ephemeral',
@ -61,15 +84,11 @@ const eligibilityCmd = async (ctx: any) => {
} else { } else {
return await ctx.respond({ return await ctx.respond({
response_type: 'ephemeral', response_type: 'ephemeral',
text: `Your verification has been denied. If you believe this to be a mistake, please send a message in <#C092833JXKK>.` 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.)" : ""},`
}) })
} }
} }
/**
* 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") { else if (res.status === "Sanctioned country") {
if (matchedBy === "user mention") { if (matchedBy === "user mention") {
return await ctx.respond({ return await ctx.respond({
@ -83,19 +102,20 @@ const eligibilityCmd = async (ctx: any) => {
}) })
} }
} }
*/
else if (res.result === "verified_eligible") { else {
return await ctx.respond({ return await ctx.respond({
response_type: 'ephemeral', response_type: 'ephemeral',
text: `${matchedBy !== "user mention" ? "You have verified your" : `<@${userId}> has verified their`} identity, and ${matchedBy !== "user mention" ? "are" : "is"} eligible for YSWS prizes.`, 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',
else if (res.result === "verified_but_over_18") { text: {
return await ctx.respond({ type: 'mrkdwn',
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.)" : ""}`
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.`, }
}
]
}) })
} }
} }

14
package-lock.json generated
View file

@ -297,16 +297,16 @@
} }
}, },
"node_modules/@slack/web-api": { "node_modules/@slack/web-api": {
"version": "7.3.4", "version": "7.8.0",
"resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-7.3.4.tgz", "resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-7.8.0.tgz",
"integrity": "sha512-KwLK8dlz2lhr3NO7kbYQ7zgPTXPKrhq1JfQc0etJ0K8LSJhYYnf8GbVznvgDT/Uz1/pBXfFQnoXjrQIOKAdSuw==", "integrity": "sha512-d4SdG+6UmGdzWw38a4sN3lF/nTEzsDxhzU13wm10ejOpPehtmRoqBKnPztQUfFiWbNvSb4czkWYJD4kt+5+Fuw==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@slack/logger": "^4.0.0", "@slack/logger": "^4.0.0",
"@slack/types": "^2.9.0", "@slack/types": "^2.9.0",
"@types/node": ">=18.0.0", "@types/node": ">=18.0.0",
"@types/retry": "0.12.0", "@types/retry": "0.12.0",
"axios": "^1.7.4", "axios": "^1.7.8",
"eventemitter3": "^5.0.1", "eventemitter3": "^5.0.1",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"is-electron": "2.2.2", "is-electron": "2.2.2",
@ -561,9 +561,9 @@
} }
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "1.7.7", "version": "1.7.9",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
"integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"follow-redirects": "^1.15.6", "follow-redirects": "^1.15.6",