Compare commits

...

19 Commits

Author SHA1 Message Date
d9a1b9b99c disable broken 2022-04-01 23:05:40 -07:00
6fe26e7837 DEBUG AGAIN FUCK 2022-04-01 22:53:50 -07:00
afc2b10a86 fix bug 2022-04-01 22:32:08 -07:00
3369bd521d DEBUG BITCH 2022-04-01 22:09:07 -07:00
d52aff9936 ok 2022-04-01 22:03:00 -07:00
a44f81bddf wtff 2022-04-01 21:56:31 -07:00
2925c3d788 recreate missing channel 2022-04-01 21:45:26 -07:00
9dcd27c45f wat 2022-04-01 21:04:39 -07:00
e882ee7e57 fix private 2022-04-01 21:04:12 -07:00
20ecfb3e84 debug 2022-04-01 20:54:03 -07:00
16f4b7eaf9 fix 2022-04-01 20:53:25 -07:00
940d3f6c30 show world in 2022-04-01 20:37:44 -07:00
4252a2f060 fucking env variables 2022-03-31 18:38:00 -07:00
f602638aae fix 2022-03-31 18:11:15 -07:00
c9c45d17e7 need defer 2022-03-31 18:01:55 -07:00
bf27b6519a fix 2022-03-31 17:59:22 -07:00
085b51a95d fix 2022-03-31 17:57:06 -07:00
fc41f8ad2f a2 2022-03-31 17:55:55 -07:00
d6d05f6a72 vrchat function only 2022-03-31 17:42:15 -07:00
5 changed files with 66 additions and 39 deletions

View File

@ -8,5 +8,5 @@ var client = module.exports = new Discord.Client({
client.login(config.token).then(async () => {
console.log("ready");
(await client.channels.fetch(config.bot_channel))?.send('a');
(await client.channels.fetch(config.bot_channel))?.send('a2');
});

View File

@ -1,21 +1,6 @@
process.title = "lamp discord bot";
process.on("unhandledRejection", error => {
console.error("Unhandled Rejection:\n" + error.stack);
});
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("dotenv").config();
require("./vrchat");

14
package-lock.json generated
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",

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",

View File

@ -1,7 +1,6 @@
var vrchat = require("vrchat");
var client = require("./client");
var config = require("./config");
var commands = require("./commands");
var fs = require("fs");
var configuration = new vrchat.Configuration(config.vrchat_configuration);
@ -10,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": '🔵',
@ -26,46 +26,73 @@ 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);
}
}
}
module.exports.interval = setInterval(updateUserStatuses, 1000*60*5);
commands.push({
name: "addvru",
description: "Add VRChat user to status monitor",
options: [
{
name: "user",
description: "User ID or username",
type: "STRING",
required: true
}
],
exec: async i => {
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;
}