cinch-links-logger 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -21
- data/cinch-links-logger.gemspec +6 -5
- data/lib/cinch/plugins/links-logger/link.rb +17 -0
- data/lib/cinch/plugins/links-logger/version.rb +3 -1
- data/lib/cinch/plugins/{links-logger/links-logger.rb → links-logger.rb} +9 -25
- data/lib/cinch-links-logger.rb +3 -1
- data/spec/cinch-links-logger_spec.rb +8 -0
- metadata +7 -4
data/README.md
CHANGED
@@ -29,30 +29,13 @@ You will need to add the Plugin and config to your list first;
|
|
29
29
|
@bot = Cinch::Bot.new do
|
30
30
|
configure do |c|
|
31
31
|
c.plugins.plugins = [Cinch::Plugins::LinksLogger]
|
32
|
-
|
33
|
-
|
34
|
-
:filename => 'yaml/links.yml',
|
35
|
-
:whitelist => nil,
|
36
|
-
:blacklist => nil }
|
32
|
+
# If you need to specify an alternate path
|
33
|
+
c.plugins.options[Cinch::Plugins::LinksTumblr] = { :filename => 'yaml/links.yml' }
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
:titles (boolean) - Setting this to true will print the URL's title to the channel.
|
43
|
-
|
44
|
-
:stats (boolean) - Setting this to true will print the name of the user who first linked
|
45
|
-
the URL, if applicable.
|
46
|
-
|
47
|
-
:blacklist - An array of domains that you want to ignore, e.g.
|
48
|
-
|
49
|
-
:blackist => ['twitter', 'reddit']
|
50
|
-
|
51
|
-
:whitelist - An array of domains that you want limit title printing and logging to, e.g.
|
52
|
-
|
53
|
-
:whitelist => ['youtube']
|
54
|
-
|
55
|
-
:filename - the file to store previously linked urls.
|
37
|
+
Links in the channel will be captured and users who type `!links` in channel will receive a
|
38
|
+
list of the last 10 links (this will be configurable in the future).
|
56
39
|
|
57
40
|
## Contributing
|
58
41
|
|
data/cinch-links-logger.gemspec
CHANGED
@@ -4,18 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'cinch/plugins/links-logger/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'cinch-links-logger'
|
8
8
|
gem.version = Cinch::Plugins::LinksLogger::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
9
|
+
gem.authors = ['Brian Haberer']
|
10
|
+
gem.email = ['bhaberer@gmail.com']
|
11
11
|
gem.description = %q{Cinch Plugin to track links in the channel}
|
12
12
|
gem.summary = %q{Cinch Plugin for links logging}
|
13
|
-
gem.homepage =
|
13
|
+
gem.homepage = 'https://github.com/bhaberer/cinch-links-logger'
|
14
|
+
gem.license = 'MIT'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
19
|
+
gem.require_paths = ['lib']
|
19
20
|
|
20
21
|
gem.add_development_dependency 'rake'
|
21
22
|
gem.add_development_dependency 'rspec'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Class to track Link data
|
3
|
+
class Link
|
4
|
+
attr_accessor :nick, :title, :count, :short_url, :time
|
5
|
+
|
6
|
+
def initialize(nick, url, time = Time.now)
|
7
|
+
@nick = nick
|
8
|
+
@title = Cinch::Toolbox.get_page_title(url)
|
9
|
+
@count = 0
|
10
|
+
@short_url = Cinch::Toolbox.shorten(url)
|
11
|
+
@time = time
|
12
|
+
end
|
13
|
+
|
14
|
+
def inc_count(count = 1)
|
15
|
+
@count += count
|
16
|
+
end
|
17
|
+
end
|
@@ -3,29 +3,23 @@ require 'open-uri'
|
|
3
3
|
require 'cinch'
|
4
4
|
require 'cinch/toolbox'
|
5
5
|
require 'cinch-storage'
|
6
|
-
require 'time-lord'
|
7
|
-
|
8
|
-
class Link < Struct.new(:nick, :title, :count, :short_url, :time)
|
9
|
-
def to_yaml
|
10
|
-
{nick: nick, title: title, count: count, short_url: short_url, time: time }
|
11
|
-
end
|
12
|
-
end
|
13
6
|
|
14
7
|
module Cinch::Plugins
|
8
|
+
# Cinch Plugin to track links
|
15
9
|
class LinksLogger
|
16
10
|
include Cinch::Plugin
|
17
11
|
attr_reader :storage
|
18
12
|
|
19
13
|
listen_to :channel
|
20
14
|
|
21
|
-
self.help = 'Use .links to see the last links
|
15
|
+
self.help = 'Use .links to see the last links posted to the channel.'
|
22
16
|
|
23
17
|
match /links/
|
24
18
|
|
25
19
|
def initialize(*args)
|
26
20
|
super
|
27
21
|
@storage = CinchStorage.new(config[:filename] || 'yaml/links.yaml')
|
28
|
-
@storage.data ||=
|
22
|
+
@storage.data ||= {}
|
29
23
|
end
|
30
24
|
|
31
25
|
def execute(m)
|
@@ -34,14 +28,12 @@ module Cinch::Plugins
|
|
34
28
|
end
|
35
29
|
|
36
30
|
def listen(m)
|
37
|
-
urls = URI.extract(m.message,
|
31
|
+
urls = URI.extract(m.message, %w(http https))
|
38
32
|
urls.each do |url|
|
39
33
|
# Ensure we have a Channel Object in the History to dump links into.
|
40
34
|
@storage.data[m.channel.name] ||= Hash.new
|
41
35
|
@link = get_or_create_link(m, url)
|
42
36
|
end
|
43
|
-
# Save if we matched urls.
|
44
|
-
@storage.synced_save(@bot) if urls
|
45
37
|
end
|
46
38
|
|
47
39
|
private
|
@@ -49,23 +41,15 @@ module Cinch::Plugins
|
|
49
41
|
def get_or_create_link(m, url)
|
50
42
|
channel = m.channel.name
|
51
43
|
# If the link was posted already, get the old info instead of getting new
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
link = Link.new(m.user.nick,
|
57
|
-
Cinch::Toolbox.get_page_title(url),
|
58
|
-
1, Cinch::Toolbox.shorten(url), Time.now)
|
59
|
-
@storage.data[channel][url] = link
|
60
|
-
end
|
61
|
-
return link
|
44
|
+
@storage.data[channel][url] ||= Link.new(m.user.nick, url)
|
45
|
+
@storage.data[channel][url].inc_count
|
46
|
+
@storage.synced_save(@bot)
|
47
|
+
@storage.data[channel][url]
|
62
48
|
end
|
63
49
|
|
64
50
|
def get_recent_links(channel)
|
65
51
|
message = ["Recent Links in #{channel}"]
|
66
52
|
links = @storage.data[channel].values.reverse[0..9]
|
67
|
-
puts links.to_s
|
68
|
-
puts message
|
69
53
|
links.each_with_index do |link|
|
70
54
|
message << if link.title.nil?
|
71
55
|
Cinch::Toolbox.expand(link.short_url)
|
@@ -73,7 +57,7 @@ module Cinch::Plugins
|
|
73
57
|
"#{link.short_url} - #{link.title}"
|
74
58
|
end
|
75
59
|
end
|
76
|
-
|
60
|
+
message
|
77
61
|
end
|
78
62
|
end
|
79
63
|
end
|
data/lib/cinch-links-logger.rb
CHANGED
@@ -14,6 +14,14 @@ describe Cinch::Plugins::LinksLogger do
|
|
14
14
|
should == 'http://github.com'
|
15
15
|
end
|
16
16
|
|
17
|
+
it 'should capture links count' do
|
18
|
+
15.times { get_replies(make_message(@bot, 'http://github.com', { channel: '#foo' })) }
|
19
|
+
links = @bot.plugins.first.storage.data['#foo']
|
20
|
+
puts "\n\n#{links}\n\n"
|
21
|
+
links.length.should == 1
|
22
|
+
links.values.first.count.should == 15
|
23
|
+
end
|
24
|
+
|
17
25
|
it 'should not capture malformed URLS' do
|
18
26
|
get_replies(make_message(@bot, 'htp://github.com', { channel: '#foo', nick: 'bar' }))
|
19
27
|
get_replies(make_message(@bot, 'http/github.com', { channel: '#foo', nick: 'bar' }))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-links-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -170,12 +170,14 @@ files:
|
|
170
170
|
- Rakefile
|
171
171
|
- cinch-links-logger.gemspec
|
172
172
|
- lib/cinch-links-logger.rb
|
173
|
-
- lib/cinch/plugins/links-logger
|
173
|
+
- lib/cinch/plugins/links-logger.rb
|
174
|
+
- lib/cinch/plugins/links-logger/link.rb
|
174
175
|
- lib/cinch/plugins/links-logger/version.rb
|
175
176
|
- spec/cinch-links-logger_spec.rb
|
176
177
|
- spec/spec_helper.rb
|
177
178
|
homepage: https://github.com/bhaberer/cinch-links-logger
|
178
|
-
licenses:
|
179
|
+
licenses:
|
180
|
+
- MIT
|
179
181
|
post_install_message:
|
180
182
|
rdoc_options: []
|
181
183
|
require_paths:
|
@@ -201,3 +203,4 @@ summary: Cinch Plugin for links logging
|
|
201
203
|
test_files:
|
202
204
|
- spec/cinch-links-logger_spec.rb
|
203
205
|
- spec/spec_helper.rb
|
206
|
+
has_rdoc:
|