a
This commit is contained in:
commit
ae2309cb62
4 changed files with 376 additions and 0 deletions
63
index.js
Normal file
63
index.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
import { REST, Routes, Client, Events, GatewayIntentBits } from 'discord.js';
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdir, cp } from 'node:fs/promises';
|
||||
|
||||
let sessions = {};
|
||||
|
||||
const { TOKEN, ID } = process.env;
|
||||
//const commands = [];
|
||||
//const rest = new REST({ version: '10' }).setToken(TOKEN);
|
||||
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
//await rest.put(Routes.applicationCommands(ID), { body: commands });
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages] });
|
||||
|
||||
client.on(Events.ClientReady, readyClient => {
|
||||
console.log(`Logged in as ${readyClient.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on(Events.MessageCreate, async interaction => {
|
||||
if (interaction.author.bot) return;
|
||||
let msg = interaction.content;
|
||||
let channel = interaction.channel.name;
|
||||
|
||||
if (channel.indexOf('play') == -1 && channel.indexOf('bot') && channel.indexOf('spam')) return;
|
||||
|
||||
let id = interaction.author.id;
|
||||
|
||||
if (!sessions[id]) {
|
||||
try {
|
||||
await mkdir(`./bin/${id}`);
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
sessions[id] = spawn('../elem', [id], {
|
||||
'cwd': `./bin/${id}`
|
||||
});
|
||||
|
||||
sessions[id].stdout.on('data', (chunk) => {
|
||||
if (chunk.toString().length > 1) {
|
||||
interaction.channel.send(chunk.toString());
|
||||
}
|
||||
});
|
||||
sessions[id].on('close', () => {
|
||||
delete sessions[id];
|
||||
})
|
||||
}
|
||||
|
||||
let msgs = msg.split('\n');
|
||||
|
||||
setTimeout(async function () {
|
||||
sessions[id].stdin.write(msgs[0] + '\n');
|
||||
}, 100);
|
||||
});
|
||||
|
||||
client.login(TOKEN);
|
Loading…
Add table
Add a link
Reference in a new issue