refactor(discord-bot): move differents modes in separate files
This commit is contained in:
34
apps/discord-bot/src/modes/user.ts
Normal file
34
apps/discord-bot/src/modes/user.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user