55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { Command } from 'commander';
|
|
import { loadConfig } from './config.js';
|
|
import { Bot } from './bot/Bot.js';
|
|
import { Server } from './server/Server.js';
|
|
import { ConfigStore } from './bot/ConfigStore.js';
|
|
import { logger } from './util/logger.js';
|
|
|
|
const program = new Command();
|
|
|
|
program
|
|
.name('poe2trade')
|
|
.description('POE2 automated trade bot')
|
|
.option('-u, --url <urls...>', 'Trade search URLs to monitor')
|
|
.option('--log-path <path>', 'Path to POE2 Client.txt')
|
|
.option('-p, --port <number>', 'Dashboard port')
|
|
.option('-c, --config <path>', 'Path to config.json', 'config.json')
|
|
.action(async (options) => {
|
|
const store = new ConfigStore(options.config);
|
|
const saved = store.settings;
|
|
|
|
const envConfig = loadConfig(options.url);
|
|
if (options.logPath) envConfig.poe2LogPath = options.logPath;
|
|
|
|
const config = {
|
|
...envConfig,
|
|
poe2LogPath: options.logPath || saved.poe2LogPath,
|
|
poe2WindowTitle: saved.poe2WindowTitle,
|
|
browserUserDataDir: saved.browserUserDataDir,
|
|
travelTimeoutMs: saved.travelTimeoutMs,
|
|
stashScanTimeoutMs: saved.stashScanTimeoutMs,
|
|
waitForMoreItemsMs: saved.waitForMoreItemsMs,
|
|
betweenTradesDelayMs: saved.betweenTradesDelayMs,
|
|
};
|
|
|
|
const port = parseInt(options.port, 10) || saved.dashboardPort;
|
|
|
|
const bot = new Bot(store, config);
|
|
const server = new Server(bot, port);
|
|
await server.start();
|
|
await bot.start(config.tradeUrls, port);
|
|
|
|
const shutdown = async () => {
|
|
logger.info('Shutting down...');
|
|
await bot.stop();
|
|
await server.stop();
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on('SIGINT', shutdown);
|
|
process.on('SIGTERM', shutdown);
|
|
|
|
logger.info(`Dashboard: http://localhost:${port}`);
|
|
});
|
|
|
|
program.parse();
|