mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 11:10:11 +08:00
feat: add exceptions to stage
This commit is contained in:
1 parent
56d96cf7a0
commit
66ce015f0e
6 files changed
+86
-1
No files matched your search
@@ -97,6 +97,19 @@ export default class CommandHandler extends SessionHandler {
|
||||
return matches.some((m) => m === true)
|
||||
}
|
||||
|
||||
async checkException(stage) {
|
||||
const exceptions = stage.exceptions || []
|
||||
for (const exception of exceptions) {
|
||||
console.log(exception)
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
if (exception.condition && (await this.isMatch(exception.condition))) {
|
||||
return exception
|
||||
}
|
||||
if (exception.catchAll) return exception
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async run() {
|
||||
this.quest = await Quest.findById(this.session.quest)
|
||||
const stages = this.getStages()
|
||||
@@ -114,6 +127,14 @@ export default class CommandHandler extends SessionHandler {
|
||||
|
||||
const stage = stages.find((_, i) => matches[i])
|
||||
if (!stage) {
|
||||
for (const s of stages) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const exception = await this.checkException(s)
|
||||
if (exception) {
|
||||
console.log('Got exception', exception)
|
||||
return this.executeException(exception)
|
||||
}
|
||||
}
|
||||
return {}
|
||||
}
|
||||
const response = this.execute(stage)
|
||||
|
||||
Reference in new issue
Block a user