Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9a1b9b99c | |||
| 6fe26e7837 | |||
| afc2b10a86 | |||
| 3369bd521d | |||
| d52aff9936 | |||
| a44f81bddf | |||
| 2925c3d788 | |||
| 9dcd27c45f | |||
| e882ee7e57 | |||
| 20ecfb3e84 | |||
| 16f4b7eaf9 | |||
| 940d3f6c30 | |||
| 4252a2f060 | |||
| f602638aae | |||
| c9c45d17e7 | |||
| bf27b6519a |
@@ -2,4 +2,5 @@ process.on("unhandledRejection", error => {
|
|||||||
console.error("Unhandled Rejection:\n" + error.stack);
|
console.error("Unhandled Rejection:\n" + error.stack);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
require("dotenv").config();
|
||||||
require("./vrchat");
|
require("./vrchat");
|
||||||
Generated
+14
@@ -8,6 +8,7 @@
|
|||||||
"@discordjs/voice": "^0.7.5",
|
"@discordjs/voice": "^0.7.5",
|
||||||
"deepl": "^1.0.12",
|
"deepl": "^1.0.12",
|
||||||
"discord.js": "^13.6.0",
|
"discord.js": "^13.6.0",
|
||||||
|
"dotenv": "^16.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fast-average-color-node": "^1.0.3",
|
"fast-average-color-node": "^1.0.3",
|
||||||
"kuroshiro": "^1.2.0",
|
"kuroshiro": "^1.2.0",
|
||||||
@@ -494,6 +495,14 @@
|
|||||||
"npm": ">=7.0.0"
|
"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": {
|
"node_modules/doublearray": {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
|
||||||
@@ -1957,6 +1966,11 @@
|
|||||||
"ws": "^8.4.0"
|
"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": {
|
"doublearray": {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"@discordjs/voice": "^0.7.5",
|
"@discordjs/voice": "^0.7.5",
|
||||||
"deepl": "^1.0.12",
|
"deepl": "^1.0.12",
|
||||||
"discord.js": "^13.6.0",
|
"discord.js": "^13.6.0",
|
||||||
|
"dotenv": "^16.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fast-average-color-node": "^1.0.3",
|
"fast-average-color-node": "^1.0.3",
|
||||||
"kuroshiro": "^1.2.0",
|
"kuroshiro": "^1.2.0",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ var authenticationApi = new vrchat.AuthenticationApi(configuration);
|
|||||||
authenticationApi.getCurrentUser().then(console.log);
|
authenticationApi.getCurrentUser().then(console.log);
|
||||||
|
|
||||||
var usersApi = new vrchat.UsersApi(configuration);
|
var usersApi = new vrchat.UsersApi(configuration);
|
||||||
|
var worldsApi = new vrchat.WorldsApi(configuration);
|
||||||
|
|
||||||
var status2icon = {
|
var status2icon = {
|
||||||
"join me": '🔵',
|
"join me": '🔵',
|
||||||
@@ -25,16 +26,40 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateUserStatuses() {
|
async function updateUserStatuses() {
|
||||||
for (let {channel, userId} of vrcul) {
|
for (let x of vrcul) {
|
||||||
try {
|
try {
|
||||||
channel = client.channels.resolve(channel);
|
|
||||||
let user = (await usersApi.getUser(userId)).data;
|
let user = (await usersApi.getUser(x.userId)).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 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);
|
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) {
|
} 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 => {
|
client.on("interactionCreate", async i => {
|
||||||
if (i.commandName == "addvru") {
|
if (i.commandName == "addvru") {
|
||||||
try {
|
try {
|
||||||
|
await i.deferReply();
|
||||||
let u = i.options.getString("user");
|
let u = i.options.getString("user");
|
||||||
let user = (await usersApi[u.startsWith("usr_") ? 'getUser' : 'getUserByName'](u)).data;
|
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 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});
|
vrcul.push({channel: channel.id, userId: user.id});
|
||||||
fs.writeFileSync("data/vrcul.json", JSON.stringify(vrcul));
|
fs.writeFileSync("data/vrcul.json", JSON.stringify(vrcul));
|
||||||
await i.reply(channel.toString());
|
await i.editReply(channel.toString());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
i.reply(error.message);
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user