onPlayerSpawn sends the election reminder to a newly spawned player.
(e events.Event)
| 688 | |
| 689 | // onPlayerSpawn sends the election reminder to a newly spawned player. |
| 690 | func (m *ElectionsModule) onPlayerSpawn(e events.Event) events.ListenerReturn { |
| 691 | evt, ok := e.(events.PlayerSpawn) |
| 692 | if !ok { |
| 693 | return events.Continue |
| 694 | } |
| 695 | |
| 696 | if m.state.ActiveElection == nil { |
| 697 | return events.Continue |
| 698 | } |
| 699 | |
| 700 | el := m.state.ActiveElection |
| 701 | daysLeft := m.daysRemaining() |
| 702 | |
| 703 | u := users.GetByUserId(evt.UserId) |
| 704 | if u == nil { |
| 705 | return events.Continue |
| 706 | } |
| 707 | |
| 708 | msg := electionAlert( |
| 709 | fmt.Sprintf(`An election is ongoing for <ansi fg="white-bold">"%s."</ansi>`, el.Title), |
| 710 | `Type <ansi fg="command">help elections</ansi> to find out more about it.`, |
| 711 | `Cast your vote at the nearest polling location.`, |
| 712 | fmt.Sprintf(`The election ends in <ansi fg="white-bold">%s</ansi>!`, daysLeft), |
| 713 | ) |
| 714 | u.SendText(msg) |
| 715 | |
| 716 | return events.Continue |
| 717 | } |
| 718 | |
| 719 | // onNewRound checks whether the election duration has elapsed and auto-ends if so. |
| 720 | // When no election is active, it checks whether any zone's election cycle period |
nothing calls this directly
no test coverage detected