From 2c48d7038a6ba166b039630de674c60bc7e4d3ca Mon Sep 17 00:00:00 2001 From: Sebastian Winkler Date: Wed, 3 Jan 2018 17:43:23 +0100 Subject: [PATCH] [elastic,gimmeproxy,gfycat] minor improvements fixes ROBYUL-DISCORD-65 and ROBYUL-DISCORD-E2 --- helpers/elastic.go | 2 +- helpers/gimmeproxy.go | 13 ++++++++----- modules/plugins/gfycat.go | 8 ++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/helpers/elastic.go b/helpers/elastic.go index 86e80724..6a793b82 100644 --- a/helpers/elastic.go +++ b/helpers/elastic.go @@ -289,7 +289,7 @@ func ElasticUpdateMessage(message *discordgo.Message) error { } if message.Content == "" { - message.Content = " " + message.Content = "/" } _, err = cache.GetElastic().Update().Index(models.ElasticIndexMessages).Type("doc").Id(elasticID). diff --git a/helpers/gimmeproxy.go b/helpers/gimmeproxy.go index 184368f3..b10454f9 100644 --- a/helpers/gimmeproxy.go +++ b/helpers/gimmeproxy.go @@ -7,6 +7,8 @@ import ( "time" + "strings" + "github.com/Seklfreak/Robyul2/cache" ) @@ -75,11 +77,12 @@ func GetRandomProxy() (proxy http.Transport, err error) { ) proxyUrlString, err := GimmeProxy() if err != nil { - return proxy, err - } - _, err = redis.SAdd(PROXIES_KEY, proxyUrlString).Result() - if err != nil { - return proxy, err + if !strings.Contains(err.Error(), "expected status 200; got 429") { + RelaxLog(err) + } + } else { + _, err = redis.SAdd(PROXIES_KEY, proxyUrlString).Result() + RelaxLog(err) } } diff --git a/modules/plugins/gfycat.go b/modules/plugins/gfycat.go index 23254e4a..878e9ece 100644 --- a/modules/plugins/gfycat.go +++ b/modules/plugins/gfycat.go @@ -117,7 +117,7 @@ func (m *Gfycat) Action(command string, content string, msg *discordgo.Message, CheckGfycatStatusLoop: for { statusGfycatEndpoint := fmt.Sprintf(gfycatApiBaseUrl, fmt.Sprintf("gfycats/fetch/status/%s", gfyName)) - result, err := gabs.ParseJSON(helpers.NetGet(statusGfycatEndpoint)) + rawResult, err := helpers.NetGetUAWithError(statusGfycatEndpoint, helpers.DEFAULT_UA) if err != nil { if strings.Contains(err.Error(), "Expected status 200; Got 504") { _, err := helpers.SendMessage(msg.ChannelID, fmt.Sprintf("<@%s> ", msg.Author.ID)+helpers.GetTextF("bot.errors.general", "Gfycat Status Error")+"\nPlease check the link or try again later.") @@ -125,8 +125,12 @@ CheckGfycatStatusLoop: return } } + result, err := gabs.ParseJSON(rawResult) + helpers.Relax(err) + + taskData, _ := result.Path("task").Data().(string) - switch result.Path("task").Data().(string) { + switch taskData { case "encoding": time.Sleep(5 * time.Second) session.ChannelTyping(msg.ChannelID)