Skip to content

Commit

Permalink
[elastic,gimmeproxy,gfycat] minor improvements
Browse files Browse the repository at this point in the history
fixes ROBYUL-DISCORD-65 and ROBYUL-DISCORD-E2
  • Loading branch information
Seklfreak committed Jan 3, 2018
1 parent e95a60b commit 2c48d70
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion helpers/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
13 changes: 8 additions & 5 deletions helpers/gimmeproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"time"

"strings"

"github.com/Seklfreak/Robyul2/cache"
)

Expand Down Expand Up @@ -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)
}
}

Expand Down
8 changes: 6 additions & 2 deletions modules/plugins/gfycat.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,20 @@ 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.")
helpers.Relax(err)
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)
Expand Down

0 comments on commit 2c48d70

Please sign in to comment.