More pfps to come...

This commit is contained in:
bingus_violet 2024-03-07 10:54:28 -06:00
parent c1dd5de444
commit c6ff7c1e87
10 changed files with 51 additions and 2 deletions

28
PFPs.json Normal file
View 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"
}
}
]
}

View file

@ -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."

View file

@ -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) => {

View file

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View file

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View file

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB