Class: Cinch::Plugins::LinksTitles

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

Overview

Versioning info

Defined Under Namespace

Classes: Link

Constant Summary collapse

VERSION =
'1.0.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ LinksTitles

Returns a new instance of LinksTitles.



25
26
27
28
29
30
31
# File 'lib/cinch/plugins/links-titles.rb', line 25

def initialize(*args)
  super
  @storage = Cinch::Storage.new(config[:filename] ||
                              'yaml/links-titles.yaml')
  @storage.data[:history] ||= {}
  @post_stats  = config[:stats].nil?  ? false : config[:stats]
end

Instance Attribute Details

#storageObject

Returns the value of attribute storage.



13
14
15
# File 'lib/cinch/plugins/links-titles.rb', line 13

def storage
  @storage
end

Instance Method Details

#listen(m) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cinch/plugins/links-titles.rb', line 33

def listen(m)
  urls = URI.extract(m.message, %w(http https))
  urls.each do |url|
    # Ensure we have a Channel Object in the History to dump links into.
    @storage.data[:history][m.channel.name] ||= Hash.new

    # Process link
    link = process_link(url, m.channel.name, m.user.nick)

    # Send link title to channel
    post_title(m, link)

    # Send link stats to channel
    post_stats(m, link)
  end

  # Don't save unless we found some urls to process
  @storage.synced_save(@bot) if urls
end