Permalink
Browse files

Fix giphy search..by using public api (while its available)

  • Loading branch information...
1 parent b3d2ce0 commit 1eb4c45a57ec432ea40b5f9b7b83cce9c8372633 @CrazyLemon CrazyLemon committed Dec 19, 2016
Showing with 4 additions and 6 deletions.
  1. +4 −6 scripts/chatter.coffee
View
@@ -121,12 +121,10 @@ module.exports = (bot) ->
r.reply bot.random vic
bot.regexp /^\.gif (.+)/, ".gif <query> -- Prikaže naključni gif", (match, r) ->
- url = "http://giphy.com/search/#{encodeURI(match[1].replace(/[^a-z0-9\s]/g,"").replace(/\s\s+/g, "-"))}"
- bot.fetchHTML url.replace(/%20/g, '-'), ($) ->
- count = $("#searchresults .found-count").text().split(" GIFs found for")
- if count[0] > 0
- gif_id = $(".hoverable-gif a").eq(0).attr("data-id")
- r.reply "http://media.giphy.com/media/#{gif_id}/giphy.gif"
+ url = "http://api.giphy.com/v1/gifs/search?q=#{encodeURI(match[1].replace(/[^a-z0-9\s]/g,"").replace(/\s\s+/g, "+"))}&api_key=dc6zaTOxFJmzC"
+ bot.fetchJSON url.replace(/%20/g,'+'), (result) ->
+ if result.pagination.total_count > 0
+ r.reply result.data[0].images.fixed_height.url
else
r.reply "No gif available :("

0 comments on commit 1eb4c45

Please sign in to comment.