diff --git a/goneb.go b/goneb.go index 6732ec9..a4c0872 100644 --- a/goneb.go +++ b/goneb.go @@ -22,7 +22,8 @@ import ( _ "github.com/matrix-org/go-neb/realms/jira" //_ "github.com/matrix-org/go-neb/services/alertmanager" _ "github.com/matrix-org/go-neb/services/echo" - //_ "github.com/matrix-org/go-neb/services/giphy" + _ "github.com/matrix-org/go-neb/services/giphy" + //_ "github.com/matrix-org/go-neb/services/github" //_ "github.com/matrix-org/go-neb/services/google" //_ "github.com/matrix-org/go-neb/services/guggy" diff --git a/services/giphy/giphy.go b/services/giphy/giphy.go index 1c92231..0fd58ce 100644 --- a/services/giphy/giphy.go +++ b/services/giphy/giphy.go @@ -10,8 +10,11 @@ import ( "strings" "github.com/matrix-org/go-neb/types" - "github.com/matrix-org/gomatrix" log "github.com/sirupsen/logrus" + "maunium.net/go/mautrix" + "maunium.net/go/mautrix/event" + mevt "maunium.net/go/mautrix/event" + "maunium.net/go/mautrix/id" ) // ServiceType of the Giphy service. @@ -58,18 +61,18 @@ type Service struct { // Commands supported: // !giphy some search query without quotes // Responds with a suitable GIF into the same room as the command. -func (s *Service) Commands(client *gomatrix.Client) []types.Command { +func (s *Service) Commands(client *mautrix.Client) []types.Command { return []types.Command{ types.Command{ Path: []string{"giphy"}, - Command: func(roomID, userID string, args []string) (interface{}, error) { + Command: func(roomID id.RoomID, userID id.UserID, args []string) (interface{}, error) { return s.cmdGiphy(client, roomID, userID, args) }, }, } } -func (s *Service) cmdGiphy(client *gomatrix.Client, roomID, userID string, args []string) (interface{}, error) { +func (s *Service) cmdGiphy(client *mautrix.Client, roomID id.RoomID, userID id.UserID, args []string) (interface{}, error) { // only 1 arg which is the text to search for. query := strings.Join(args, " ") gifResult, err := s.searchGiphy(query) @@ -90,14 +93,14 @@ func (s *Service) cmdGiphy(client *gomatrix.Client, roomID, userID string, args return nil, err } - return gomatrix.ImageMessage{ - MsgType: "m.image", + return mevt.MessageEventContent{ + MsgType: event.MsgImage, Body: gifResult.Slug, - URL: resUpload.ContentURI, - Info: gomatrix.ImageInfo{ + URL: resUpload.ContentURI.CUString(), + Info: &mevt.FileInfo{ Height: asInt(image.Height), Width: asInt(image.Width), - Mimetype: "image/gif", + MimeType: "image/gif", Size: asInt(image.Size), }, }, nil @@ -130,16 +133,16 @@ func (s *Service) searchGiphy(query string) (*result, error) { return &search.Data, nil } -func asInt(strInt string) uint { - u64, err := strconv.ParseUint(strInt, 10, 32) +func asInt(strInt string) int { + i64, err := strconv.ParseInt(strInt, 10, 32) if err != nil { return 0 // default to 0 since these are all just hints to the client } - return uint(u64) + return int(i64) } func init() { - types.RegisterService(func(serviceID, serviceUserID, webhookEndpointURL string) types.Service { + types.RegisterService(func(serviceID string, serviceUserID id.UserID, webhookEndpointURL string) types.Service { return &Service{ DefaultService: types.NewDefaultService(serviceID, serviceUserID, ServiceType), }