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.

67 lines
1.2 KiB

  1. package logs
  2. import (
  3. "context"
  4. "encoding/json"
  5. "time"
  6. "git.aiterp.net/rpdata/logbot3/internal/api"
  7. "git.aiterp.net/rpdata/logbot3/internal/models"
  8. )
  9. // Add adds a log file.
  10. func Add(ctx context.Context, channelName string, date time.Time, open bool, event string) (models.Log, error) {
  11. input := addInput{
  12. Date: date,
  13. Channel: channelName,
  14. Open: &open,
  15. Event: &event,
  16. }
  17. data, err := api.Global().Query(ctx, addGQL, map[string]interface{}{"input": input}, []string{"log.add"})
  18. if err != nil {
  19. return models.Log{}, err
  20. }
  21. res := addResult{}
  22. err = json.Unmarshal(data, &res)
  23. if err != nil {
  24. return models.Log{}, err
  25. }
  26. return res.Log, nil
  27. }
  28. type addResult struct {
  29. Log models.Log `json:"addLog"`
  30. }
  31. type addInput struct {
  32. Date time.Time `json:"date"`
  33. Channel string `json:"channel"`
  34. Title *string `json:"title"`
  35. Open *bool `json:"open"`
  36. Event *string `json:"event"`
  37. Description *string `json:"description"`
  38. }
  39. const addGQL = `
  40. mutation AddLog($input:LogAddInput!) {
  41. addLog(input:$input) {
  42. id
  43. date
  44. channelName
  45. title
  46. eventName
  47. description
  48. open
  49. posts {
  50. id
  51. time
  52. kind
  53. nick
  54. text
  55. }
  56. }
  57. }
  58. `