diff --git a/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia.go b/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia.go index 3c540bf..c7b95c6 100644 --- a/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia.go +++ b/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "net/http" "net/url" - "strconv" "strings" log "github.com/Sirupsen/logrus" @@ -23,9 +22,11 @@ const maxExtractLength = 1024 // Max length of extract string in bytes var httpClient = &http.Client{} type wikipediaSearchResults struct { - Query struct { - Pages map[string]wikipediaPage `json:"pages"` - } `json:"query"` + Query wikipediaQuery `json:"query"` +} + +type wikipediaQuery struct { + Pages map[string]wikipediaPage `json:"pages"` } type wikipediaPage struct { @@ -98,7 +99,7 @@ func (s *Service) cmdWikipediaSearch(client *gomatrix.Client, roomID, userID str } // Add a link to the bottom of the extract - extractText += "\n" + "http://en.wikipedia.org/?curid=" + strconv.FormatInt(searchResultPage.PageID, 10) + extractText += fmt.Sprintf("\nhttp://en.wikipedia.org/?curid=%d", searchResultPage.PageID) return gomatrix.TextMessage{ MsgType: "m.notice", diff --git a/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia_test.go b/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia_test.go index 3de53aa..6440cb9 100644 --- a/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia_test.go +++ b/src/github.com/matrix-org/go-neb/services/wikipedia/wikipedia_test.go @@ -46,16 +46,21 @@ func TestCommand(t *testing.T) { t.Fatalf("Bad search string: got \"%s\" (%d characters) ", searchString, searchStringLength) } - resImage := wikipediaImage{ - Width: 64, - Height: 64, + page := wikipediaPage{ + PageID: 1, + NS: 1, + Title: "Test page", + Touched: "2017-02-21 00:00:00", + LastRevID: 1, + Extract: "Some extract text", } - - res := wikipediaSearchResult{ - Title: "A Cat", - Link: "http://cat.com/cat.jpg", - Mime: "image/jpeg", - Image: resImage, + pages := map[string]wikipediaPage{ + "1": page, + } + res := wikipediaSearchResults{ + Query: wikipediaQuery{ + Pages: pages, + }, } b, err := json.Marshal(res) @@ -100,7 +105,7 @@ func TestCommand(t *testing.T) { // Execute the matrix !command cmds := wikipedia.Commands(matrixCli) - if len(cmds) != 3 { + if len(cmds) != 1 { t.Fatalf("Unexpected number of commands: %d", len(cmds)) } // cmd := cmds[0]