(userId int, inputText string, flags events.EventFlag)
| 491 | } |
| 492 | |
| 493 | func (w *World) processInput(userId int, inputText string, flags events.EventFlag) { |
| 494 | |
| 495 | user := users.GetByUserId(userId) |
| 496 | if user == nil { // Something went wrong. User not found. |
| 497 | mudlog.Error("User not found", "userId", userId) |
| 498 | return |
| 499 | } |
| 500 | |
| 501 | var activeQuestion *prompt.Question = nil |
| 502 | hadPrompt := false |
| 503 | if cmdPrompt := user.GetPrompt(); cmdPrompt != nil { |
| 504 | hadPrompt = true |
| 505 | if activeQuestion = cmdPrompt.GetNextQuestion(); activeQuestion != nil { |
| 506 | |
| 507 | activeQuestion.Answer(string(inputText)) |
| 508 | inputText = `` |
| 509 | |
| 510 | // set the input buffer to invoke the command prompt it was relevant to |
| 511 | if cmdPrompt.Command != `` { |
| 512 | inputText = cmdPrompt.Command + " " + cmdPrompt.Rest |
| 513 | } |
| 514 | } else { |
| 515 | // If a prompt was found, but no pending questions, clear it. |
| 516 | user.ClearPrompt() |
| 517 | } |
| 518 | |
| 519 | } |
| 520 | |
| 521 | command := `` |
| 522 | remains := `` |
| 523 | |
| 524 | var err error |
| 525 | handled := false |
| 526 | |
| 527 | inputText = strings.TrimSpace(inputText) |
| 528 | |
| 529 | if len(inputText) > 0 { |
| 530 | |
| 531 | // Update their last input |
| 532 | // Must be actual text, blank space doesn't count. |
| 533 | user.SetLastInputRound(util.GetRoundCount()) |
| 534 | |
| 535 | // Check for macros |
| 536 | if user.Macros != nil && len(inputText) == 2 { |
| 537 | if macro, ok := user.Macros[inputText]; ok { |
| 538 | handled = true |
| 539 | readyTurn := util.GetTurnCount() |
| 540 | for _, newCmd := range strings.Split(macro, `;`) { |
| 541 | if newCmd == `` { |
| 542 | continue |
| 543 | } |
| 544 | |
| 545 | events.AddToQueue(events.Input{ |
| 546 | UserId: userId, |
| 547 | InputText: newCmd, |
| 548 | ReadyTurn: readyTurn, |
| 549 | }) |
| 550 |
no test coverage detected