-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
78 lines (64 loc) · 2.13 KB
/
app.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
69
70
71
72
73
74
75
76
77
78
const express = require("express")
const app = express()
const config = require("./config")
const { Intents } = require('discord.js');
const client = new (require("discord.js")).Client({ intents: [Intents.FLAGS.GUILDS] })
const Badges = require("./Badges")
const PORT = config.PORT || 3000
const moment = require('moment')
moment.locale('en')
client.on("ready", () => {
client.user.setPresence({ activities: [{ name: 'with Whois' }], status: 'offline' })
})
client.login(config.TOKEN).then(r => r)
app.set("view engine", "ejs")
app.use(express.static("public"))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.get(`/`, (req, res) => {
res.render("index", {
error: null
})
})
app.post(`/whois`, async (req, res) => {
if(req.body.user) res.redirect(`/${req.body.user}`)
else res.redirect("/404")
})
app.get(`/:userID`, async (req, res) => {
const userid = req.params.userID
//if (!userid) return res.redirect("/404")
const user = userid === client.user.id ? client.user : await client.users.fetch(getID(userid)).catch(e => {})
if (!user) return res.render("index", {
error: "Invalid user ID !"
})
if (!user.flags) await user.fetchFlags()
let flags = []
let Flags;
if (user.flags === null) {
} else {
Flags = user.flags.toArray()
if (user.bot && Flags.includes("VERIFIED_BOT")) user.verified = true
flags = Flags.filter(b => !!Badges[b]).map(m => Badges[m])
if (user.avatar && user.avatar.startsWith("a_")) flags.push(Badges["DISCORD_NITRO"])
if (user.flags.has(1 << 18)) flags.push(Badges["CERTIFIED_MODERATOR"])
if (user.flags.has(1 << 17)) flags.push(Badges["VERIFIED_DEVELOPER"])
if (user.flags.has(1 << 22)) flags.push(Badges["ACTIVE_DEVELOPER"])
if (user.bot) {
flags.push(Badges["BOT"])
}
}
return res.render("user", {
user,
flags,
moment
})
})
app.all(/(.*)/, (req, res) => {
return res.render("404")
})
app.listen(PORT, () => {
console.log(`Website running on port :${PORT}`)
})
function getID(source) {
return source
}