hack-club-eligiblity/index.ts

110 lines
4.3 KiB
TypeScript

import type { UsersInfoResponse } from "@slack/web-api";
const { App } = (await import("@slack/bolt"));
import "dotenv/config";
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
});
const eligibilityCmd = async (ctx: any) => {
await ctx.ack();
const text = ctx.command.text.slice();
let match;
let userId = ctx.context.userId;
let matchedBy = "no input"
if ((match = text.match(/\<\@(.+)\|(.+)>/))) {
userId = match[1];
matchedBy = "user mention"
} else if (text)
matchedBy = "invalid input"
const res = await fetch("https://identity.hackclub.com/api/external/check?slack_id=" + userId, {
headers: {
'User-Agent': 'HackClubEligibilityBot/1.0 (ran by Loop / dainfloop)'
}
redirect: "follow"
}).then(res => res.json())
if (res.status === "not_found")
return await ctx.respond({
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.` : ""}`,
unfurl_links: true
})
else if (res.status === "needs_submission") {
return await ctx.respond({
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.` : ""}`,
unfurl_links: true
})
}
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.`,
})
}
else if (res.status === "rejected") {
if (matchedBy === "user mention") {
return await ctx.respond({
response_type: 'ephemeral',
text: `<@${userId}>'s verification has been denied.`
})
} else {
return await ctx.respond({
response_type: 'ephemeral',
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({
response_type: 'ephemeral',
text: `<@${userId}> lives in a country that cannot have packages delivered to due to sanctions.`
})
} else {
return await ctx.respond({
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 if (res.status === "verified_eligible") {
return await ctx.respond({
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.`,
})
}
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.`,
})
}
}
app.command("/check-eligiblity", eligibilityCmd)
app.command("/check-eligibility", eligibilityCmd)
; (async () => {
await app.start(60275);
console.log('⚡️ Bolt app is running!');
})();