-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate-avatar.js
31 lines (28 loc) · 1.13 KB
/
update-avatar.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
const fs = require('fs');
fetch("https://api.lanyard.rest/v1/users/468465290531962900")
.then((res) => res.json())
.then((data) => {
if (data.success) {
const userId = data.data.discord_user.id;
const avatarHash = data.data.discord_user.avatar;
const avatarUrl = `https://cdn.discordapp.com/avatars/${userId}/${avatarHash}`;
// Read the index.html file
fs.readFile('index.html', 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
// Dynamically find and update the og:image content attribute with the new avatar URL
const ogImageRegex = /<meta property="og:image" content="[^"]*">/;
const updatedContent = data.replace(ogImageRegex, `<meta property="og:image" content="${avatarUrl}">`);
// Write the updated content back to index.html
fs.writeFile('index.html', updatedContent, 'utf8', function(err) {
if (err) return console.log(err);
});
});
} else {
console.error("Error fetching avatar data.");
}
})
.catch((error) => {
console.error("Error fetching from Lanyard API:", error);
});