Class: Plugins::Snooper

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, Cinch::Helpers, Cinch::Plugin
Defined in:
lib/Zeta/plugins/snooper.rb

Instance Method Summary collapse

Methods included from Cinch::Plugin

#check?, #log2chan

Instance Method Details

#execute(msg, url) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/Zeta/plugins/snooper.rb', line 53

def execute(msg, url)
  url = "http://#{url}" unless url=~/^https?:\/\//
  url = URI.encode(url)

  # Ignore items on blacklist
  # blacklist = DEFAULT_BLACKLIST.dup
  # blacklist.concat(config[:blacklist]) if config[:blacklist]
  # return if blacklist.any?{|entry| url =~ entry}

  # Log
  # debug "URL matched: #{url}"

  # Parse URI
  p = URI(url)

  # Disregaurd on blacklist
  return if Blacklist.urls.include? p.host

  # API key lookup
  VideoInfo.provider_api_keys = { youtube: Config.secrets[:google] }

  # Parse out specific websites
  if p.host == 'youtube.com' || p.host == 'www.youtube.com' || p.host == 'youtu.be'
    match_youtube(msg, url)
  elsif p.host == 'i.imgur.com' || p.host == 'imgur.com'
    match_imgur(msg, url)
  else
    match_other(msg,url)
  end

rescue => e
  error "#{e.class.name}: #{e.message}"
  error "[404] #{msg.user} - #{url}"
end