(_ string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)
| 312 | } |
| 313 | |
| 314 | func server_Config(_ string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) { |
| 315 | |
| 316 | // Get if already exists, otherwise create new |
| 317 | cmdPrompt, isNew := user.StartPrompt(`server config`, "") |
| 318 | |
| 319 | if isNew { |
| 320 | user.SendText(``) |
| 321 | menuOptions, _ := getConfigOptions("") |
| 322 | tplTxt, _ := templates.Process("tables/numbered-list", menuOptions, user.UserId) |
| 323 | user.SendText(tplTxt) |
| 324 | } |
| 325 | |
| 326 | configPrefix := "" |
| 327 | if selection, ok := cmdPrompt.Recall("config-selected"); ok { |
| 328 | configPrefix = selection.(string) |
| 329 | } |
| 330 | |
| 331 | if configPrefix != "" { |
| 332 | allConfigData := configs.GetConfig().AllConfigData() |
| 333 | if configVal, ok := allConfigData[configPrefix]; ok { |
| 334 | |
| 335 | if !isEditAllowed(configPrefix) { |
| 336 | user.SendText(errValueLocked.Error()) |
| 337 | user.ClearPrompt() |
| 338 | return true, nil |
| 339 | } |
| 340 | |
| 341 | question := cmdPrompt.Ask(fmt.Sprintf(newValuePrompt, configPrefix), []string{fmt.Sprintf("%v", configVal)}, fmt.Sprintf("%v", configVal)) |
| 342 | if !question.Done { |
| 343 | return true, nil |
| 344 | } |
| 345 | |
| 346 | user.ClearPrompt() |
| 347 | |
| 348 | err := configs.SetVal(configPrefix, question.Response) |
| 349 | if err == nil { |
| 350 | allConfigData := configs.GetConfig().AllConfigData() |
| 351 | user.SendText(``) |
| 352 | user.SendText(fmt.Sprintf(`<ansi fg="6">%s</ansi> has been set to: <ansi fg="9">%s<ansi>`, configPrefix, allConfigData[configPrefix])) |
| 353 | user.SendText(``) |
| 354 | return true, nil |
| 355 | } |
| 356 | user.SendText(err.Error()) |
| 357 | return true, nil |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | question := cmdPrompt.Ask(`Choose a config option, or "quit":`, []string{``}, ``) |
| 362 | if !question.Done { |
| 363 | return true, nil |
| 364 | } |
| 365 | |
| 366 | if question.Response == "quit" { |
| 367 | user.SendText("Quitting...") |
| 368 | user.ClearPrompt() |
| 369 | return true, nil |
| 370 | } |
| 371 |
no test coverage detected