-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuser.js
More file actions
79 lines (73 loc) · 2.86 KB
/
user.js
File metadata and controls
79 lines (73 loc) · 2.86 KB
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
79
const axios = require("axios");
const { MessageEmbed, WebhookClient } = require('discord.js');
require('dotenv').config();
vrchat_();
// vrchat main func
function vrchat_() {
// friends check
function Online() {
axios.get("https://vrchat.com/api/1/auth/user", { headers: { Cookie: process.env.COOKIE } }).then(res => {
const mydata_ = res.data
console.log(`Logged in as: ${mydata_.displayName} 💗`);
axios.get("https://vrchat.com/api/1/auth/user/friends", { headers: { Cookie: process.env.COOKIE } }).then(res => {
const data = res.data;
data.forEach(friend => {
const friend_data = {
"username": friend.username,
"displayName": friend.displayName,
"des": friend.statusDescription,
"bio": friend.bio,
"avatarImage": friend.currentAvatarImageUrl,
"url": `https://vrchat.com/home/user/${friend.id}`,
"status": friend.status
};
const obj_fields = {
"status": friend.status,
'last_login': friend.last_login,
"last_platform": friend.last_platform,
'location': friend.location,
}
discord(mydata_,friend_data,objToArr(obj_fields));
})
});
});
}
Online();
setInterval(()=>{Online()},15*60*1000); // online state check every 15 minutes
}
function objToArr(obj) {
var arr = [];
for (const [key, value] of Object.entries(obj)) {
var obj_={};
if(value!==''){
obj_ = { name: key, value: value, inline: true };
}else{
obj_ = { name: key, value: '-', inline: true };
}
arr.push(obj_);
}
return arr
}
// discord main func
function discord(user,obj,fields) {
// state color
const state_ = {
'join me' : '#38F3EF',
'active' : '#3cf08a',
'ask me' : '#F38E23',
'busy': '#FD4D4D'
};
// discord embed
const embed = new MessageEmbed()
.setTitle(`${obj.displayName} (${obj.username})`)
.setURL(obj.url)
.setColor(state_[obj.status])
.setDescription(`Description | ${obj.des}\n**bio** | ${obj.bio}\n`)
.setThumbnail(obj.avatarImage)
.addFields(fields)
.setTimestamp()
.setFooter({ text: user.displayName, iconURL: 'https://cdn-icons-png.flaticon.com/512/173/173045.png' });
const webhookClient = new WebhookClient({ url: process.env.WEBHOOK });
webhookClient.send({ embeds: [embed] });
}
console.log('server is starting ✅')