@sarahisweird/hmoog
Version:
Out-of-game automation for Hackmud
153 lines (152 loc) • 4.96 kB
TypeScript
import { ExecutionResult, FlushReason } from './types.js';
/** Options for the {@link HmOog.constructor HmOog constructor}. */
export interface OogOptions {
/**
* The path to the shell.txt
* @default (the Hackmud data folder of your system)/shell.txt
*/
shellPath: string;
/**
* If the Hackmud shell should be focused on startup.
* @default false
*/
shouldFocusShell: boolean;
}
/** The class that manages OOG activity. */
export declare class HmOog {
private readonly shellPath;
private readonly shouldFocusShell;
private readonly fileWatcher;
private didInit;
private lastShellFlag;
private unprocessedLines;
private isInHardline;
/**
* @param options Initialisation options - see {@link OogOptions}
*/
constructor(options?: Partial<OogOptions>);
/**
* Initialize the OOG. Must be called before any other methods!
*/
init(): Promise<void>;
/**
* Wait until the shell is flushed.
*
* @returns why the shell was flushed
*/
waitForFlush(): Promise<FlushReason>;
/**
* Wait until the shell is flushed by a `flush` command.
*/
waitForCommandFlush(): Promise<void>;
/**
* Runs the `flush` command and waits until it successfully flushed the shell.
*
* @param timeout=0 the maximum number of milliseconds to try flushing.
* A value below 1 means no waiting.
*
* @returns whether or not a timeout happened.
*
* @remarks
* The flush operation may be delayed by another program that's currently being executed,
* in which case this function only returns when both the program and the flush command ran.
*/
flush(timeout?: number): Promise<boolean>;
/**
* Sends a command to Hackmud and processes the result.
*
* @param command The command to send
* @returns The result of the command
* @throws TypeError if the command contains newlines
* @throws OogExecutionError if the command couldn't be typed into Hackmud
*/
runCommand(command: string): Promise<ExecutionResult>;
private processOutput;
/**
* Sends a command to Hackmud.
*
* @param command The command to send
* @returns whether the command could be typed into Hackmud
* @throws TypeError if the command contains newlines
*/
sendRaw(command: string): Promise<boolean>;
/**
* Removes and returns all shell lines yet to be processed by other methods.
*
* @returns a list of the raw shell output
*/
consumeLines(): string[];
/**
* Get the current hardline activation status.
*/
isHardlineActive(): boolean;
/**
* Enters hardline.
*
* @remarks
*
* Due to the hardline GUI, it takes *at least* 15 seconds to enter hardline!
* If entering hardline fails, the call takes ~2s.
* If it succeeds, it will take over 20s!
*
* This delay can **not** be reduced meaningfully due to the
* `-hardline active-` message, as well as all the animations being pretty slow.
*
* @returns 0 if successful, otherwise how many milliseconds are left until the next hardline.
*/
enterHardline(): Promise<number>;
/**
* Exits hardline.
*
* @remarks
*
* Wait five seconds after calling `kernel.hardline {dc: true}`, due to the
* `-hardline disconnected-` message breaking parsing.
*
* While it could be reduced, it would also show up unexpectedly in results
* from {@link runCommand}!
*/
exitHardline(): Promise<void>;
/**
* Helper method to get the number of milliseconds left until the next hardline is available.
*
* @private
*/
private getHardlineCooldown;
/**
* Small helper method to check if {@link init} has been run.
*
* @private
* @throws OogNotInitializedError if not initialized
*/
private assertDidInit;
/**
* Sends a special flag, so we can find where we last left off.
*
* @remarks
*
* The reason we need to do this is that we can't tell apart old stuff from new stuff
* in every case. If the outputs have been exactly the same, we'd need to guesswork.
* This completely negates the need for guessing!
*
* @private
*/
private placeShellFlag;
/**
* Helper method that searches for the previous {@link placeShellFlag shell flag} and removes everything
* before it, including the flag itself and its error output.
*
* @private
* @param lines The lines to process
*/
private removeOldLines;
/**
* Reads the actual shell.txt file and puts yet unprocessed lines into {@link unprocessedLines}.
*
* Removes *some* junk output like any `flush` executions.
*
* @private
* @returns The reason for the last shell flush
*/
private updateShell;
}