Browse Source
bot: Bot setup and teardown done: Connect w/retry, join/leave, full config, and logging.
master
bot: Bot setup and teardown done: Connect w/retry, join/leave, full config, and logging.
master
Gisle Aune
6 years ago
9 changed files with 236 additions and 76 deletions
-
4.gitignore
-
2internal/api/client.go
-
140internal/bot/bot.go
-
43internal/bot/handler.go
-
10internal/config/config.go
-
20internal/models/change.go
-
61internal/models/changes/list.go
-
25internal/models/channels/subscribe-logged.go
-
7main.go
@ -1 +1,5 @@ |
|||
# Binaries |
|||
debug |
|||
debug.exe |
|||
logbot3 |
|||
logbot3.exe |
@ -0,0 +1,61 @@ |
|||
package changes |
|||
|
|||
import ( |
|||
"context" |
|||
"encoding/json" |
|||
"time" |
|||
|
|||
"git.aiterp.net/rpdata/logbot3/internal/api" |
|||
"git.aiterp.net/rpdata/logbot3/internal/models" |
|||
) |
|||
|
|||
// The Filter for List.
|
|||
type Filter struct { |
|||
Keys []models.ChangeKey `json:"keys,omitempty"` |
|||
EarliestDate *time.Time `json:"earliestDate,omitempty"` |
|||
Limit int `json:"limit,omitempty"` |
|||
} |
|||
|
|||
// List lists all changes according to the filter.
|
|||
func List(ctx context.Context, filter *Filter) ([]models.Change, error) { |
|||
data, err := api.Global().Query(ctx, listGQL, map[string]interface{}{"filter": filter}, nil) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
|
|||
res := listResult{} |
|||
err = json.Unmarshal(data, &res) |
|||
|
|||
return res.Changes, err |
|||
} |
|||
|
|||
type listResult struct { |
|||
Changes []models.Change `json:"changes"` |
|||
} |
|||
|
|||
var listGQL = ` |
|||
query ListChanges($filter:ChangesFilter) { |
|||
changes(filter:$filter) { |
|||
id |
|||
model |
|||
op |
|||
author |
|||
listed |
|||
date |
|||
keys { |
|||
model |
|||
id |
|||
} |
|||
objects { |
|||
__typename |
|||
...on Channel { |
|||
name |
|||
logged |
|||
hub |
|||
eventName |
|||
locationName |
|||
} |
|||
} |
|||
} |
|||
} |
|||
` |
Write
Preview
Loading…
Cancel
Save
Reference in new issue