Compare commits

..

17 Commits

Author SHA1 Message Date
lamp d04200742d fix undefined unhandled rejection 2022-07-17 21:24:35 -07:00
lamp fbb082fee8 init masto stream (testing) 2022-07-17 21:21:13 -07:00
lamp bb80d22568 2022-07-17 21:07:05 -07:00
lamp 721435f039 icon thing 2022-05-20 19:15:30 -07:00
lamp e85d88de69 delete masto 2022-05-20 19:13:11 -07:00
lamp a4730289a0 fuk u type explicicy 2022-05-10 22:21:10 -07:00
lamp 02be479a15 fix size options 2022-05-10 22:18:38 -07:00
lamp 1b2df7a1cb fix formatting break embed 2022-05-10 14:20:26 -07:00
lamp 7eb01dda9d command to get emoji url 2022-05-10 14:03:15 -07:00
lamp c130ef1506 fix bug 2022-05-08 00:13:50 -07:00
lamp 660234acfd delete archive command and permissions set 2022-05-07 22:36:08 -07:00
lamp c0470e89b6 mastodon pixiv bot 2022-05-07 22:32:09 -07:00
lamp 823c398a5a disable verification 2022-04-11 22:58:36 -07:00
lamp 9b84e4ff7c delay the welcome message 2022-04-06 01:52:04 -07:00
lamp e19f11acae command to change server icon 2022-04-06 01:25:03 -07:00
lamp 0fcd5f125c rm vrchat 2022-04-06 01:22:30 -07:00
lamp 1316460838 vrchat command only 2022-03-31 17:37:49 -07:00
10 changed files with 615 additions and 333 deletions
+1 -1
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('a2'); (await client.channels.fetch(config.bot_channel))?.send('a');
}); });
+81 -36
View File
@@ -38,32 +38,6 @@ 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)",
@@ -123,7 +97,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: "setbanner", name: "setserverbanner",
description: "Set the server banner image", description: "Set the server banner image",
options: [ options: [
{ {
@@ -150,6 +124,86 @@ 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}`);
}
} }
]; ];
@@ -162,14 +216,5 @@ 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);
}); });
+5
View File
@@ -8,6 +8,7 @@ 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: "707729833601531935", eval_undefined_emoji: "707729833601531935",
mi_emoji: "887931046086185060", mi_emoji: "887931046086185060",
@@ -77,5 +78,9 @@ 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
} }
} }
+8 -3
View File
@@ -7,9 +7,12 @@ 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
client.channels.resolve(config.default_channel)?.send( /*setTimeout(() => {
`Welcome ${member}. Please tell from where you entered this server and some other info about yourself in order to gain access to message history.` 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 // join message
/*client.on("messageDelete", message => { /*client.on("messageDelete", message => {
@@ -74,3 +77,5 @@ client.on("emojiDelete", emoji => {
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);
+18 -3
View File
@@ -1,6 +1,21 @@
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 || error));
}); });
require("dotenv").config(); require("./util"); // global variables set in here
require("./vrchat"); 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("./masto");
+15
View File
@@ -0,0 +1,15 @@
var {login} = require("masto");
var config = require("./config");
var client = require("./client");
client.once("ready", async () => {
var donger = await login(config.masto);
module.exports = donger;
var stream = await donger.stream.streamUser();
stream.on("update", toot => {
console.debug("toot", toot); // testing
});
});
+482 -187
View File
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -3,13 +3,12 @@
"@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",
"node-fetch": "^2.6.1", "masto": "^4.4.0",
"vrchat": "^1.6.9" "node-fetch": "^2.6.1"
} }
} }
+2 -1
View File
@@ -17,9 +17,10 @@ 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),
[`https://www.pixiv.net/en/artworks/${newPosts[i].id}`], [url],
undefined, undefined,
true true
); );
-98
View File
@@ -1,98 +0,0 @@
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;
}