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
11 changed files with 336 additions and 644 deletions

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('a'); (await client.channels.fetch(config.bot_channel))?.send('a2');
}); });

View File

@ -38,6 +38,32 @@ var commands = module.exports = [
i.reply(owo); i.reply(owo);
} }
}, },
{
name: "archive",
description: "Delete a channel without actually deleting it",
options: [
{
name: "channel",
description: "channel",
type: "CHANNEL",
required: true
}
],
defaultPermission: false,
permissions: [
{
id: config.admin_role,
type: "ROLE",
permission: true
}
],
exec: async i => {
let channel = i.options.getChannel("channel");
await channel.setParent(config.archive_category);
await channel.lockPermissions();
await i.reply({content: channel.toString()});
}
},
{ {
name: "avatar", name: "avatar",
description: "View a user's original avatar (and save permanently as attachment)", description: "View a user's original avatar (and save permanently as attachment)",
@ -97,7 +123,7 @@ var commands = module.exports = [
exec: i => commands.find(x => x.name == "steal").exec(i) exec: i => commands.find(x => x.name == "steal").exec(i)
}, },
{ {
name: "setserverbanner", name: "setbanner",
description: "Set the server banner image", description: "Set the server banner image",
options: [ options: [
{ {
@ -124,86 +150,6 @@ var commands = module.exports = [
await i.reply(error.message); await i.reply(error.message);
} }
} }
},
{
name: "setservericon",
description: "Change the server icon",
options: [
{
name: "url",
description: "HTTP(S) URL to an image",
type: "STRING"
}
],
exec: async i => {
var url = i.options.getString("url");
try {
if (!url) {
await i.guild.setIcon(null);
await i.reply("cleared the server icon");
} else {
if (/^https?:\/\//i.test(url)) {
await i.guild.setIcon(url);
await i.reply(url);
} else {
await i.reply("http image url only!");
}
}
} catch (error) {
await i.reply(error.message);
}
}
},
{
name: "getemoji",
description: "Generate a URL for an emoji",
options: [
{
name: "emoji",
description: "The emoji (code) or the name of the emoji (case-sensitive)",
type: "STRING",
required: true
},
{
name: "format",
description: "choose image format",
type: "STRING",
choices: [
{name: "PNG", value: "png"},
{name: "JPG", value: "jpg"},
{name: "WEBP", value: "webp"},
{name: "GIF", value: "gif"}
]
},
{
name: "size",
description: "choose image size",
type: "INTEGER",
choices: "16,20,22,24,28,32,40,44,48,56,60,64,80,96,100,128".split(',').map(s => ({name: s, value: Number(s)}))
}
],
exec: i => {
var emojiname = i.options.getString("emoji");
if (emojiname.startsWith('<') && emojiname.endsWith('>')) emoji = Discord.Util.parseEmoji(emojiname);
else {
if (emojiname.startsWith(':')) emojiname = emojiname.slice(1);
if (emojiname.endsWith(':')) emojiname = emojiname.slice(-1);
var emoji = client.emojis.cache.find(e => e.name == emojiname);
if (!emoji) emoji = client.emojis.cache.find(e => e.name.toLowerCase() == emojiname.toLowerCase());
if (!emoji) return void i.reply(`could not find emoji named ${emojiname}`);
}
if (!emoji.id) return void i.reply(`invalid input`);
var qs = [];
var size = i.options.getInteger("size");
if (size) qs.push(`size=${size}`);
var format = i.options.getString("format");
if (!format) format = emoji.animated ? "gif" : "png";
if (format == "gif" && !emoji.animated) return void i.reply(`Non-animated emoji is not available as GIF.`);
if (format == "webp") qs.push(`quality=lossless`);
var url = `https://media.discordapp.net/emojis/${emoji.id}.${format}`;
if (qs.length > 0) url += '?' + qs.join('&');
i.reply(`${emoji.name}.${format}\n${url}`);
}
} }
]; ];
@ -216,5 +162,14 @@ client.once("ready", async () => {
let guild_commands = commands.filter(x => !x.global); let guild_commands = commands.filter(x => !x.global);
let guild = client.guilds.resolve(config.guild); let guild = client.guilds.resolve(config.guild);
await guild.commands.set(guild_commands); await guild.commands.set(guild_commands);
await guild.commands.permissions.set({
fullPermissions: guild_commands.map(local_command => {
let discord_command = guild.commands.cache.find(discord_command => local_command.name == discord_command.name);
return {
id: discord_command.id,
permissions: local_command.permissions || []
}
})
});
await client.application.commands.set(global_commands); await client.application.commands.set(global_commands);
}); });

View File

@ -8,9 +8,8 @@ module.exports = {
human_role: "672956630962274306", human_role: "672956630962274306",
bot_role: "673671040010027034", bot_role: "673671040010027034",
inactive_role: "892869309603389500", inactive_role: "892869309603389500",
verified_role: "949064806030254130",
view_archived_channels_role: "916056534402863125", view_archived_channels_role: "916056534402863125",
eval_undefined_emoji: "🅱️", eval_undefined_emoji: "707729833601531935",
mi_emoji: "887931046086185060", mi_emoji: "887931046086185060",
ki_emoji: "887935846710394910", ki_emoji: "887935846710394910",
default_channel: "949831184957980722", default_channel: "949831184957980722",
@ -78,11 +77,5 @@ module.exports = {
vrchat_configuration: { vrchat_configuration: {
username: process.env.VRCHAT_USERNAME, username: process.env.VRCHAT_USERNAME,
password: process.env.VRCHAT_PASSWORD password: process.env.VRCHAT_PASSWORD
}, }
masto: {
url: "https://mastodong.lol",
accessToken: process.env.MASTO_TOKEN
},
masto_account_id: "108643271047165149",
masto_webhook: process.env.DISCORD_WEBHOOK_FOR_MASTO
} }

View File

@ -7,12 +7,9 @@ client.on("guildMemberAdd", member => {
// add role // add role
member.roles.add(member.user.bot ? config.bot_role : config.human_role); member.roles.add(member.user.bot ? config.bot_role : config.human_role);
// welcome message // welcome message
/*setTimeout(() => { client.channels.resolve(config.default_channel)?.send(
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.`
`Welcome ${member}. Please tell from where you entered this server and some other info about yourself in order to gain access to message history.` );
);
}, 3000);*/
member.roles.add(config.verified_role);
}); });
// join message // join message
/*client.on("messageDelete", message => { /*client.on("messageDelete", message => {
@ -76,6 +73,4 @@ client.on("emojiDelete", emoji => {
content: "emoji deleted", content: "emoji deleted",
files: [{attachment: emoji.url, name: `${emoji.name}.${emoji.url.split('.').pop()}`}] files: [{attachment: emoji.url, name: `${emoji.name}.${emoji.url.split('.').pop()}`}]
}); });
}); });
//g=setInterval(() => client.guilds.resolve(config.guild)?.setIcon(`mf/${Math.floor(Math.random()*14548)}.png`), 1800000);

View File

@ -9,7 +9,7 @@ client.on("messageCreate", async function (message) {
if (message.content.startsWith("!>")) { if (message.content.startsWith("!>")) {
with (message) { with (message) {
try { try {
var x = await eval(message.content.substring(2).trim()); var x = await eval(message.content.substr(2).trim());
} catch(e) { } catch(e) {
var x = e.message; var x = e.message;
} }

View File

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

View File

@ -1,39 +0,0 @@
var {login} = require("masto");
var config = require("./config");
var client = require("./client");
var {WebhookClient} = require("discord.js");
var webhook = new WebhookClient({url: config.masto_webhook});
module.exports.webhook = webhook;
client.once("ready", async () => {
var donger = await login(config.masto);
console.log("donger logged in");
module.exports.donger = donger;
(async function openStream() {
try {
var stream = await donger.stream.streamUser();
module.exports.stream = stream;
stream.on("update", toot => {
if (toot.account.id != config.masto_account_id) return;
if (toot.visibility != "public") return;
if (toot.inReplyToAccountId && toot.inReplyToAccountId != toot.account.id) return;
webhook.send(toot.url || toot.reblog.url); //todo maybe custom embed
//todo maybe handle deletes
});
stream.ws.on("close", () => {
console.log("donger stream closed");
setTimeout(openStream, 10000);
});
} catch (error) {
console.error("donger stream", error.message);
setTimeout(openStream, 60000);
}
})();
});

669
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,13 @@
"@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",
"kuroshiro-analyzer-kuromoji": "^1.1.0", "kuroshiro-analyzer-kuromoji": "^1.1.0",
"libsodium-wrappers": "^0.7.9", "libsodium-wrappers": "^0.7.9",
"masto": "^4.4.0", "node-fetch": "^2.6.1",
"node-fetch": "^2.6.1" "vrchat": "^1.6.9"
} }
} }

View File

@ -17,10 +17,9 @@ async function check(tag, channel) {
} else break; } else break;
} }
for (let i = newPosts.length - 1; i >= 0; i--) { for (let i = newPosts.length - 1; i >= 0; i--) {
let url = `https://www.pixiv.net/en/artworks/${newPosts[i].id}`;
await embedPixiv( await embedPixiv(
client.channels.resolve(channel), client.channels.resolve(channel),
[url], [`https://www.pixiv.net/en/artworks/${newPosts[i].id}`],
undefined, undefined,
true true
); );

98
vrchat.js Normal file
View File

@ -0,0 +1,98 @@
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);
authenticationApi.getCurrentUser().then(console.log);
var usersApi = new vrchat.UsersApi(configuration);
var worldsApi = new vrchat.WorldsApi(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 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;
}