41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
const { Client, Events, GatewayIntentBits } = require("discord.js");
|
|
const { token, id } = require("./config.json");
|
|
const { spawn } = require("child_process");
|
|
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.MessageContent,
|
|
],
|
|
});
|
|
|
|
client.once(Events.ClientReady, c => {
|
|
console.log(`okay cool, ${c.user.tag}`);
|
|
console.log(
|
|
`Invite link: https://discord.com/oauth2/authorize?client_id=${id}&permissions=3072&scope=bot`
|
|
);
|
|
});
|
|
|
|
client.login(token);
|
|
|
|
client.on("messageCreate", message => {
|
|
if (message.author.id == id || !message.mentions.has(id)) return;
|
|
try {
|
|
let process = spawn("./target/release/slimp", [message.content], {
|
|
stdio: "pipe",
|
|
});
|
|
process.stdout.on("data", data =>
|
|
message.reply(mk_message(data.toString()))
|
|
);
|
|
process.stderr.on("data", data => console.error(data.toString()));
|
|
} catch (e) {
|
|
console.error(e);
|
|
message.reply(":(");
|
|
}
|
|
});
|
|
|
|
function mk_message(str) {
|
|
return "```lisp\n" + str.slice(0, 1975) + "```";
|
|
}
|