Compare commits

..

3 Commits

Author SHA1 Message Date
1316460838 vrchat command only 2022-03-31 17:37:49 -07:00
ed76ad6044 small refactor 2022-03-31 17:33:48 -07:00
c0036e7471 fix 2022-03-31 17:28:01 -07:00
4 changed files with 80 additions and 136 deletions

View File

@ -10,80 +10,3 @@ client.login(config.token).then(async () => {
console.log("ready");
(await client.channels.fetch(config.bot_channel))?.send('a');
});
/* small misc stuff here */
////////////////////////////////////////////////////////////////////////////////////////
client.on("guildMemberAdd", member => {
if (member.guild.id != config.guild) return;
// add role
member.roles.add(member.user.bot ? config.bot_role : config.human_role);
// welcome message
client.channels.resolve(config.default_channel)?.send(
`Welcome ${member}. Please tell from where you entered this server and some other info about yourself in order to gain access to message history.`
);
});
// join message
/*client.on("messageDelete", message => {
if (message.channel.id != config.default_channel) return;
if (message.type != "GUILD_MEMBER_JOIN") return;
client.channels.resolve(config.default_channel)?.send(
`sussy baka ${message.author} deleted their join message ||(from <t:${Math.floor(message.createdAt.valueOf()/1000)}>)||`
);
});*/
client.on("guildMemberRemove", member => {
if (member.guild.id != config.guild) return;
// leave message
client.channels.resolve(config.default_channel)?.send(random([
`${member.user.username} left`,
`${member.user.username} disappeared`,
`${member.user.username.toLowerCase()} is gone`
]));
});
client.on("messageCreate", message => {
// comment thread on announcements
message.channel.id == config.announcement_channel && message.startThread({name: "Comments"});
// stupid m bot
message.author.id == "732072478519722096" && message.content.endsWith("is bad letter m is much better") && message.delete();
});
// add reactions to video and audio
{
let a = async m => {
if (m.guild?.id != config.guild) return;
if ((m.embeds.some(e => e.type == "video") || m.attachments.some(a => a.contentType?.startsWith('video'))) && !m.g) {
m.g = true;
m.react(config.mi_emoji);
}
if (m.attachments.some(a => a.contentType?.startsWith('audio')) && !m.d) {
m.d = true;
m.react(config.ki_emoji);
}
}
client.on("messageCreate", a);
client.on("messageUpdate", (r, q) => a(q));
}
// thing to access archived channels
client.on("voiceStateUpdate", (oldState, newState) => {
if (newState.guild.id != config.guild) return;
if (oldState.channelId != config.archive_portal_voice_channel && newState.channelId == config.archive_portal_voice_channel) {
// join
newState.member?.roles.add(config.view_archived_channels_role);
} else if (oldState.channelId == config.archive_portal_voice_channel && newState.channelId != config.archive_portal_voice_channel) {
// leave
newState.member?.roles.remove(config.view_archived_channels_role);
}
});
// save deleted emojis
client.on("emojiDelete", emoji => {
client.channels.resolve(config.bot_channel)?.send({
content: "emoji deleted",
files: [{attachment: emoji.url, name: `${emoji.name}.${emoji.url.split('.').pop()}`}]
});
});

76
discord-misc.js Normal file
View File

@ -0,0 +1,76 @@
var client = require("./client.js");
var config = require("./config");
client.on("guildMemberAdd", member => {
if (member.guild.id != config.guild) return;
// add role
member.roles.add(member.user.bot ? config.bot_role : config.human_role);
// welcome message
client.channels.resolve(config.default_channel)?.send(
`Welcome ${member}. Please tell from where you entered this server and some other info about yourself in order to gain access to message history.`
);
});
// join message
/*client.on("messageDelete", message => {
if (message.channel.id != config.default_channel) return;
if (message.type != "GUILD_MEMBER_JOIN") return;
client.channels.resolve(config.default_channel)?.send(
`sussy baka ${message.author} deleted their join message ||(from <t:${Math.floor(message.createdAt.valueOf()/1000)}>)||`
);
});*/
client.on("guildMemberRemove", member => {
if (member.guild.id != config.guild) return;
// leave message
client.channels.resolve(config.default_channel)?.send(random([
`${member.user.username} left`,
`${member.user.username} disappeared`,
`${member.user.username.toLowerCase()} is gone`
]));
});
client.on("messageCreate", message => {
// comment thread on announcements
message.channel.id == config.announcement_channel && message.startThread({name: "Comments"});
// stupid m bot
message.author.id == "732072478519722096" && message.content.endsWith("is bad letter m is much better") && message.delete();
});
// add reactions to video and audio
{
let a = async m => {
if (m.guild?.id != config.guild) return;
if ((m.embeds.some(e => e.type == "video") || m.attachments.some(a => a.contentType?.startsWith('video'))) && !m.g) {
m.g = true;
m.react(config.mi_emoji);
}
if (m.attachments.some(a => a.contentType?.startsWith('audio')) && !m.d) {
m.d = true;
m.react(config.ki_emoji);
}
}
client.on("messageCreate", a);
client.on("messageUpdate", (r, q) => a(q));
}
// thing to access archived channels
client.on("voiceStateUpdate", (oldState, newState) => {
if (newState.guild.id != config.guild) return;
if (oldState.channelId != config.archive_portal_voice_channel && newState.channelId == config.archive_portal_voice_channel) {
// join
newState.member?.roles.add(config.view_archived_channels_role);
} else if (oldState.channelId == config.archive_portal_voice_channel && newState.channelId != config.archive_portal_voice_channel) {
// leave
newState.member?.roles.remove(config.view_archived_channels_role);
}
});
// save deleted emojis
client.on("emojiDelete", emoji => {
client.channels.resolve(config.bot_channel)?.send({
content: "emoji deleted",
files: [{attachment: emoji.url, name: `${emoji.name}.${emoji.url.split('.').pop()}`}]
});
});

View File

@ -5,6 +5,7 @@ process.on("unhandledRejection", error => {
require("./util"); // global variables set in here
require("./client");
require("./discord-misc");
require('./eval-exec');
require('./colors');
require('./www');

View File

@ -1,47 +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);
var authenticationApi = new vrchat.AuthenticationApi(configuration);
authenticationApi.getCurrentUser().then(console.log);
var usersApi = new vrchat.UsersApi(configuration);
var status2icon = {
"join me": '🔵',
"active": '🟢',
"ask me": '🟠',
"busy": '🔴',
"offline": '⚫'
}
try {
var vrcul = JSON.parse(fs.readFileSync("data/vrcul.json"), "utf8");
} catch(error) {
var vrcul = [];
}
async function updateUserStatuses() {
for (let {channel, userId} of vrcul) {
try {
channel = client.channels.resolve(channel);
let user = await usersApi.getUser(userId);
let status_icon = user.state == "online" ? status2icon(user.status) : '⚫';
let nn = `${status_icon} ${user.displayName}`;
if (nn != channel.name)
await channel.setName(nn);
} catch (error) {
console.error("vrcus", error.message);
}
}
}
module.exports.interval = setInterval(updateUserStatuses, 1000*60*5);
commands.push({
name: "addvru",
description: "Add VRChat user to status monitor",
@ -52,20 +11,5 @@ commands.push({
type: "STRING",
required: true
}
],
exec: async i => {
try {
let u = i.options.getString("user");
let user = await usersApi[u.startsWith("usr_") ? 'getUser' : 'getUserByName'](u);
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);
vrcul.push({channel: channel.id, userId: user.id});
fs.writeFileSync("data/vrcul.json", JSON.stringify(vrcul));
await i.reply(channel.toString());
} catch (error) {
i.reply(error.message);
}
}
]
});