From bc88c83c9ad64a428b7149480cb8d0d236e402a9 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Sat, 8 Nov 2025 12:25:47 +0100 Subject: [PATCH] feat: toggle user mode with --user flag --- src/index.ts | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 46fcd60..8593bd3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,23 @@ import { Partials, } from "discord.js"; +// user mode = write in console, send in channel +const flagIndex = process.argv.indexOf("--user"); +let userMode: { enabled: true; channelId: string } | { enabled: false } = { + enabled: false, +}; +if (flagIndex !== -1) { + const channelId = process.argv[flagIndex + 1]; + if (channelId === undefined) { + console.error("ERROR: --user expects channelId as a paramater"); + process.exit(1); + } + + userMode = { enabled: true, channelId }; +} + +console.log(`User mode: ${userMode.enabled ? "enabled" : "disabled"}`); + const client = new Client({ intents: [ GatewayIntentBits.Guilds, @@ -149,14 +166,27 @@ const fn = async () => { client.on("ready", async (client) => { console.log(`Logged in as ${client.user.username}`); - await initAccounts(); + if (userMode.enabled) { + const chan = client.channels.cache.get(userMode.channelId); + if (chan?.type !== ChannelType.GuildText) { + console.error("ERROR: invalid channel"); + process.exit(1); + } + process.stdout.write(`${chan.name} ~ `); + for await (const line of console) { + await chan.send(line); + process.stdout.write(`${chan.name} ~ `); + } + } else { + await initAccounts(); - await fn(); - setInterval(fn, env.WOV_FETCH_INTERVAL); + await fn(); + setInterval(fn, env.WOV_FETCH_INTERVAL); + } }); client.on("messageCreate", async (message) => { - if (message.author.bot) return; + if (message.author.bot || userMode.enabled) return; const displayName = message.member?.displayName || message.author.username;