Compare commits

...

23 Commits

Author SHA1 Message Date
ab43d009b0 masto auto reconnect stream 2022-07-18 13:02:23 -07:00
b18c90996e fix 2022-07-17 22:21:01 -07:00
1f4dec517f masto bridge v1 2022-07-17 22:17:24 -07:00
1704537a13 fix missing eval emoji 2022-07-17 21:28:15 -07:00
69c5a106b5 2022-07-17 21:27:40 -07:00
a2966b1475 fix [object Object] 2022-07-17 21:26:54 -07:00
d04200742d fix undefined unhandled rejection 2022-07-17 21:24:35 -07:00
fbb082fee8 init masto stream (testing) 2022-07-17 21:21:13 -07:00
bb80d22568 2022-07-17 21:07:05 -07:00
721435f039 icon thing 2022-05-20 19:15:30 -07:00
e85d88de69 delete masto 2022-05-20 19:13:11 -07:00
a4730289a0 fuk u type explicicy 2022-05-10 22:21:10 -07:00
02be479a15 fix size options 2022-05-10 22:18:38 -07:00
1b2df7a1cb fix formatting break embed 2022-05-10 14:20:26 -07:00
7eb01dda9d command to get emoji url 2022-05-10 14:03:15 -07:00
c130ef1506 fix bug 2022-05-08 00:13:50 -07:00
660234acfd delete archive command and permissions set 2022-05-07 22:36:08 -07:00
c0470e89b6 mastodon pixiv bot 2022-05-07 22:32:09 -07:00
823c398a5a disable verification 2022-04-11 22:58:36 -07:00
9b84e4ff7c delay the welcome message 2022-04-06 01:52:04 -07:00
e19f11acae command to change server icon 2022-04-06 01:25:03 -07:00
0fcd5f125c rm vrchat 2022-04-06 01:22:30 -07:00
1316460838 vrchat command only 2022-03-31 17:37:49 -07:00
10 changed files with 630 additions and 295 deletions

View File

@ -38,32 +38,6 @@ var commands = module.exports = [
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",
description: "View a user's original avatar (and save permanently as attachment)",
@ -123,7 +97,7 @@ var commands = module.exports = [
exec: i => commands.find(x => x.name == "steal").exec(i)
},
{
name: "setbanner",
name: "setserverbanner",
description: "Set the server banner image",
options: [
{
@ -150,6 +124,86 @@ var commands = module.exports = [
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}`);
}
}
];
@ -162,14 +216,5 @@ client.once("ready", async () => {
let guild_commands = commands.filter(x => !x.global);
let guild = client.guilds.resolve(config.guild);
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);
});

View File

@ -8,8 +8,9 @@ module.exports = {
human_role: "672956630962274306",
bot_role: "673671040010027034",
inactive_role: "892869309603389500",
verified_role: "949064806030254130",
view_archived_channels_role: "916056534402863125",
eval_undefined_emoji: "707729833601531935",
eval_undefined_emoji: "🅱️",
mi_emoji: "887931046086185060",
ki_emoji: "887935846710394910",
default_channel: "949831184957980722",
@ -77,5 +78,11 @@ module.exports = {
vrchat_configuration: {
username: process.env.VRCHAT_USERNAME,
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,9 +7,12 @@ client.on("guildMemberAdd", member => {
// add role
member.roles.add(member.user.bot ? config.bot_role : config.human_role);
// welcome message
/*setTimeout(() => {
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.`
);
}, 3000);*/
member.roles.add(config.verified_role);
});
// join message
/*client.on("messageDelete", message => {
@ -74,3 +77,5 @@ client.on("emojiDelete", emoji => {
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("!>")) {
with (message) {
try {
var x = await eval(message.content.substr(2).trim());
var x = await eval(message.content.substring(2).trim());
} catch(e) {
var x = e.message;
}

View File

@ -1,6 +1,6 @@
process.title = "lamp discord bot";
process.on("unhandledRejection", error => {
console.error("Unhandled Rejection:\n" + error.stack);
console.error("Unhandled Rejection:\n", error.stack || error);
});
require("./util"); // global variables set in here
@ -18,4 +18,4 @@ require("./activitytracker");
require("./vocabularygame");
require("./pixiv-subscribe");
require("./count-cmd");
require("./vrchat");
require("./masto");

39
masto.js Normal file
View File

@ -0,0 +1,39 @@
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);
}
})();
});

661
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
"kuroshiro": "^1.2.0",
"kuroshiro-analyzer-kuromoji": "^1.1.0",
"libsodium-wrappers": "^0.7.9",
"node-fetch": "^2.6.1",
"vrchat": "^1.6.9"
"masto": "^4.4.0",
"node-fetch": "^2.6.1"
}
}

View File

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

View File

@ -1,71 +0,0 @@
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)).data;
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",
options: [
{
name: "user",
description: "User ID or username",
type: "STRING",
required: true
}
],
exec: async i => {
try {
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);
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);
}
}
});