Compare commits
6 Commits
22540076e2
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 97cbd989c5 | |||
| b45bc6c864 | |||
| 667e04be29 | |||
| 20bdae485b | |||
| f716bf9cc3 | |||
| cebe8dbd42 |
@@ -25,34 +25,60 @@ var status2icon = {
|
||||
}
|
||||
var selfUserId;
|
||||
|
||||
vrc.authenticationApi.getCurrentUser().then(res => {
|
||||
console.log("vrc login", res.data.username);
|
||||
selfUserId = res.data.id;
|
||||
exithook(cb => {
|
||||
console.log("logging out");
|
||||
client.destroy();
|
||||
vrc.authenticationApi.logout().then(res => {
|
||||
console.log(res.data);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
client.login(process.env.TOKEN).then(() => {
|
||||
console.log("discord login", client.user.tag);
|
||||
}).catch(error => console.error("discord login fail", error.stack));
|
||||
startClock();
|
||||
}).catch(error => console.error("vrc login fail:", JSON.stringify(error.response.data)));
|
||||
}).catch(error => {
|
||||
console.log("discord login fail", error.stack)
|
||||
});
|
||||
|
||||
client.once("ready", async () => {
|
||||
var vrcat = client.channels.resolve(VRCAT);
|
||||
if (!vrcat) return console.error("category not found");
|
||||
if (!vrcat) return console.log("category not found");
|
||||
for (let child of vrcat.children.values()) await child.delete();
|
||||
exithook(async cb => {
|
||||
console.log("discord cleanup");
|
||||
for (let child of vrcat.children.values()) await child.delete();
|
||||
client.destroy();
|
||||
console.log("discord destroyed");
|
||||
cb();
|
||||
});
|
||||
try {
|
||||
var logindata = await vrc.authenticationApi.getCurrentUser().then(res => res.data);
|
||||
} catch (error) {
|
||||
console.log("vrc login fail:", JSON.stringify(error.response.data));
|
||||
vrcat.createChannel("login failure", {type: "GUILD_VOICE"}).catch(()=>{});
|
||||
}
|
||||
if (!logindata) return;
|
||||
console.log("vrc login", logindata.username);
|
||||
selfUserId = logindata.id;
|
||||
exithook(cb => {
|
||||
console.log("vrc logout");
|
||||
vrc.authenticationApi.logout().then(res => {
|
||||
console.log("vrc", res.data);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
do {
|
||||
try {
|
||||
await syncStat();
|
||||
} catch (error) {
|
||||
console.error(error.stack);
|
||||
console.log("syncStat", error.message);
|
||||
if (error.response?.status == 401 /* && error.response.data.message == "\"Missing Credentials\"" /* todo? */) {
|
||||
console.log(error.response.data);
|
||||
try {
|
||||
var logindata = await vrc.authenticationApi.getCurrentUser().then(res => res.data);
|
||||
console.log("vrc relogin", logindata.username);
|
||||
selfUserId = logindata.id;
|
||||
} catch (error) {
|
||||
console.log("relogin fail", error.message, logindata);
|
||||
vrcat.createChannel("login failure", {type: "GUILD_VOICE"}).catch(()=>{});
|
||||
await new Promise(r => setTimeout(r, 1000*60*60));
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 1000*60*5))
|
||||
} else {
|
||||
vrcat.createChannel(error.response?.status?.toString() || error.message, {type: "GUILD_VOICE"}).catch(()=>{});
|
||||
}
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 1000*60*5));
|
||||
} while (true);
|
||||
});
|
||||
|
||||
@@ -61,11 +87,11 @@ async function syncStat() {
|
||||
friendsOnline = friendsOnline.filter(x => x.location);
|
||||
var selfUser = await vrc.usersApi.getUser(selfUserId).then(res => res.data);
|
||||
if (selfUser.state == "online") friendsOnline.unshift(selfUser);
|
||||
console.debug(friendsOnline.map(m => m.displayName));
|
||||
//console.debug(friendsOnline.map(m => m.displayName));
|
||||
for (let fren of friendsOnline) {
|
||||
try {
|
||||
let vcnam = `${status2icon[fren.status]} ${fren.displayName}`;
|
||||
let subvcnam = `${SUBCH_PFX} ${await getWorldNameForId(fren.location.split(':')[0])}`;
|
||||
let vcnam = `${status2icon[fren.status]} ${fren.displayName}`.substring(0,100);
|
||||
let subvcnam = `${SUBCH_PFX} ${await getWorldNameForId(fren.location.split(':')[0])}`.substring(0,100);
|
||||
let vc = client.channels.resolve(VRCAT).children.find(vc => vc.vrcuid == fren.id);
|
||||
if (vc) {
|
||||
if (vc.name != vcnam) await vc.setName(vcnam);
|
||||
@@ -76,7 +102,7 @@ async function syncStat() {
|
||||
vc.vrcuid = fren.id;
|
||||
}
|
||||
} catch(error) {
|
||||
console.error(`fren ${fren.username} brok:`, error);
|
||||
console.log(`fren ${fren.username} brok:`, error);
|
||||
}
|
||||
}
|
||||
for (let vc of client.channels.resolve(VRCAT).children.values()) {
|
||||
@@ -98,16 +124,3 @@ async function getWorldNameForId(worldId) {
|
||||
global.client = client;
|
||||
global.vrc = vrc;
|
||||
global.syncStat = syncStat;
|
||||
|
||||
|
||||
function startClock() {
|
||||
(function clock() {
|
||||
var d = new Date();
|
||||
vrc.usersApi.updateUser(selfUserId, {
|
||||
statusDescription: d.toLocaleTimeString([], {timeStyle: 'short'})
|
||||
});
|
||||
d.setSeconds(60);
|
||||
setTimeout(clock, d - Date.now());
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
Generated
+7
-7
@@ -8,7 +8,7 @@
|
||||
"async-exit-hook": "^2.0.1",
|
||||
"discord.js": "^13.6.0",
|
||||
"dotenv": "^16.0.0",
|
||||
"vrchat": "^1.6.9"
|
||||
"vrchat": "^1.7.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@discordjs/builders": {
|
||||
@@ -328,9 +328,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vrchat": {
|
||||
"version": "1.6.9",
|
||||
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.6.9.tgz",
|
||||
"integrity": "sha512-eV3EzHtObBGIzb5tEOP6vqeZsGIlMLXybO2CwpkSDvGra2ORIoh5hYnUq9JeMnAsmwF/xMpPHrb5yg5ZPDhAoA==",
|
||||
"version": "1.7.1",
|
||||
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.7.1.tgz",
|
||||
"integrity": "sha512-RuJkqEsouqnUDQBmZCwLgXQSSijdR3yaaew8ajM/j+28NAEXHR3uMyrnWPmWDZUPTV9zASlSTpabft1yq84z9Q==",
|
||||
"dependencies": {
|
||||
"@types/tough-cookie": "^4.0.1",
|
||||
"axios": "^0.21.4",
|
||||
@@ -601,9 +601,9 @@
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
|
||||
},
|
||||
"vrchat": {
|
||||
"version": "1.6.9",
|
||||
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.6.9.tgz",
|
||||
"integrity": "sha512-eV3EzHtObBGIzb5tEOP6vqeZsGIlMLXybO2CwpkSDvGra2ORIoh5hYnUq9JeMnAsmwF/xMpPHrb5yg5ZPDhAoA==",
|
||||
"version": "1.7.1",
|
||||
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.7.1.tgz",
|
||||
"integrity": "sha512-RuJkqEsouqnUDQBmZCwLgXQSSijdR3yaaew8ajM/j+28NAEXHR3uMyrnWPmWDZUPTV9zASlSTpabft1yq84z9Q==",
|
||||
"requires": {
|
||||
"@types/tough-cookie": "^4.0.1",
|
||||
"axios": "^0.21.4",
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@
|
||||
"async-exit-hook": "^2.0.1",
|
||||
"discord.js": "^13.6.0",
|
||||
"dotenv": "^16.0.0",
|
||||
"vrchat": "^1.6.9"
|
||||
"vrchat": "^1.7.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user