Compare commits

..

No commits in common. "f716bf9cc353e276879b10518abff65bfcf454c0" and "22540076e2f433c5d1164dc5757db777bbf52f22" have entirely different histories.

3 changed files with 26 additions and 41 deletions

View File

@ -25,48 +25,34 @@ 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)
});
}).catch(error => console.error("discord login fail", error.stack));
startClock();
}).catch(error => console.error("vrc login fail:", JSON.stringify(error.response.data)));
client.once("ready", async () => {
var vrcat = client.channels.resolve(VRCAT);
if (!vrcat) return console.error("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.error("vrc login fail:", JSON.stringify(error.response.data));
await vrcat.createChannel("login failure", {type: "GUILD_VOICE"});
}
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();
});
});
startClock();
do {
try {
await syncStat();
} catch (error) {
console.error(error.stack);
vrcat.createChannel("error occured", {type: "GUILD_VOICE"}).catch(()=>{});
}
await new Promise(r => setTimeout(r, 1000*60*5));
await new Promise(r => setTimeout(r, 1000*60*5))
} while (true);
});
@ -117,10 +103,9 @@ global.syncStat = syncStat;
function startClock() {
(function clock() {
var d = new Date();
if (!(d.getMinutes() % 2)) // skip odd minutes to keep average request rate under 1 per minute
vrc.usersApi.updateUser(selfUserId, {
statusDescription: d.toLocaleTimeString([], {timeStyle: 'short'})
}).catch(error => console.error("clock", error.message));
});
d.setSeconds(60);
setTimeout(clock, d - Date.now());
})();

14
package-lock.json generated
View File

@ -8,7 +8,7 @@
"async-exit-hook": "^2.0.1",
"discord.js": "^13.6.0",
"dotenv": "^16.0.0",
"vrchat": "^1.7.1"
"vrchat": "^1.6.9"
}
},
"node_modules/@discordjs/builders": {
@ -328,9 +328,9 @@
}
},
"node_modules/vrchat": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.7.1.tgz",
"integrity": "sha512-RuJkqEsouqnUDQBmZCwLgXQSSijdR3yaaew8ajM/j+28NAEXHR3uMyrnWPmWDZUPTV9zASlSTpabft1yq84z9Q==",
"version": "1.6.9",
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.6.9.tgz",
"integrity": "sha512-eV3EzHtObBGIzb5tEOP6vqeZsGIlMLXybO2CwpkSDvGra2ORIoh5hYnUq9JeMnAsmwF/xMpPHrb5yg5ZPDhAoA==",
"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.7.1",
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.7.1.tgz",
"integrity": "sha512-RuJkqEsouqnUDQBmZCwLgXQSSijdR3yaaew8ajM/j+28NAEXHR3uMyrnWPmWDZUPTV9zASlSTpabft1yq84z9Q==",
"version": "1.6.9",
"resolved": "https://registry.npmjs.org/vrchat/-/vrchat-1.6.9.tgz",
"integrity": "sha512-eV3EzHtObBGIzb5tEOP6vqeZsGIlMLXybO2CwpkSDvGra2ORIoh5hYnUq9JeMnAsmwF/xMpPHrb5yg5ZPDhAoA==",
"requires": {
"@types/tough-cookie": "^4.0.1",
"axios": "^0.21.4",

View File

@ -3,6 +3,6 @@
"async-exit-hook": "^2.0.1",
"discord.js": "^13.6.0",
"dotenv": "^16.0.0",
"vrchat": "^1.7.1"
"vrchat": "^1.6.9"
}
}