cinch-links-logger 0.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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +1 -0
- data/cinch-links-logger.gemspec +23 -0
- data/lib/cinch-links-logger.rb +2 -0
- data/lib/cinch/plugins/links-logger/links-logger.rb +110 -0
- data/lib/cinch/plugins/links-logger/version.rb +7 -0
- metadata +102 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian Haberer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Cinch::Plugins::LinksLogger
|
2
|
+
|
3
|
+
Cinch Plugin for logging links and printing titles / stats for linked urls.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cinch-links-logger'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cinch-links-logger
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You will need to add the Plugin and config to your list first;
|
22
|
+
|
23
|
+
@bot = Cinch::Bot.new do
|
24
|
+
configure do |c|
|
25
|
+
c.plugins.plugins = [Cinch::Plugins::LinksLogger]
|
26
|
+
c.plugins.options[Cinch::Plugins::LinksTumblr] = { :stats => true,
|
27
|
+
:titles => true,
|
28
|
+
:filename => 'yaml/links.yml',
|
29
|
+
:whitelist => nil,
|
30
|
+
:blacklist => nil }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
The configuration variables are all optional, what's listed are their defaults
|
35
|
+
|
36
|
+
:titles (boolean) - Setting this to true will print the URL's title to the channel.
|
37
|
+
|
38
|
+
:stats (boolean) - Setting this to true will print the name of the user who first linked
|
39
|
+
the URL, if applicable.
|
40
|
+
|
41
|
+
:blacklist - An array of domains that you want to ignore, e.g.
|
42
|
+
|
43
|
+
:blackist => ['twitter', 'reddit']
|
44
|
+
|
45
|
+
:whitelist - An array of domains that you want limit title printing and logging to, e.g.
|
46
|
+
|
47
|
+
:whitelist => ['youtube']
|
48
|
+
|
49
|
+
:filename - the file to store previously linked urls.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cinch/plugins/links-logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "cinch-links-logger"
|
8
|
+
gem.version = Cinch::Plugins::LinksLogger::VERSION
|
9
|
+
gem.authors = ["Brian Haberer"]
|
10
|
+
gem.email = ["bhaberer@gmail.com"]
|
11
|
+
gem.description = %q{Cinch Plugin to track links in the channel}
|
12
|
+
gem.summary = %q{Cinch Plugin for links logging}
|
13
|
+
gem.homepage = "https://github.com/bhaberer/cinch-links-logger"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency('cinch-storage', '>= 0.0.1')
|
21
|
+
gem.add_dependency('cinch-toolbox', '>= 0.0.5')
|
22
|
+
gem.add_dependency('time-lord', '>= 1.0.1')
|
23
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'open-uri'
|
3
|
+
require 'cinch-storage'
|
4
|
+
require 'cinch-toolbox'
|
5
|
+
require 'time-lord'
|
6
|
+
|
7
|
+
module Cinch::Plugins
|
8
|
+
class LinksLogger
|
9
|
+
include Cinch::Plugin
|
10
|
+
|
11
|
+
listen_to :channel
|
12
|
+
|
13
|
+
self.help = 'Use .links to see the last links users have posted to the channel.'
|
14
|
+
|
15
|
+
match /links/
|
16
|
+
|
17
|
+
def initialize(*args)
|
18
|
+
super
|
19
|
+
@storage = CinchStorage.new(config[:filename] || 'yaml/links.yaml')
|
20
|
+
@storage.data[:history] ||= Hash.new
|
21
|
+
@post_titles = config[:titles].nil? ? true : config[:titles]
|
22
|
+
@post_stats = config[:stats].nil? ? true : config[:stats]
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(m)
|
26
|
+
if m.channel.nil?
|
27
|
+
m.user.msg "You must use that command in the main channel."
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
m.user.send "Recent Links in #{m.channel}"
|
32
|
+
last = @storage.data[:history][m.channel.name].values.sort {|a,b| b[:time] <=> a[:time] }
|
33
|
+
last[0,10].each_with_index do |link, i|
|
34
|
+
msg = "#{i + 1} - "
|
35
|
+
if link[:title].nil?
|
36
|
+
msg << Cinch::Toolbox.expand(@link[:short_url])
|
37
|
+
else
|
38
|
+
msg << "#{link[:short_url]} ∴ #{link[:title]}"
|
39
|
+
end
|
40
|
+
m.user.send msg
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def listen(m)
|
45
|
+
urls = URI.extract(m.message, ["http", "https"])
|
46
|
+
urls.each do |url|
|
47
|
+
# Ensure we have a Channel Object in the History to dump links into.
|
48
|
+
@storage.data[:history][m.channel.name] ||= Hash.new
|
49
|
+
|
50
|
+
# Make sure it conforms to white/black lists before bothering.
|
51
|
+
if whitelisted?(url) && !blacklisted?(url)
|
52
|
+
# If the link was posted already, get the old info instead of getting new
|
53
|
+
if @storage.data[:history][m.channel.name].key?(url)
|
54
|
+
@storage.data[:history][m.channel.name][url][:count] += 1
|
55
|
+
@link = @storage.data[:history][m.channel.name][url]
|
56
|
+
else
|
57
|
+
@link = { :nick => m.user.nick,
|
58
|
+
:title => Cinch::Toolbox.get_page_title(url) || nil,
|
59
|
+
:count => 1,
|
60
|
+
:short_url => Cinch::Toolbox.shorten(url),
|
61
|
+
:time => Time.now }
|
62
|
+
@storage.data[:history][m.channel.name][url] = @link
|
63
|
+
end
|
64
|
+
else
|
65
|
+
debug "#{blacklisted?(url) ? 'Blacklisted URL was not logged' : 'Domain not Whitelisted'} #{url}"
|
66
|
+
return
|
67
|
+
end
|
68
|
+
|
69
|
+
# Check to see if we should post titles
|
70
|
+
if @post_titles
|
71
|
+
# Only spam the channel if you have a title
|
72
|
+
unless @link[:title].nil?
|
73
|
+
m.reply "#{@link[:short_url] || url} ∴ #{@link[:title]}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check to see if we should post stats and if it'ss been linked more than once.
|
78
|
+
if @post_stats && @link[:count] > 1
|
79
|
+
# No stats if this person was the first one to link it
|
80
|
+
unless @link[:nick] == m.user.nick
|
81
|
+
m.reply "That was already linked by #{@link[:nick]} #{@link[:time].ago.to_words}.", true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Don't save unless we found some urls to process
|
87
|
+
if urls
|
88
|
+
synchronize(:save_links) do
|
89
|
+
@storage.save
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def whitelisted?(url)
|
97
|
+
return true unless config[:whitelist]
|
98
|
+
debug "Checking Whitelist! #{config[:whitelist]} url: #{url}"
|
99
|
+
return true if url.match(Regexp.new("https:?\/\/.*\.?#{config[:whitelist].join('|')}\."))
|
100
|
+
false
|
101
|
+
end
|
102
|
+
|
103
|
+
def blacklisted?(url)
|
104
|
+
return false unless config[:blacklist]
|
105
|
+
debug "Checking Blacklist! #{config[:blacklist]} url: #{url}"
|
106
|
+
return true if url.match(Regexp.new("https:?\/\/.*\.?#{config[:blacklist].join('|')}\."))
|
107
|
+
false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-links-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Haberer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cinch-storage
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: cinch-toolbox
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.5
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.5
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: time-lord
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.1
|
62
|
+
description: Cinch Plugin to track links in the channel
|
63
|
+
email:
|
64
|
+
- bhaberer@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- cinch-links-logger.gemspec
|
75
|
+
- lib/cinch-links-logger.rb
|
76
|
+
- lib/cinch/plugins/links-logger/links-logger.rb
|
77
|
+
- lib/cinch/plugins/links-logger/version.rb
|
78
|
+
homepage: https://github.com/bhaberer/cinch-links-logger
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.24
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Cinch Plugin for links logging
|
102
|
+
test_files: []
|