Skip to content

Commit

Permalink
!image eats !gif
Browse files Browse the repository at this point in the history
!gif maybe used to use Reddit, but now it's basically the same as !image
with a parameter requesting animated images.

Signed-off-by: Robb Kidd <robb@thekidds.org>
  • Loading branch information
robbkidd committed Jul 24, 2020
1 parent 19e98e5 commit a00decf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 71 deletions.
68 changes: 0 additions & 68 deletions plugins/gif.rb

This file was deleted.

13 changes: 10 additions & 3 deletions plugins/image.rb
Expand Up @@ -8,12 +8,18 @@
class Image < Linkbot::Plugin

def initialize
register :regex => /!image(?: (.+))?/
help "!image [searchity search] - Return a relevant picture"
register :regex => /\A!(gif|image)(?: (.+))?/i

help <<~HELP
!image [searchity search] - Return a relevant picture
!gif [searchity search] - make that an animated image, barkeep!
HELP
end

def on_message(message, matches)
color = nil
gif_requested = message.body.start_with?('!gif ')

searchterm = matches[0]
if searchterm.nil?
past_messages = message_history(message)
Expand All @@ -26,6 +32,7 @@ def on_message(message, matches)

searchterm = URI.encode(searchterm)
searchurl = "https://www.google.com/search?tbm=isch&q=#{searchterm}&safe=active"
searchurl += "&tbs=itp:animated" if gif_requested

# this is an old iphone user agent. Seems to make google return good results.
useragent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"
Expand Down Expand Up @@ -56,7 +63,7 @@ def on_message(message, matches)

url = images.sample

if wallpaper?(url)
if !gif_requested && wallpaper?(url)
url = [url, "(dealwithit) WALLPAPER WALLPAPER WALLPAPER (dealwithit)"]
end

Expand Down

0 comments on commit a00decf

Please sign in to comment.