refactor: improve code quality
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
import { logger } from "@lbf-bot/utils";
|
||||
import type { Client, TextChannel } from "discord.js";
|
||||
import type { Client } 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}`);
|
||||
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 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} ~ `,
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
prompt: `${chan.name} ~ `,
|
||||
});
|
||||
|
||||
rl.prompt();
|
||||
|
||||
rl.on("line", (line) => {
|
||||
if (line.trim().length > 0) {
|
||||
void chan.send(line);
|
||||
}
|
||||
rl.prompt();
|
||||
});
|
||||
|
||||
rl.on("close", () => {
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
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