MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / followUserCommand

Method followUserCommand

modules/follow/follow.go:392–525  ·  view source on GitHub ↗

Commands

(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)

Source from the content-addressed store, hash-verified

390//
391
392func (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

Callers

nothing calls this directly

Calls 14

loseFollowersMethod · 0.95
stopFollowingMethod · 0.95
startFollowMethod · 0.95
GetFunction · 0.92
SplitButRespectQuotesFunction · 0.92
GetDateFunction · 0.92
GetRoundCountFunction · 0.92
GetByUserIdFunction · 0.92
GetInstanceFunction · 0.92
AddPeriodMethod · 0.80
FindByNameMethod · 0.80
HatesAlignmentMethod · 0.80

Tested by

no test coverage detected