More pfps to come...
28
PFPs.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"default": [
|
||||
{
|
||||
"name": "Misery",
|
||||
"pfpRoot": "/pfps/Misery/",
|
||||
"pfps": {
|
||||
"online": ["MiseryBedHappy.png"],
|
||||
"dnd": ["MiseryBedAngry.png"],
|
||||
"idle": ["MiseryBedNeutral.png"],
|
||||
"offline": [],
|
||||
"fallback": "/pfps/Misery/MiseryBedNeutral.png"
|
||||
}
|
||||
}
|
||||
],
|
||||
"christmas": [
|
||||
{
|
||||
"name": "Misery",
|
||||
"pfpRoot": "/pfps/Misery/",
|
||||
"pfps": {
|
||||
"online": ["MiserySantaHappy.png"],
|
||||
"dnd": ["MiserySantaAngry.png"],
|
||||
"idle": ["MiserySantaNeutral.png"],
|
||||
"offline": [],
|
||||
"fallback": "/pfps/Misery/MiserySantaNeutral.png"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
"documentation": "https://codeberg.org/Bingus_Violet/api.violets-purgatory.dev",
|
||||
"current_commands": {
|
||||
"/v1/pfp": {
|
||||
"description": "Generates a random PFP. For use on the main page & with UserPFP on Discord."
|
||||
"description": "Generates a (biased) random PFP. For use on the main page & with UserPFP on Discord."
|
||||
},
|
||||
"/v1/lanyard": {
|
||||
"description": "Fetches the most recently updated Lanyard update. Only gives data about *my* lanyard status. Don't worry about 'overusing' this, as it doesn't call a request to Lanyard or Discord everytime, it just gets the most recent data gathered by the web socket. Mainly designed to prevent my many sites from overloading the Lanyard socket, but also so that I can add extra features in the future if I so desire."
|
||||
|
|
23
index.js
|
@ -11,6 +11,8 @@ var lanyardData = "Nothing Fetched yet!"
|
|||
|
||||
var sockets = []
|
||||
|
||||
var pfpSeason = "default"
|
||||
|
||||
function randomFileInDir(directory) {
|
||||
var dir = fs.readdirSync(directory)
|
||||
return path.join(directory, dir[Math.floor(Math.random() * dir.length)])
|
||||
|
@ -23,7 +25,26 @@ app.get("/", (req, res) => {
|
|||
})
|
||||
|
||||
app.get("/v1/pfp", (req, res) => {
|
||||
res.sendFile(randomFileInDir(path.join(__dirname, 'pfps')))
|
||||
var time = new Date(Date.now())
|
||||
if ([11, 12, 1].includes(time.getMonth() + 1)) {
|
||||
pfpSeason = "christmas"
|
||||
}
|
||||
|
||||
var pfpConfig = JSON.parse(fs.readFileSync(path.join(__dirname, "PFPs.json")))[pfpSeason]
|
||||
var characterNumb = time.getDate() % pfpConfig.length
|
||||
var char = pfpConfig[characterNumb]
|
||||
var pfps = char.pfps
|
||||
|
||||
try {
|
||||
var status = lanyardData.d.discord_status
|
||||
var pfpPool = pfps[status]
|
||||
var rand = Math.floor(Math.random() * pfpPool.length)
|
||||
var pfp = path.join(__dirname, char.pfpRoot, pfpPool[rand])
|
||||
res.sendFile(pfp)
|
||||
} catch (error) {
|
||||
var pfp = path.join(__dirname, char.fallback)
|
||||
res.sendFile(pfp)
|
||||
}
|
||||
})
|
||||
|
||||
app.get("/v1/lanyard", (req, res) => {
|
||||
|
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |