added easyOCR
This commit is contained in:
parent
37d6678577
commit
9f208b0606
27 changed files with 1780 additions and 112 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { logger } from '../util/logger.js';
|
||||
import type { LinkMode } from '../types.js';
|
||||
import type { ConfigStore, SavedLink } from './ConfigStore.js';
|
||||
|
||||
export interface TradeLink {
|
||||
|
|
@ -8,6 +9,7 @@ export interface TradeLink {
|
|||
name: string;
|
||||
label: string;
|
||||
active: boolean;
|
||||
mode: LinkMode;
|
||||
addedAt: string;
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +27,11 @@ export interface BotStatus {
|
|||
waitForMoreItemsMs: number;
|
||||
betweenTradesDelayMs: number;
|
||||
};
|
||||
inventory?: {
|
||||
grid: boolean[][];
|
||||
items: { row: number; col: number; w: number; h: number }[];
|
||||
free: number;
|
||||
};
|
||||
}
|
||||
|
||||
export class BotController extends EventEmitter {
|
||||
|
|
@ -35,6 +42,7 @@ export class BotController extends EventEmitter {
|
|||
private tradesFailed = 0;
|
||||
private startTime = Date.now();
|
||||
private store: ConfigStore;
|
||||
private _inventory: BotStatus['inventory'] = undefined;
|
||||
|
||||
constructor(store: ConfigStore) {
|
||||
super();
|
||||
|
|
@ -69,7 +77,7 @@ export class BotController extends EventEmitter {
|
|||
this.emit('resumed');
|
||||
}
|
||||
|
||||
addLink(url: string, name: string = ''): TradeLink {
|
||||
addLink(url: string, name: string = '', mode?: LinkMode): TradeLink {
|
||||
url = this.stripLive(url);
|
||||
const id = this.extractId(url);
|
||||
const label = this.extractLabel(url);
|
||||
|
|
@ -81,11 +89,12 @@ export class BotController extends EventEmitter {
|
|||
name: name || savedLink?.name || '',
|
||||
label,
|
||||
active: savedLink?.active !== undefined ? savedLink.active : true,
|
||||
mode: mode || savedLink?.mode || 'live',
|
||||
addedAt: new Date().toISOString(),
|
||||
};
|
||||
this.links.set(id, link);
|
||||
this.store.addLink(url, link.name);
|
||||
logger.info({ id, url, name: link.name, active: link.active }, 'Trade link added');
|
||||
this.store.addLink(url, link.name, link.mode);
|
||||
logger.info({ id, url, name: link.name, active: link.active, mode: link.mode }, 'Trade link added');
|
||||
this.emit('link-added', link);
|
||||
return link;
|
||||
}
|
||||
|
|
@ -118,6 +127,15 @@ export class BotController extends EventEmitter {
|
|||
this.store.updateLinkById(id, { name });
|
||||
}
|
||||
|
||||
updateLinkMode(id: string, mode: LinkMode): void {
|
||||
const link = this.links.get(id);
|
||||
if (!link) return;
|
||||
link.mode = mode;
|
||||
this.store.updateLinkById(id, { mode });
|
||||
logger.info({ id, mode }, 'Trade link mode updated');
|
||||
this.emit('link-mode-changed', { id, mode, link });
|
||||
}
|
||||
|
||||
isLinkActive(searchId: string): boolean {
|
||||
const link = this.links.get(searchId);
|
||||
return link ? link.active : false;
|
||||
|
|
@ -153,9 +171,14 @@ export class BotController extends EventEmitter {
|
|||
waitForMoreItemsMs: s.waitForMoreItemsMs,
|
||||
betweenTradesDelayMs: s.betweenTradesDelayMs,
|
||||
},
|
||||
inventory: this._inventory,
|
||||
};
|
||||
}
|
||||
|
||||
setInventory(inv: BotStatus['inventory']): void {
|
||||
this._inventory = inv;
|
||||
}
|
||||
|
||||
getStore(): ConfigStore {
|
||||
return this.store;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue