cinch-title 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,12 +4,15 @@ A plugin for the Cinch ircbot framework to output HTML-titles for URL:s posted t
4
4
 
5
5
  == Usage
6
6
 
7
+ require 'cinch'
8
+ require 'cinch/plugins/title'
9
+
7
10
  bot = Cinch::Bot.new do
8
11
  configure do |c|
9
12
  c.nick = "HTMLBot"
10
13
  c.server = "irc.freenode.org"
11
14
  c.channels = ["#cinchbots"]
12
- c.plugins.plugins = [Cinch::Plugins::Netfeed::HTMLTitle]
15
+ c.plugins.plugins = [Cinch::Plugins::Title]
13
16
  c.plugins.options = {
14
17
  Cinch::Plugins::Netfeed::HTMLTitle => {
15
18
  "ignore" => [
@@ -20,6 +23,8 @@ A plugin for the Cinch ircbot framework to output HTML-titles for URL:s posted t
20
23
  end
21
24
  end
22
25
 
26
+ bot.start
27
+
23
28
  === Options
24
29
 
25
30
  ignore: a list of regexps of URI:S that should be ignored
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2010 Victor Bergöö
4
+ # This program is made available under the terms of the MIT License.
5
+
6
+ require 'cinch'
7
+ require 'nokogiri'
8
+ require 'curb'
9
+ require 'uri'
10
+ require 'cgi'
11
+
12
+ module Cinch
13
+ module Plugins
14
+ class Title
15
+ include Cinch::Plugin
16
+
17
+ match /(.*http.*)/, :use_prefix => false
18
+
19
+ def execute m, message
20
+ suffix = m.user.nick[-1] == 's' ? "'" : "'s"
21
+
22
+ URI.extract(message, ["http", "https"]) do |uri|
23
+ begin
24
+ next if ignore uri
25
+
26
+ m.reply "#{m.user.nick}#{suffix} URL: #{parse(uri)}"
27
+ rescue URI::InvalidURIError => e
28
+ m.reply "invalid url: #{uri}"
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def parse uri
36
+ content = Curl::Easy.perform(uri).body_str
37
+ html = Nokogiri::HTML(content)
38
+ title = html.xpath('//title').first
39
+
40
+ return "No title" if title.nil?
41
+ CGI.unescape_html title.text.gsub(/\s+/, ' ')
42
+ end
43
+
44
+ def ignore uri
45
+ ignore = ["jpg$", "JPG$", "jpeg$", "gif$", "png$", "bmp$", "pdf$"]
46
+ ignore += config["ignore"] if config.key? "ignore"
47
+
48
+ ignore.each do |re|
49
+ return true if uri =~ /#{re}/
50
+ end
51
+
52
+ false
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Victor Berg\xC3\xB6\xC3\xB6"
@@ -14,8 +14,8 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-05 00:00:00 +01:00
18
- default_executable: cinch-title
17
+ date: 2011-01-30 00:00:00 +01:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cinch
@@ -58,29 +58,24 @@ dependencies:
58
58
  version_requirements: *id003
59
59
  description: Plugin for the irc-framework Cinch to output HTML-titles
60
60
  email: victor.bergoo@gmail.com
61
- executables:
62
- - cinch-title
61
+ executables: []
62
+
63
63
  extensions: []
64
64
 
65
65
  extra_rdoc_files:
66
66
  - LICENSE
67
67
  - README.rdoc
68
68
  files:
69
- - .gitignore
70
69
  - LICENSE
71
70
  - README.rdoc
72
- - Rakefile
73
- - VERSION
74
- - bin/cinch-title
75
- - cinch-title.gemspec
76
- - lib/cinch-title.rb
71
+ - lib/cinch/plugins/title.rb
77
72
  has_rdoc: true
78
73
  homepage: http://github.com/netfeed/cinch-title
79
74
  licenses: []
80
75
 
81
76
  post_install_message:
82
- rdoc_options:
83
- - --charset=UTF-8
77
+ rdoc_options: []
78
+
84
79
  require_paths:
85
80
  - lib
86
81
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- pkg
data/Rakefile DELETED
@@ -1,21 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rubygems'
3
- require 'rake'
4
-
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gem|
8
- gem.name = "cinch-title"
9
- gem.summary = %Q{Plugin for Cinch to output HTML-titles}
10
- gem.description = %Q{Plugin for the irc-framework Cinch to output HTML-titles}
11
- gem.email = "victor.bergoo@gmail.com"
12
- gem.homepage = "http://github.com/netfeed/cinch-title"
13
- gem.authors = ["Victor Bergöö"]
14
- gem.add_dependency "cinch"
15
- gem.add_dependency "nokogiri"
16
- gem.add_dependency "curb"
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
data/bin/cinch-title DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- # Copyright (c) 2010 Victor Bergöö
4
- # This program is made available under the terms of the MIT License.
5
-
6
- require 'rubygems'
7
- require File.expand_path('../../lib/cinch-title', __FILE__)
8
-
9
- bot = Cinch::Bot.new do
10
- configure do |c|
11
- c.nick = "HTMLBot"
12
- c.server = "irc.freenode.org"
13
- c.channels = ["#cinchbots"]
14
- c.plugins.plugins = [Cinch::Plugins::Netfeed::HTMLTitle]
15
- end
16
- end
17
-
18
- bot.start
data/cinch-title.gemspec DELETED
@@ -1,56 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{cinch-title}
8
- s.version = "0.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Victor Bergöö"]
12
- s.date = %q{2010-12-05}
13
- s.default_executable = %q{cinch-title}
14
- s.description = %q{Plugin for the irc-framework Cinch to output HTML-titles}
15
- s.email = %q{victor.bergoo@gmail.com}
16
- s.executables = ["cinch-title"]
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.rdoc"
20
- ]
21
- s.files = [
22
- ".gitignore",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "bin/cinch-title",
28
- "cinch-title.gemspec",
29
- "lib/cinch-title.rb"
30
- ]
31
- s.homepage = %q{http://github.com/netfeed/cinch-title}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
35
- s.summary = %q{Plugin for Cinch to output HTML-titles}
36
-
37
- if s.respond_to? :specification_version then
38
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
- s.specification_version = 3
40
-
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<cinch>, [">= 0"])
43
- s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
44
- s.add_runtime_dependency(%q<curb>, [">= 0"])
45
- else
46
- s.add_dependency(%q<cinch>, [">= 0"])
47
- s.add_dependency(%q<nokogiri>, [">= 0"])
48
- s.add_dependency(%q<curb>, [">= 0"])
49
- end
50
- else
51
- s.add_dependency(%q<cinch>, [">= 0"])
52
- s.add_dependency(%q<nokogiri>, [">= 0"])
53
- s.add_dependency(%q<curb>, [">= 0"])
54
- end
55
- end
56
-
data/lib/cinch-title.rb DELETED
@@ -1,52 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- # Copyright (c) 2010 Victor Bergöö
4
- # This program is made available under the terms of the MIT License.
5
-
6
- require 'cinch'
7
- require 'nokogiri'
8
- require 'curb'
9
- require 'uri'
10
- require 'cgi'
11
-
12
- module Cinch
13
- module Plugins
14
- module Netfeed
15
- class HTMLTitle
16
- include Cinch::Plugin
17
-
18
- match /(.*http.*)/, :use_prefix => false
19
-
20
- def execute m, message
21
- suffix = m.user.nick[-1] == 's' ? "'" : "'s"
22
-
23
- ignore = ["jpg$", "jpeg$", "gif$", "png$", "bmp$"]
24
- ignore += config["ignore"] if config.key? "ignore"
25
-
26
- URI.extract(message, ["http", "https"]) do |uri|
27
- begin
28
- ignore.each do |re|
29
- raise ArgumentError.new "dang it" if uri =~ /#{re}/
30
- end
31
-
32
- m.reply "#{m.user.nick}#{suffix} URL: #{parse(uri)}"
33
- rescue ArgumentError => e
34
- next
35
- rescue URI::InvalidURIError => e
36
- m.reply "invalid url: #{uri}"
37
- end
38
- end
39
- end
40
-
41
- def parse uri
42
- content = Curl::Easy.perform(uri).body_str
43
- html = Nokogiri::HTML(content)
44
- title = html.at("title")
45
-
46
- return "No title" if title.nil?
47
- CGI.unescape_html title.text.gsub(/\s+/, ' ')
48
- end
49
- end
50
- end
51
- end
52
- end