UNPKG

ts3-nodejs-library

Version:
160 lines (159 loc) 5.79 kB
import { QueryResponseTypes, QueryResponse } from "../types/QueryResponse"; import { ResponseError } from "../exception/ResponseError"; export declare class Command { private requestParser; private responseParser; private cmd; private options; private multiOpts; private flags; private response; private error; /** Initializes the Respone with default values */ reset(): Command; /** Sets the main command to send */ setCommand(cmd: string): Command; /** * Sets the TeamSpeak Key Value Pairs * @param opts sets the Object with the key value pairs which should get sent to the TeamSpeak Query */ setOptions(options: Command.options): Command; /** * Sets the TeamSpeak Key Value Pairs * @param opts sets the Object with the key value pairs which should get sent to the TeamSpeak Query */ setMultiOptions(options: Command.multiOpts): Command; /** * adds a customparser * @param parsers */ setParser(parsers: Command.ParserCallback): this; /** checks wether there are options used with this command */ hasOptions(): boolean; /** checks wether there are options used with this command */ hasMultiOptions(): boolean; /** * set TeamSpeak flags * @param flags sets the flags which should get sent to the teamspeak query */ setFlags(flags: Command.flags): Command; /** checks wether there are flags used with this command */ hasFlags(): boolean; /** * set the Line which has been received from the TeamSpeak Query * @param line the line which has been received from the teamSpeak query */ setResponse(line: string): Command; /** * Set the error line which has been received from the TeamSpeak Query * @param error the error line which has been received from the TeamSpeak Query */ setError(error: string): Command; /** get the parsed error object which has been received from the TeamSpeak Query */ getError(): ResponseError | null; /** checks if a error has been received */ hasError(): boolean; /** get the parsed response object which has been received from the TeamSpeak Query */ getResponse(): Partial<QueryResponseTypes>[]; /** runs the parser of this instance */ parse(raw: string): Partial<QueryResponseTypes>[]; /** runs the parser of this instance */ build(): string; /** * retrieves the default parsers */ static getParsers(): Command.Parsers; /** * * @param param0 the custom snapshot response parser */ static parseSnapshotCreate({ raw }: Pick<Command.ParserArgument, "raw">): Partial<Partial<QueryResponseTypes>>[]; /** * the custom snapshot request parser * @param data snapshot string * @param cmd command object */ static buildSnapshotDeploy(data: string, cmd: Command): string; /** * parses a query response * @param data the query response received */ static parse({ raw }: Pick<Command.ParserArgument, "raw">): Partial<Partial<QueryResponseTypes>>[]; /** * Checks if a error has been received * @return The parsed String which is readable by the TeamSpeak Query */ static build(command: Command): string; /** * builds the query string for options * @return the parsed String which is readable by the TeamSpeak Querytt */ buildOptions(): string; /** builds the query string for options */ buildOption(options: Record<string, any>): string; /** builds the query string for flags */ buildFlags(): string; /** * escapes a key value pair * @param {string} key the key used * @param {string|string[]} value the value or an array of values * @return the parsed String which is readable by the TeamSpeak Query */ static escapeKeyValue(key: string, value: string | string[]): string; /** * retrieves the key value pair from a string * @param str the key value pair to unescape eg foo=bar */ static getKeyValue(str: string): { key: string; value: string | undefined; }; /** * Parses a value to the type which the key represents * @param k the key which should get looked up * @param v the value which should get parsed */ static parseValue(k: string, v: string | undefined): any; /** * parses a string value * @param value string to parse */ static parseString(value: string): string; static parseRecursive(value: string): Partial<Partial<QueryResponseTypes>>[]; /** * parses a string array * @param value string to parse */ static parseStringArray(value: string): string[]; /** * parses a number * @param value string to parse */ static parseNumber(value: string): number; /** * parses a number array * @param value string to parse */ static parseNumberArray(value: string): number[]; /** unescapes a string */ static unescape(str: string): string; /** escapes a string */ static escape(str: string): string; } export declare namespace Command { interface ParserArgument { cmd: typeof Command; raw: string; } interface Parsers { response: ResponseParser; request: RequestParser; } type ParserCallback = (parser: Parsers) => Parsers; type ResponseParser = (data: ParserArgument) => QueryResponse[]; type RequestParser = (cmd: Command) => string; type options = Record<string, string | string[] | number | number[] | undefined | null>; type multiOpts = Command.options[]; type flags = (number | string | null)[]; const Identifier: Record<keyof QueryResponseTypes, (value: string) => any>; }