Files
linux-odyssey/packages/game/src/condition/ErrorMatcher.ts
T
2024-03-07 00:50:42 +08:00

19 lines
424 B
TypeScript

import { Matcher } from './Matcher.js'
import { Command } from '../types.js'
export class ErrorMatcher implements Matcher {
private matcher?: RegExp
constructor(errorPattern?: string) {
if (errorPattern) {
this.matcher = new RegExp(errorPattern)
}
}
match(command: Command): boolean {
if (!this.matcher) {
return !command.error
}
return this.matcher.test(command.error || '')
}
}