@@ -17,16 +17,19 @@ import (
17
17
// ServiceType of the Giphy service.
18
18
const ServiceType = "giphy"
19
19
20
+ type image struct {
21
+ URL string `json:"url"`
22
+ // Giphy returns ints as strings..
23
+ Width string `json:"width"`
24
+ Height string `json:"height"`
25
+ Size string `json:"size"`
26
+ }
27
+
20
28
type result struct {
21
29
Slug string `json:"slug"`
22
30
Images struct {
23
- Original struct {
24
- URL string `json:"url"`
25
- // Giphy returns ints as strings..
26
- Width string `json:"width"`
27
- Height string `json:"height"`
28
- Size string `json:"size"`
29
- } `json:"original"`
31
+ Downsized image `json:"downsized"`
32
+ Original image `json:"original"`
30
33
} `json:"images"`
31
34
}
32
35
@@ -38,13 +41,18 @@ type giphySearch struct {
38
41
//
39
42
// Example request:
40
43
// {
41
- // "api_key": "dc6zaTOxFJmzC"
44
+ // "api_key": "dc6zaTOxFJmzC",
45
+ // "use_downsized": false
42
46
// }
43
47
type Service struct {
44
48
types.DefaultService
45
49
// The Giphy API key to use when making HTTP requests to Giphy.
46
50
// The public beta API key is "dc6zaTOxFJmzC".
47
51
APIKey string `json:"api_key"`
52
+ // Whether to use the downsized image from Giphy.
53
+ // Uses the original image when set to false.
54
+ // Defaults to false.
55
+ UseDownsized bool `json:"use_downsized"`
48
56
}
49
57
50
58
// Commands supported:
@@ -68,10 +76,16 @@ func (s *Service) cmdGiphy(client *gomatrix.Client, roomID, userID string, args
68
76
if err != nil {
69
77
return nil , err
70
78
}
71
- if gifResult .Images .Original .URL == "" {
79
+
80
+ image := gifResult .Images .Original
81
+ if s .UseDownsized {
82
+ image = gifResult .Images .Downsized
83
+ }
84
+
85
+ if image .URL == "" {
72
86
return nil , fmt .Errorf ("No results" )
73
87
}
74
- resUpload , err := client .UploadLink (gifResult . Images . Original .URL )
88
+ resUpload , err := client .UploadLink (image .URL )
75
89
if err != nil {
76
90
return nil , err
77
91
}
@@ -81,10 +95,10 @@ func (s *Service) cmdGiphy(client *gomatrix.Client, roomID, userID string, args
81
95
Body : gifResult .Slug ,
82
96
URL : resUpload .ContentURI ,
83
97
Info : gomatrix.ImageInfo {
84
- Height : asInt (gifResult . Images . Original .Height ),
85
- Width : asInt (gifResult . Images . Original .Width ),
98
+ Height : asInt (image .Height ),
99
+ Width : asInt (image .Width ),
86
100
Mimetype : "image/gif" ,
87
- Size : asInt (gifResult . Images . Original .Size ),
101
+ Size : asInt (image .Size ),
88
102
},
89
103
}, nil
90
104
}
0 commit comments