Files
lbf-bot/apps/discord-bot/src/modes/user.ts
2025-12-05 20:24:17 +01:00

37 lines
948 B
TypeScript

import { logger } from "@lbf-bot/utils";
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) => {
logger.info(`Client ready`);
logger.info(`Connected 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);
});
});
};