The new logbot, not committed from the wrong terminal window this time.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
896 B

6 years ago
  1. package channels
  2. import (
  3. "context"
  4. "encoding/json"
  5. "git.aiterp.net/rpdata/logbot3/internal/api"
  6. "git.aiterp.net/rpdata/logbot3/internal/models"
  7. )
  8. type setLoggedResult struct {
  9. EditChannel models.Channel `json:"editChannel"`
  10. }
  11. var setLoggedGQL = `
  12. mutation SetChanelLogged($name: String!, $logged: Boolean!) {
  13. editChannel(input: {name: $name, logged: $logged}) {
  14. name
  15. logged
  16. eventName
  17. locationName
  18. }
  19. }
  20. `
  21. // SetLogged sets a channel as logged
  22. func SetLogged(ctx context.Context, name string, logged bool) (models.Channel, error) {
  23. data, err := api.Global().Query(ctx, setLoggedGQL, map[string]interface{}{"name": name, "logged": logged}, []string{"channel.edit"})
  24. if err != nil {
  25. return models.Channel{}, err
  26. }
  27. result := setLoggedResult{}
  28. err = json.Unmarshal(data, &result)
  29. if err != nil {
  30. return models.Channel{}, err
  31. }
  32. return result.EditChannel, nil
  33. }