Class: Cinch::Plugins::LinksTumblr

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/links-tumblr/version.rb,
lib/cinch/plugins/links-tumblr.rb

Overview

Cinch Plugin to tumbl links from a given channel to a configured tumblr.

Constant Summary collapse

VERSION =
'1.0.1'

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ LinksTumblr

Returns a new instance of LinksTumblr.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cinch/plugins/links-tumblr.rb', line 20

def initialize(*args)
  super
  @storage = CinchStorage.new(config[:filename] || 'yaml/tumblr.yml')
  @storage.data ||= {}
  @hostname = config[:hostname]
  @password = config[:password]
  @creds = { consumer_key:    config[:consumer_key],
             consumer_secret: config[:consumer_secret],
             token:           config[:token],
             token_secret:    config[:token_secret] }
  credential_check
end

Instance Method Details

#execute(m) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/cinch/plugins/links-tumblr.rb', line 33

def execute(m)
  return if Cinch::Toolbox.sent_via_private_message?(m)

  if @hostname
    msg = "Links are available @ http://#{@hostname}"
    msg << " Password: #{@password}" unless @password.nil?
    m.user.send msg
  end
end

#listen(m) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cinch/plugins/links-tumblr.rb', line 43

def listen(m)
  urls = URI.extract(m.message, %w(http https))
  urls.each do |url|
    @storage.data[m.channel.name] ||= []

    # Check to see if we've seen the link
    unless @storage.data[m.channel.name].include?(url)
      tumble(url, m.user.nick)

      # Store the links to try and cut down on popular urls getting
      # tumbled 20 times
      @storage.data[m.channel.name] << url
    end
    @storage.synced_save(@bot)
  end
end