refactor(discord-bot): move differents modes in separate files

This commit is contained in:
Pihkaal
2025-12-04 18:43:53 +01:00
parent 2ad0fcc623
commit 464f367c80
4 changed files with 145 additions and 94 deletions

View File

@@ -0,0 +1,34 @@
import type { Client, TextChannel } from "discord.js";
import { ChannelType } from "discord.js";
import * as readline from "node:readline";
export const setupUserMode = (client: Client, channelId: string) => {
client.on("clientReady", (client) => {
console.log(`Logged in as ${client.user.username}`);
const chan = client.channels.cache.get(channelId);
if (chan?.type !== ChannelType.GuildText) {
console.error("ERROR: invalid channel");
process.exit(1);
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: `${chan.name} ~ `,
});
rl.prompt();
rl.on("line", async (line) => {
if (line.trim().length > 0) {
await (chan as TextChannel).send(line);
}
rl.prompt();
});
rl.on("close", () => {
process.exit(0);
});
});
};