package main import ( "bytes" "encoding/json" "net/http" "time" ) const ( wikiURL = "https://wiki.example.com/graphql" token = "WIKIJS_API_TOKEN" webhook = "https://discord.com/api/webhooks/XXXX/XXXX" interval = 5 * time.Minute ) var lastUpdate string func check() { q := `{"query":"{ pages { list(orderBy: UPDATED_AT, orderDirection: DESC, limit: 1){ updatedAt title }}}"}` req, _ := http.NewRequest("POST", wikiURL, bytes.NewBuffer([]byte(q))) req.Header.Set("Authorization", "Bearer "+token) req.Header.Set("Content-Type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil { return } defer res.Body.Close() var r struct { Data struct { Pages struct { List []struct { UpdatedAt string Title string } } } } json.NewDecoder(res.Body).Decode(&r) if len(r.Data.Pages.List) == 0 { return } u := r.Data.Pages.List[0] if u.UpdatedAt != lastUpdate { lastUpdate = u.UpdatedAt msg, _ := json.Marshal(map[string]string{ "content": "Wiki frissĂ­tve: " + u.Title, }) http.Post(webhook, "application/json", bytes.NewBuffer(msg)) } } func main() { for { check() time.Sleep(interval) } }