Compare commits
2 Commits
22540076e2
...
f716bf9cc3
Author | SHA1 | Date | |
---|---|---|---|
|
f716bf9cc3 | ||
|
cebe8dbd42 |
51
index.js
51
index.js
@ -25,34 +25,48 @@ 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)));
|
||||
client.login(process.env.TOKEN).then(() => {
|
||||
console.log("discord login", client.user.tag);
|
||||
}).catch(error => {
|
||||
console.error("discord login fail", error.stack)
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
@ -103,9 +117,10 @@ 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
14
package-lock.json
generated
@ -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",
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user