-
Notifications
You must be signed in to change notification settings - Fork 4
/
pronouns.js
68 lines (62 loc) · 1.8 KB
/
pronouns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const axios = require('axios');
const display = {
"aeaer": "Ae/Aer",
"any": "Any",
"eem": "E/Em",
"faefaer": "Fae/Faer",
"hehim": "He/Him",
"heshe": "He/She",
"hethem": "He/They",
"itits": "It/Its",
"other": "Other",
"perper": "Per/Per",
"sheher": "She/Her",
"shethem": "She/They",
"theythem": "They/Them",
"vever": "Ve/Ver",
"xexem": "Xe/Xem",
"ziehir": "Zie/Hir",
};
let cache = {};
const client = axios.create({
baseURL: 'https://pronouns.alejo.io/api',
timeout: 5000,
});
async function get_pronoun_id(user) {
if (cache[user]) {
return cache[user];
}
const res = await client.get(`/users/${user}`);
if (res == null || !res.data[0]) {
console.log("Failed to get pronoun id for user " + user);
if (res) {
console.log(res.data);
}
return null;
}
const id = res.data[0].pronoun_id;
cache[user] = id;
return id;
}
async function get_pronouns(user) {
const id = await get_pronoun_id(user);
if (!id) {
return null;
}
const out = display[id];
if (!out) {
console.log("Unknown pronoun id: " + id + " for user " + user);
return null;
}
return out;
}
async function pronouns(chatClient, channel, user) {
return get_pronouns(user).then(pronoun => {
if (pronoun) {
chatClient.say(channel, `I think ${user}'s pronouns are ${pronoun}. If this isn't right, set them at https://pronouns.alejo.io`);
} else {
chatClient.say(channel, `I don't know ${user}'s pronouns. Set them at https://pronouns.alejo.io`);
}
}).catch(() => chatClient.say(channel, `Sorry, I'm having trouble getting ${user}'s pronouns. Try again later.`));
}
module.exports = { pronouns, get_pronouns, get_pronoun_id };