Commands
(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)
| 390 | // |
| 391 | |
| 392 | func (f *FollowModule) followUserCommand(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) { |
| 393 | |
| 394 | if rest == "" { |
| 395 | user.SendText(`Follow whom? Try <ansi fg="command">help command</ansi>`) |
| 396 | return true, nil |
| 397 | } |
| 398 | |
| 399 | if parties.Get(user.UserId) != nil { |
| 400 | user.SendText(`You can't use this command while in a party.`) |
| 401 | return true, nil |
| 402 | } |
| 403 | |
| 404 | args := util.SplitButRespectQuotes(strings.ToLower(rest)) |
| 405 | |
| 406 | followTargetName := args[0] |
| 407 | followAction := `follow` |
| 408 | followEndRound := uint64(0) |
| 409 | |
| 410 | if rest == `stop` || rest == `lose` { |
| 411 | followAction = rest |
| 412 | followTargetName = `` |
| 413 | } |
| 414 | |
| 415 | gd := gametime.GetDate(util.GetRoundCount()) |
| 416 | |
| 417 | if len(args) > 1 { |
| 418 | followEndRound = gd.AddPeriod(strings.Join(args[1:], ` `)) |
| 419 | } else if followPeriod, ok := f.plug.Config.Get(`DefaultFollowPeriod`).(string); ok { |
| 420 | followEndRound = gd.AddPeriod(followPeriod) |
| 421 | } |
| 422 | |
| 423 | // in case something went wrong, we still want to cap it. |
| 424 | if followEndRound <= util.GetRoundCount() { |
| 425 | followEndRound = gd.AddPeriod(`5 real minutes`) |
| 426 | } |
| 427 | |
| 428 | userId, mobInstId := 0, 0 |
| 429 | if len(followTargetName) > 0 { |
| 430 | userId, mobInstId = room.FindByName(followTargetName) |
| 431 | } |
| 432 | |
| 433 | followCommandTarget := followId{userId: userId, mobInstanceId: mobInstId} |
| 434 | followCommandSource := followId{userId: user.UserId} |
| 435 | |
| 436 | if followCommandTarget.userId == followCommandSource.userId { |
| 437 | user.SendText(`You can't target yourself.`) |
| 438 | return true, nil |
| 439 | } |
| 440 | |
| 441 | // Lose any followers |
| 442 | if followAction == `lose` { |
| 443 | |
| 444 | if lostFollowers := f.loseFollowers(followCommandSource); len(lostFollowers) > 0 { |
| 445 | |
| 446 | // Tell all the followers they |
| 447 | for _, fId := range lostFollowers { |
| 448 | if fId.userId == 0 { |
| 449 | continue |
nothing calls this directly
no test coverage detected