-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.js
42 lines (36 loc) · 1.07 KB
/
tools.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
const { metadata } = require("./metadata.js");
function isInteractionUserAdmin(interaction) {
const userInfo = parse_user_info(interaction, "INTERACTION");
return userInfo.user_level === "admin";
}
function set_user_level(username) {
if (metadata.admin.includes(username)) {
return "admin";
}
else if (metadata.moderator.includes(username)) {
return "moderator";
}
else if (metadata.organizer.includes(username)) {
return "organizer";
}
else {
return "user";
}
}
function parse_user_info(event, event_type) {
let user_object = null;
if (event_type === "INTERACTION") {
user_object = event.user;
}
else if (event_type === "MESSAGE") {
user_object = event.author;
}
else {
console.log(`While parsing user info, event type ${event_type} not recognized.`)
return null;
}
const username = `${user_object.username}#${user_object.discriminator}`;
const user_level = set_user_level(username);
return { username: username, user_level: user_level }
}
module.exports = { isInteractionUserAdmin, parse_user_info };