Compare commits

...

16 Commits

Author SHA1 Message Date
lamp d9a1b9b99c disable broken 2022-04-01 23:05:40 -07:00
lamp 6fe26e7837 DEBUG AGAIN FUCK 2022-04-01 22:53:50 -07:00
lamp afc2b10a86 fix bug 2022-04-01 22:32:08 -07:00
lamp 3369bd521d DEBUG BITCH 2022-04-01 22:09:07 -07:00
lamp d52aff9936 ok 2022-04-01 22:03:00 -07:00
lamp a44f81bddf wtff 2022-04-01 21:56:31 -07:00
lamp 2925c3d788 recreate missing channel 2022-04-01 21:45:26 -07:00
lamp 9dcd27c45f wat 2022-04-01 21:04:39 -07:00
lamp e882ee7e57 fix private 2022-04-01 21:04:12 -07:00
lamp 20ecfb3e84 debug 2022-04-01 20:54:03 -07:00
lamp 16f4b7eaf9 fix 2022-04-01 20:53:25 -07:00
lamp 940d3f6c30 show world in 2022-04-01 20:37:44 -07:00
lamp 4252a2f060 fucking env variables 2022-03-31 18:38:00 -07:00
lamp f602638aae fix 2022-03-31 18:11:15 -07:00
lamp c9c45d17e7 need defer 2022-03-31 18:01:55 -07:00
lamp bf27b6519a fix 2022-03-31 17:59:22 -07:00
4 changed files with 61 additions and 9 deletions
+1
View File
@@ -2,4 +2,5 @@ process.on("unhandledRejection", error => {
console.error("Unhandled Rejection:\n" + error.stack);
});
require("dotenv").config();
require("./vrchat");
+14
View File
@@ -8,6 +8,7 @@
"@discordjs/voice": "^0.7.5",
"deepl": "^1.0.12",
"discord.js": "^13.6.0",
"dotenv": "^16.0.0",
"express": "^4.17.1",
"fast-average-color-node": "^1.0.3",
"kuroshiro": "^1.2.0",
@@ -494,6 +495,14 @@
"npm": ">=7.0.0"
}
},
"node_modules/dotenv": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==",
"engines": {
"node": ">=12"
}
},
"node_modules/doublearray": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
@@ -1957,6 +1966,11 @@
"ws": "^8.4.0"
}
},
"dotenv": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q=="
},
"doublearray": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
+1
View File
@@ -3,6 +3,7 @@
"@discordjs/voice": "^0.7.5",
"deepl": "^1.0.12",
"discord.js": "^13.6.0",
"dotenv": "^16.0.0",
"express": "^4.17.1",
"fast-average-color-node": "^1.0.3",
"kuroshiro": "^1.2.0",
+45 -9
View File
@@ -9,6 +9,7 @@ var authenticationApi = new vrchat.AuthenticationApi(configuration);
authenticationApi.getCurrentUser().then(console.log);
var usersApi = new vrchat.UsersApi(configuration);
var worldsApi = new vrchat.WorldsApi(configuration);
var status2icon = {
"join me": '🔵',
@@ -25,16 +26,40 @@ try {
}
async function updateUserStatuses() {
for (let {channel, userId} of vrcul) {
for (let x of vrcul) {
try {
channel = client.channels.resolve(channel);
let user = (await usersApi.getUser(userId)).data;
let status_icon = user.state == "online" ? status2icon(user.status) : '⚫';
let user = (await usersApi.getUser(x.userId)).data;
let status_icon = user.state == "online" ? status2icon[user.status] : '⚫';
let nn = `${status_icon} ${user.displayName}`;
if (nn != channel.name)
var channel = client.channels.resolve(x.channel);
if (!channel) {
channel = await client.channels.resolve(config.vrchat_status_category).createChannel(nn, {type: "GUILD_VOICE"});
x.channel = channel.id;
fs.writeFileSync("data/vrcul.json", JSON.stringify(vrcul));
} else if (nn != channel.name) {
await channel.setName(nn);
}
continue;
let belowChannel = client.channels.resolve(config.vrchat_status_category).children.find(x => x.position == channel.position + 1);
if (user.worldId && user.worldId != "offline") {
let bcn = `${await getWorldNameForId(user.worldId)}`;
if (belowChannel && belowChannel.name.startsWith('┗') && belowChannel.name != bcn) { //todo debug
await belowChannel.setName(bcn);
} else {
let ch = await client.channels.resolve(config.vrchat_status_category).createChannel(`${await getWorldNameForId(user.worldId)}`, {type: "GUILD_VOICE", /*position: belowChannel.position*/});
// position option is erratic
await ch.setPosition(channel.position + 1);
}
} else if (belowChannel?.name.startsWith('┗')) {
await belowChannel.delete();
}
} catch (error) {
console.error("vrcus", error.message);
console.error("vrcus", error.stack);
}
}
}
@@ -47,16 +72,27 @@ module.exports.interval = setInterval(updateUserStatuses, 1000*60*5);
client.on("interactionCreate", async i => {
if (i.commandName == "addvru") {
try {
await i.deferReply();
let u = i.options.getString("user");
let user = (await usersApi[u.startsWith("usr_") ? 'getUser' : 'getUserByName'](u)).data;
let status_icon = user.state == "online" ? status2icon(user.status) : '⚫';
let status_icon = user.state == "online" ? status2icon[user.status] : '⚫';
let nn = `${status_icon} ${user.displayName}`;
let channel = await client.channels.resolve(config.vrchat_status_category).createChannel(nn);
let channel = await client.channels.resolve(config.vrchat_status_category).createChannel(nn, {type: "GUILD_VOICE"});
vrcul.push({channel: channel.id, userId: user.id});
fs.writeFileSync("data/vrcul.json", JSON.stringify(vrcul));
await i.reply(channel.toString());
await i.editReply(channel.toString());
} catch (error) {
i.reply(error.message);
}
}
});
var worldnamecache = {};
async function getWorldNameForId(worldId) {
if (worldId == "private") return "Private World";
return worldnamecache[worldId] = worldnamecache[worldId] || (await worldsApi.getWorld(worldId)).data.name;
}