cinch-url-scraper 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: fd77a3f970e23ec9b380360821ea4be3115c0deb
4
+ data.tar.gz: 681e538e924fecaebc53094631a5a399a770d29f
5
+ SHA512:
6
+ metadata.gz: 59dfc1a8fc399ee5e49b331e4ddacb81dd0b454cf47b5adcb5a71333d61c12bca82695f27d67cac37ff2b37882de6af4b7741f55a3104cc2c68dfb9e36f3bca2
7
+ data.tar.gz: 35977529ba01b3e13e1425b3ef691057a926adce887cff79be7cd5c6b9bd2520b201864f1e2397f9e57b96997bd626bab5a371cbef39e80f293df372b6ddf93a
data/README.md CHANGED
@@ -7,7 +7,7 @@ A Cinch plugin to get information about posted URLs.
7
7
  First install the gem by running:
8
8
 
9
9
  ```bash
10
- gem install cinch-url-scrapper
10
+ gem install cinch-url-scraper
11
11
  ```
12
12
 
13
13
  Then load it in your bot:
@@ -18,7 +18,9 @@ require "cinch/plugins/urlscraper"
18
18
 
19
19
  bot = Cinch::Bot.new do
20
20
  configure do |c|
21
- c.plugins.plugins = [Cinch::Plugins::UmlScraper]
21
+ c.plugins.plugins = [Cinch::Plugins::UrlScraper]
22
+ c.plugins.options[Cinch::Plugins::UrlScraper] = { enabled_channels: ["#Foo", "#Bar"] } # This line is not required
23
+
22
24
  end
23
25
  end
24
26
 
@@ -31,6 +33,11 @@ bot.start
31
33
  <url> # display url title / information
32
34
  ```
33
35
 
36
+ ```irc
37
+ !url <on|off> # toggles URL scraping on and off for that channel
38
+ ```
39
+
40
+
34
41
  ## Example
35
42
 
36
43
  <mpapis>: git@gist.github.com:3505088.git:
@@ -1,4 +1,5 @@
1
1
  # source: http://subforge.org/projects/shreds/repository/entry/bot/cinch.rb#L396
2
+
2
3
  # @copyright (c) 2010-2012, Christoph Kappel <unexist@dorfelite.net>
3
4
 
4
5
  require "json"
@@ -8,9 +9,19 @@ module Cinch
8
9
  module Plugins
9
10
  class UrlScraper
10
11
  include Cinch::Plugin
12
+ include Cinch::Helpers
11
13
 
12
14
  listen_to :channel
15
+ set :plugin_name, 'urlscraper'
16
+ set :help, <<-USAGE.gsub(/^ {6}/, '')
17
+ If enabled, this plugin will return the title of the webpage that you or another user posts in the channel. For YouTube and IMDB there are special outputs for relevent information.
18
+ Enable/Disable Usage:
19
+ - !url [on/off]: This command will turn the URL Scraper on or off for the channel you use this command in.
20
+ USAGE
21
+
13
22
  def listen(m)
23
+ return if m.message.include? "nospoil"
24
+ return if config[:enabled_channels] && ! config[:enabled_channels].include?(m.channel.name)
14
25
  # Create mechanize agent
15
26
  if @agent.nil?
16
27
  @agent = Mechanize.new
@@ -51,24 +62,31 @@ module Cinch
51
62
  # Get votes
52
63
  votes = page.search("//a/span[@itemprop='ratingCount']").text
53
64
 
54
- m.reply "Title: %s (at %s, %s/10 from %s users)" % [
55
- title, uri.host, rating, votes
65
+ m.reply "#{m.user.nick}'s IMDB Title: %s (Rating: %s/10 from %s users)" % [
66
+ title, rating, votes
56
67
  ]
68
+
57
69
  when "www.youtube.com"
58
70
  # Reload with nofeather
59
71
  page = @agent.get(link + "&nofeather=True")
60
72
 
61
73
  # Get page hits
62
- hits = page.search("//span[@class='watch-view-count']/strong")
63
- hits = hits.text.gsub(/[.,]/, "")
74
+ hits = page.search("//span[@class='watch-view-count ']")
75
+ hits = hits.text.gsub(/[.,]/, ",")
64
76
 
65
77
  # Get likes
66
- likes = page.search("//span[@class='watch-likes-dislikes']")
67
- likes = likes.text.gsub(/[.,]/, "")
68
-
69
- m.reply "Title: %s (at %s, %s hits, %s)" % [
70
- title, uri.host, hits, likes.strip
78
+ likes = page.search("//span[@class='likes-count']")
79
+ likes = likes.text.gsub(/[.,]/, ",")
80
+
81
+ # Get dislikes
82
+ dislikes = page.search("//span[@class='dislikes-count']")
83
+ dislikes = dislikes.text.gsub(/[.,]/, ",")
84
+
85
+ m.reply "#{m.user.nick}'s YT Title: %s (Views: %s, Likes: %s || Dislikes: %s)" % [
86
+ title, hits.strip, likes.strip, dislikes.strip
71
87
  ]
88
+
89
+
72
90
  when "gist.github.com"
73
91
  # Get owner
74
92
  owner = page.search("//div[@class='name']/a").inner_html
@@ -98,6 +116,7 @@ module Cinch
98
116
  ]
99
117
  when "subforge.org", "subtle.de"
100
118
  m.reply "Title: %s (at %s)" % [ title, uri.host ]
119
+
101
120
  when "twitter.com"
102
121
  if link =~ /\/status\/(\d+)$/
103
122
  json = @agent.get("https://api.twitter.com/1/statuses/show/#{$1}.json?trim_user=1").body
@@ -111,8 +130,34 @@ module Cinch
111
130
  else
112
131
  m.reply "Title: %s (at %s)" % [ title, uri.host ] if title
113
132
  end
133
+ end
134
+ end
135
+
136
+ match /url (on|off)$/
137
+
138
+ def execute(m, option)
139
+
140
+ config[:enabled_channels] ||= [bot.channels.map(&:name)]
141
+ puts bot.channels.map(&:name)
142
+
143
+ @url = option == "on"
144
+
145
+ case option
146
+ when "on"
147
+ config[:enabled_channels] << m.channel.name
148
+ else
149
+ config[:enabled_channels].delete(m.channel.name)
150
+ end
151
+
152
+ m.reply Format(:green, "URL Scraping for #{m.channel} is now #{@url ? 'enabled' : 'disabled'}!")
153
+
154
+ @bot.debug("#{self.class.name} → #{config[:enabled_channels].inspect}");
155
+
156
+ config[:enabled_channels]=nil if config[:enabled_channels]==[]
157
+
158
+ rescue
159
+ m.reply Format(:red, "Error: #{$!}")
160
+ end
161
+ end
114
162
  end
115
- end
116
- end
117
- end
118
- end
163
+ end
metadata CHANGED
@@ -1,20 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-url-scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michal Papis
8
+ - Richard Banks
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000 Z
12
+ date: 2014-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cinch
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
18
  - - ~>
20
19
  - !ruby/object:Gem::Version
@@ -22,7 +21,6 @@ dependencies:
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ~>
28
26
  - !ruby/object:Gem::Version
@@ -30,7 +28,6 @@ dependencies:
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: mechanize
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
32
  - - ~>
36
33
  - !ruby/object:Gem::Version
@@ -38,7 +35,6 @@ dependencies:
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
39
  - - ~>
44
40
  - !ruby/object:Gem::Version
@@ -46,6 +42,7 @@ dependencies:
46
42
  description: A Cinch plugin to get information about posted URLs.
47
43
  email:
48
44
  - mpapis@gmail.com
45
+ - namaste@rawrnet.net
49
46
  executables: []
50
47
  extensions: []
51
48
  extra_rdoc_files: []
@@ -55,26 +52,25 @@ files:
55
52
  - lib/cinch/plugins/urlscraper.rb
56
53
  homepage: https://github.com/mpapis/cinch-url-scraper
57
54
  licenses: []
55
+ metadata: {}
58
56
  post_install_message:
59
57
  rdoc_options: []
60
58
  require_paths:
61
59
  - lib
62
60
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
61
  requirements:
65
62
  - - ! '>='
66
63
  - !ruby/object:Gem::Version
67
64
  version: 1.9.1
68
65
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
66
  requirements:
71
67
  - - ! '>='
72
68
  - !ruby/object:Gem::Version
73
69
  version: '0'
74
70
  requirements: []
75
71
  rubyforge_project:
76
- rubygems_version: 1.8.24
72
+ rubygems_version: 2.1.11
77
73
  signing_key:
78
- specification_version: 3
74
+ specification_version: 4
79
75
  summary: A Cinch plugin to get information about posted URLs.
80
76
  test_files: []