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
745 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 findResult struct {
  9. Channel models.Channel `json:"channel"`
  10. }
  11. var findGQL = `
  12. query FindChannel($name: String!) {
  13. channel(name: $name) {
  14. name
  15. logged
  16. eventName
  17. locationName
  18. }
  19. }
  20. `
  21. // Find finds a channel by name
  22. func Find(ctx context.Context, name string) (models.Channel, error) {
  23. data, err := api.Global().Query(ctx, findGQL, map[string]interface{}{"name": name}, nil)
  24. if err != nil {
  25. return models.Channel{}, err
  26. }
  27. result := findResult{}
  28. err = json.Unmarshal(data, &result)
  29. if err != nil {
  30. return models.Channel{}, err
  31. }
  32. return result.Channel, nil
  33. }