Compare commits
19 Commits
master
...
vrchat-hac
Author | SHA1 | Date | |
---|---|---|---|
d9a1b9b99c | |||
6fe26e7837 | |||
afc2b10a86 | |||
3369bd521d | |||
d52aff9936 | |||
a44f81bddf | |||
2925c3d788 | |||
9dcd27c45f | |||
e882ee7e57 | |||
20ecfb3e84 | |||
16f4b7eaf9 | |||
940d3f6c30 | |||
4252a2f060 | |||
f602638aae | |||
c9c45d17e7 | |||
bf27b6519a | |||
085b51a95d | |||
fc41f8ad2f | |||
d6d05f6a72 |
@ -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('a');
|
(await client.channels.fetch(config.bot_channel))?.send('a2');
|
||||||
});
|
});
|
||||||
|
17
index.js
17
index.js
@ -1,21 +1,6 @@
|
|||||||
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("./util"); // global variables set in here
|
require("dotenv").config();
|
||||||
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
package-lock.json
generated
14
package-lock.json
generated
@ -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",
|
||||||
|
71
vrchat.js
71
vrchat.js
@ -1,7 +1,6 @@
|
|||||||
var vrchat = require("vrchat");
|
var vrchat = require("vrchat");
|
||||||
var client = require("./client");
|
var client = require("./client");
|
||||||
var config = require("./config");
|
var config = require("./config");
|
||||||
var commands = require("./commands");
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var configuration = new vrchat.Configuration(config.vrchat_configuration);
|
var configuration = new vrchat.Configuration(config.vrchat_configuration);
|
||||||
@ -10,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": '🔵',
|
||||||
@ -26,46 +26,73 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.interval = setInterval(updateUserStatuses, 1000*60*5);
|
module.exports.interval = setInterval(updateUserStatuses, 1000*60*5);
|
||||||
|
|
||||||
commands.push({
|
|
||||||
name: "addvru",
|
|
||||||
description: "Add VRChat user to status monitor",
|
|
||||||
options: [
|
client.on("interactionCreate", async i => {
|
||||||
{
|
if (i.commandName == "addvru") {
|
||||||
name: "user",
|
|
||||||
description: "User ID or username",
|
|
||||||
type: "STRING",
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
exec: async i => {
|
|
||||||
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user