UNPKG

twitch-core

Version:
49 lines (48 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandParser = void 0; class CommandParser { constructor(client) { this.client = client; } parse(message, prefix) { const regex = new RegExp('^(' + this.escapePrefix(prefix) + ')([^\\s]+) ?(.*)', 'gims'); const matches = regex.exec(message); if (matches) { const prefix = matches[1]; const command = matches[2]; const result = { command: command, prefix: prefix, args: [] }; if (matches.length > 3) { result.args = matches[3] .trim() .split(' ') .filter(v => v !== ''); } if (this.client.options.verboseLogging) { this.client.logger.verbose(JSON.stringify(result, null, 2)); } return result; } return null; } escapePrefix(prefix) { if (prefix === '?' || prefix === '^' || prefix === '[' || prefix === ']' || prefix === ']' || prefix === '(' || prefix === ')' || prefix === '*' || prefix === '\\') { prefix = '\\' + prefix; } return prefix; } } exports.CommandParser = CommandParser;