bot: Added channel handler and the actual logging.

This commit is contained in:
2018-11-22 22:24:33 +01:00
parent 7336ea2b47
commit c08bd6c05a
9 changed files with 630 additions and 6 deletions
+58
View File
@@ -0,0 +1,58 @@
package posts
import (
"context"
"encoding/json"
"time"
"git.aiterp.net/rpdata/logbot3/internal/api"
"git.aiterp.net/rpdata/logbot3/internal/models"
)
// Add adds a log file.
func Add(ctx context.Context, log models.Log, time time.Time, kind, nick, text string) (models.Post, error) {
input := addInput{
LogID: log.ID,
Time: time,
Kind: kind,
Nick: nick,
Text: text,
}
data, err := api.Global().Query(ctx, addGQL, map[string]interface{}{"input": input}, []string{"post.add"})
if err != nil {
return models.Post{}, err
}
res := addResult{}
err = json.Unmarshal(data, &res)
if err != nil {
return models.Post{}, err
}
return res.Post, nil
}
type addResult struct {
Post models.Post `json:"addPost"`
}
type addInput struct {
LogID string `json:"logId"`
Time time.Time `json:"time"`
Kind string `json:"kind"`
Nick string `json:"nick"`
Text string `json:"text"`
}
const addGQL = `
mutation AddPost($input:PostAddInput!) {
addPost(input:$input) {
id
time
kind
nick
text
}
}
`