Class: Cinch::Plugins::LinksLogger

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

Overview

Versioning info

Constant Summary collapse

VERSION =
'1.0.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ LinksLogger

Returns a new instance of LinksLogger.



20
21
22
23
24
# File 'lib/cinch/plugins/links-logger.rb', line 20

def initialize(*args)
  super
  @storage = Cinch::Storage.new(config[:filename] || 'yaml/links.yaml')
  @storage.data ||= {}
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



12
13
14
# File 'lib/cinch/plugins/links-logger.rb', line 12

def storage
  @storage
end

Instance Method Details

#execute(m) ⇒ Object



26
27
28
29
# File 'lib/cinch/plugins/links-logger.rb', line 26

def execute(m)
  return if Cinch::Toolbox.sent_via_private_message?(m)
  get_recent_links(m.channel.name).each { |line| m.user.send line }
end

#listen(m) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/cinch/plugins/links-logger.rb', line 31

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[m.channel.name] ||= Hash.new
    @link = get_or_create_link(m, url)
  end
end