From dc444e90dc08efef8175668556b2dca3cd377f56 Mon Sep 17 00:00:00 2001 From: Will Pine Date: Tue, 9 Apr 2019 15:45:56 +1000 Subject: [PATCH 1/3] Added ability to use downsampled images from Giphy --- .../matrix-org/go-neb/services/giphy/giphy.go | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/services/giphy/giphy.go b/src/github.com/matrix-org/go-neb/services/giphy/giphy.go index 4da7d31..826fe20 100644 --- a/src/github.com/matrix-org/go-neb/services/giphy/giphy.go +++ b/src/github.com/matrix-org/go-neb/services/giphy/giphy.go @@ -28,8 +28,10 @@ type image struct { type result struct { Slug string `json:"slug"` Images struct { - Downsized image `json:"downsized"` - Original image `json:"original"` + Original image `json:"original"` + DownsampledFixedHeight image `json:"fixed_height_downsampled"` + DownsampledFixedWidth image `json:"fixed_width_downsampled"` + Downsized image `json:"downsized"` } `json:"images"` } @@ -49,6 +51,14 @@ type Service struct { // The Giphy API key to use when making HTTP requests to Giphy. // The public beta API key is "dc6zaTOxFJmzC". APIKey string `json:"api_key"` + + // Specifies whether to use downsampled/downsized image from Giphy. + // 0 indicates original image (defaults to this) + // 1 for downsized images + // 2 for fixed height downsampled, 3 for fixed width downsampled images + ImageType int `json:"image_type"` + + // Whether to use the downsized image from Giphy. // Uses the original image when set to false. // Defaults to false. @@ -78,9 +88,14 @@ func (s *Service) cmdGiphy(client *gomatrix.Client, roomID, userID string, args } image := gifResult.Images.Original - if s.UseDownsized { + + switch s.ImageType { + case 1: + image = gifResult.Images.DownsampledFixedHeight + case 2: + image = gifResult.Images.DownsampledFixedWidth + case 3: image = gifResult.Images.Downsized - } if image.URL == "" { return nil, fmt.Errorf("No results") From b160daf48d86e046673adf95cdd055604b59c78b Mon Sep 17 00:00:00 2001 From: Will Pine Date: Tue, 9 Apr 2019 15:52:48 +1000 Subject: [PATCH 2/3] Removed old UseDownsized code in favor of ImageType --- src/github.com/matrix-org/go-neb/services/giphy/giphy.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/services/giphy/giphy.go b/src/github.com/matrix-org/go-neb/services/giphy/giphy.go index 826fe20..6b1a307 100644 --- a/src/github.com/matrix-org/go-neb/services/giphy/giphy.go +++ b/src/github.com/matrix-org/go-neb/services/giphy/giphy.go @@ -44,7 +44,7 @@ type giphySearch struct { // Example request: // { // "api_key": "dc6zaTOxFJmzC", -// "use_downsized": false +// "image_type": 0 // } type Service struct { types.DefaultService @@ -57,12 +57,6 @@ type Service struct { // 1 for downsized images // 2 for fixed height downsampled, 3 for fixed width downsampled images ImageType int `json:"image_type"` - - - // Whether to use the downsized image from Giphy. - // Uses the original image when set to false. - // Defaults to false. - UseDownsized bool `json:"use_downsized"` } // Commands supported: @@ -88,7 +82,6 @@ func (s *Service) cmdGiphy(client *gomatrix.Client, roomID, userID string, args } image := gifResult.Images.Original - switch s.ImageType { case 1: image = gifResult.Images.DownsampledFixedHeight From c936b8482c57bb3392d62a1cf3300642f5e4fef0 Mon Sep 17 00:00:00 2001 From: Will Pine Date: Tue, 9 Apr 2019 15:52:56 +1000 Subject: [PATCH 3/3] Added support for downsampled images in the Giphy bot --- config.sample.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.sample.yaml b/config.sample.yaml index dc196c9..d69c1dc 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -67,7 +67,7 @@ services: UserID: "@goneb:localhost" # requires a Syncing client Config: api_key: "qwg4672vsuyfsfe" - use_downsized: false + image_type: 0 - ID: "guggy_service" Type: "guggy"