electionAdminCommand handles the `election` admin command.
(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)
| 289 | |
| 290 | // electionAdminCommand handles the `election` admin command. |
| 291 | func (m *ElectionsModule) electionAdminCommand(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) { |
| 292 | args := strings.Fields(rest) |
| 293 | |
| 294 | if len(args) == 0 { |
| 295 | tplTxt, _ := templates.Process(`help/elections-admin`, nil, user.UserId) |
| 296 | user.SendText(tplTxt) |
| 297 | return true, nil |
| 298 | } |
| 299 | |
| 300 | switch strings.ToLower(args[0]) { |
| 301 | |
| 302 | case `start`: |
| 303 | if len(args) < 2 { |
| 304 | user.SendText(`Usage: <ansi fg="command">election start <title></ansi>` + term.CRLFStr) |
| 305 | return true, nil |
| 306 | } |
| 307 | |
| 308 | if m.state.ActiveElection != nil { |
| 309 | user.SendText(fmt.Sprintf(`An election for <ansi fg="white-bold">%s</ansi> is already in progress.`+term.CRLFStr, m.state.ActiveElection.Title)) |
| 310 | return true, nil |
| 311 | } |
| 312 | |
| 313 | title := strings.Join(args[1:], ` `) |
| 314 | zone := room.Zone |
| 315 | |
| 316 | m.state.ActiveElection = &Election{ |
| 317 | Title: title, |
| 318 | Zone: zone, |
| 319 | StartRound: util.GetRoundCount(), |
| 320 | Votes: make(map[int]int), |
| 321 | } |
| 322 | |
| 323 | daysLeft := m.daysRemaining() |
| 324 | msg := electionAlert( |
| 325 | fmt.Sprintf(`An election has started for "<ansi fg="white-bold">%s</ansi>."`, title), |
| 326 | `Type <ansi fg="command">help elections</ansi> to find out more about it.`, |
| 327 | `Cast your vote at the nearest polling location.`, |
| 328 | fmt.Sprintf(`The election ends in <ansi fg="white-bold">%s</ansi>!`, daysLeft), |
| 329 | ) |
| 330 | broadcastAlert(msg) |
| 331 | |
| 332 | case `end`: |
| 333 | if m.state.ActiveElection == nil { |
| 334 | user.SendText(`There is no active election to end.` + term.CRLFStr) |
| 335 | return true, nil |
| 336 | } |
| 337 | m.endElection(user) |
| 338 | |
| 339 | case `taxrate`: |
| 340 | // Admin/mod only. Usage: |
| 341 | // election taxrate <0-100> (uses current room's zone) |
| 342 | // election taxrate <zonename> <0-100> (explicit zone) |
| 343 | if len(args) < 2 { |
| 344 | user.SendText(`Usage: <ansi fg="command">election taxrate <0-100></ansi> or <ansi fg="command">election taxrate <zone> <0-100></ansi>` + term.CRLFStr) |
| 345 | return true, nil |
| 346 | } |
| 347 | |
| 348 | zoneKey := strings.ToLower(room.Zone) |
nothing calls this directly
no test coverage detected