Compare commits

..

1 Commits

Author SHA1 Message Date
lamp 1316460838 vrchat command only 2022-03-31 17:37:49 -07:00
5 changed files with 28 additions and 111 deletions
+1 -1
View File
@@ -8,5 +8,5 @@ var client = module.exports = new Discord.Client({
client.login(config.token).then(async () => { client.login(config.token).then(async () => {
console.log("ready"); console.log("ready");
(await client.channels.fetch(config.bot_channel))?.send('a2'); (await client.channels.fetch(config.bot_channel))?.send('a');
}); });
+16 -1
View File
@@ -1,6 +1,21 @@
process.title = "lamp discord bot";
process.on("unhandledRejection", error => { process.on("unhandledRejection", error => {
console.error("Unhandled Rejection:\n" + error.stack); console.error("Unhandled Rejection:\n" + error.stack);
}); });
require("dotenv").config(); require("./util"); // global variables set in here
require("./client");
require("./discord-misc");
require('./eval-exec');
require('./colors');
require('./www');
require('./pinboard');
require('./pixiv-embedder');
require('./translate2');
require('./world-clock');
require('./buttonthing');
require("./activitytracker");
require("./vocabularygame");
require("./pixiv-subscribe");
require("./count-cmd");
require("./vrchat"); require("./vrchat");
-14
View File
@@ -8,7 +8,6 @@
"@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",
@@ -495,14 +494,6 @@
"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",
@@ -1966,11 +1957,6 @@
"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",
-1
View File
@@ -3,7 +3,6 @@
"@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",
+11 -94
View File
@@ -1,98 +1,15 @@
var vrchat = require("vrchat");
var client = require("./client");
var config = require("./config");
var fs = require("fs");
var configuration = new vrchat.Configuration(config.vrchat_configuration);
var authenticationApi = new vrchat.AuthenticationApi(configuration); var commands = require("./commands");
authenticationApi.getCurrentUser().then(console.log); commands.push({
name: "addvru",
var usersApi = new vrchat.UsersApi(configuration); description: "Add VRChat user to status monitor",
var worldsApi = new vrchat.WorldsApi(configuration); options: [
{
var status2icon = { name: "user",
"join me": '🔵', description: "User ID or username",
"active": '🟢', type: "STRING",
"ask me": '🟠', required: true
"busy": '🔴',
"offline": '⚫'
}
try {
var vrcul = JSON.parse(fs.readFileSync("data/vrcul.json"), "utf8");
} catch(error) {
var vrcul = [];
}
async function updateUserStatuses() {
for (let x of vrcul) {
try {
let user = (await usersApi.getUser(x.userId)).data;
let status_icon = user.state == "online" ? status2icon[user.status] : '⚫';
let nn = `${status_icon} ${user.displayName}`;
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.stack);
}
}
}
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 nn = `${status_icon} ${user.displayName}`;
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.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;
}