mitten 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,96 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ class ScreenTimeSearch < Mitten::Plugin
5
+ def initialize(*args)
6
+ super
7
+
8
+ @theaters_uri = [
9
+ 'http://www.startheaters.jp/schedule',
10
+ 'http://www.google.co.jp/movies?tid=3d1a4be489681836'
11
+ ]
12
+ @movies_uri = 'http://www.startheaters.jp/movie'
13
+ @pickup_uri = 'http://www.startheaters.jp/'
14
+
15
+ @all = @config['all'] || '映画見たい'
16
+ @suffix = @config['suffix'] || 'の上映時間教えて'
17
+ @pickup = @config['pickup'] || 'おすすめ映画'
18
+ end
19
+
20
+ def on_privmsg(prefix, channel, message)
21
+ @results = []
22
+
23
+ case message
24
+ when /^#{@all}(.+|)$/
25
+ @results << '今やってる映画だよ♪'
26
+ get_movies_list @movies_uri
27
+ when /^#{@pickup}(.+|)$/
28
+ @results << 'おすすめ映画ピックアップしてみたよ♪'
29
+ get_movies_list @pickup_uri
30
+ when /^(.+)#{@suffix}$/
31
+ get_screen_time($1)
32
+ @results << 'そんな映画はにゃいっ/(^o^)\' if @results.empty?
33
+ end
34
+
35
+ @results.each { |message| notice(channel, message) }
36
+ end
37
+
38
+ private
39
+
40
+ def get_movies_list(uri)
41
+ begin
42
+ doc = Nokogiri::HTML(open(uri).read)
43
+
44
+ movies = []
45
+ (doc/'h3/a').each do |movie|
46
+ movies << movie.text.gsub(/ +/, ' ')
47
+ end
48
+
49
+ @results << movies.join(' / ')
50
+ rescue
51
+ '/(^o^)\ こわれたっ'
52
+ end
53
+ end
54
+
55
+ def get_screen_time(search_title)
56
+ begin
57
+ expression = Regexp.new(Regexp.quote(search_title))
58
+
59
+ @theaters_uri.each do |theater|
60
+ html = Nokogiri::HTML(open(theater).read)
61
+
62
+ if theater.include? 'startheaters'
63
+ (html/'div.unit_block').each do |movie_info|
64
+ title = movie_info.at('h3/a').text
65
+
66
+ if title =~ expression
67
+ site = movie_info.at('div.pic_block/a[@target="_blank"]').attributes['href']
68
+ @results << "#{title.gsub(' ', '')} #{site}"
69
+
70
+ (movie_info/'table.set_d').each do |screen|
71
+ movie = [" - [#{screen.at('th.cinema/img').attributes['alt']}]"]
72
+ (screen/'td').each do |time|
73
+ movie << time.text unless time.text.to_i == 0
74
+ end
75
+ @results << movie.join(' ')
76
+ end
77
+ end
78
+ end
79
+ else
80
+ theater_name = '[桜坂劇場]'
81
+
82
+ (html/'div.movie').each do |info|
83
+ movie_title = (info/'div.name/a/span[@dir="ltr"]').text
84
+
85
+ if movie_title =~ expression
86
+ time = info.inner_html.scan(/(..:..+?)</).last
87
+ @results << "#{theater_name} #{movie_title} #{time} (http://www.sakura-zaka.com/)"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ rescue
93
+ '/(^o^)\ こわれたっ'
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,63 @@
1
+ require 'nkf'
2
+
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ class SunSignAstrology < Mitten::Plugin
7
+ def initialize(*args)
8
+ super
9
+ @suffix = @config['suffix'] || 'の運勢教えて'
10
+ end
11
+
12
+ def on_privmsg(prefix, channel, message)
13
+ case message
14
+ when /^(.+)#{@suffix}$/
15
+ result = search_sign($1)
16
+
17
+ if result == nil
18
+ notice(channel, '/(^o^)\ わかにゃいっ')
19
+ else
20
+ notice(channel, result)
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def search_sign(sign)
28
+ ranking = get_ranking 'http://fortune.yahoo.co.jp/12astro/ranking.html'
29
+ result = ''
30
+
31
+ ranking.each do |rank|
32
+ if rank[:name].to_s == sign
33
+ result = "#{rank[:name]} #{rank[:rank]} #{rank[:desc]}!だよ♪ (#{rank[:link]})"
34
+ end
35
+ end
36
+ result
37
+ end
38
+
39
+ def get_ranking(uri)
40
+ begin
41
+ doc = Nokogiri::HTML(open(uri).read)
42
+
43
+ names = doc/'td/p/img'
44
+ ranks = doc/'td/img'
45
+ descs = doc/'p.ft01/a'
46
+
47
+ ranking = []
48
+ names.each_with_index do |name, desc_counter|
49
+ rank_counter = desc_counter + 1
50
+ ranking << {
51
+ :name => name.attributes['alt'],
52
+ :rank => ranks[rank_counter].attributes['alt'],
53
+ :desc => descs[desc_counter].text,
54
+ :link => descs[desc_counter].attributes['href']
55
+ }
56
+ end
57
+
58
+ ranking
59
+ rescue
60
+ '/(^o^)\ こわれたっ'
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,25 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+
4
+ class TimeCall < Mitten::Plugin
5
+ def initialize(*args)
6
+ super
7
+
8
+ @config_file = @config['config']
9
+ end
10
+
11
+ def before_hook
12
+ @call_list = load_config
13
+ end
14
+
15
+ def load_config
16
+ OpenStruct.new(File.open(@config_file) { |f| YAML.load(f) }).time
17
+ end
18
+
19
+ def main
20
+ now = Time.now.strftime('%H%M').to_i
21
+ @channels.each do |channel|
22
+ notice(channel, @call_list[now]) if @call_list[now]
23
+ end
24
+ end
25
+ end
data/plugins/tweet.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ class Tweet < Mitten::Plugin
5
+ def initialize(*args)
6
+ super
7
+
8
+ @prefix = @config['prefix']
9
+ end
10
+
11
+ def on_privmsg(prefix, channel, message)
12
+ if /#{@config['prefix']}/ =~ message
13
+ user = $1
14
+ html = Nokogiri::HTML(open("http://twitter.com/#{user}").read)
15
+
16
+ tweet = (html/'.entry-content').first
17
+ if !tweet.nil?
18
+ tweet = "@#{user}: #{tweet.text}"
19
+ else
20
+ tweet = (html/'h1.logged-out').first
21
+ if tweet.nil?
22
+ tweet = 'いにゃい/(^o^)\'
23
+ else
24
+ tweet = tweet.text
25
+ end
26
+ end
27
+ notice(channel, tweet)
28
+ end
29
+ rescue
30
+ notice(channel, 'こわれたっ/(^o^)\')
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require "open-uri"
2
+ require 'nokogiri'
3
+
4
+ class Typhoon < Mitten::Plugin
5
+ def initialize(*args)
6
+ super
7
+
8
+ @uri = 'http://typhoon.yahoo.co.jp/weather/jp/typhoon/typha.html'
9
+ @prefix = @config['prefix'] || '台風どうなった'
10
+ end
11
+
12
+ def on_privmsg(prefix, channel, message)
13
+ case message
14
+ when /^#{@prefix}(.+|)/
15
+ get_typhoon_info.each { |message| notice(channel, message) }
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def get_typhoon_info
22
+ begin
23
+ typhoon_info = []
24
+ doc = Nokogiri::HTML(open(@uri).read, nil, 'EUC-JP')/'tr[@valign="top"]'
25
+
26
+ (doc/'td[@widh="60%"]').each do |typhoon|
27
+ typhoon_name = typhoon.inner_html.scan(/<b>(.+)<\/b>/)
28
+ description = typhoon.inner_text.scan(/ (.+?)。/)
29
+
30
+ typhoon_info << "#{typhoon_name} #{description}".toutf8
31
+ end
32
+ typhoon_info << @uri
33
+ rescue
34
+ '/(^o^)\ こわれたっ'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ require 'nokogiri'
2
+
3
+ class URIShorten < Mitten::Plugin
4
+ def initialize(*args)
5
+ super
6
+
7
+ @prefix = @config['prefix'] || 's'
8
+ end
9
+
10
+ def on_privmsg(prefix, channel, message)
11
+ case message
12
+ when /^#{@prefix} (http:\/\/.+?)$/
13
+ notice(channel, shorten($1))
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def shorten(target)
20
+ uri = URI.escape("http://j.mp/?s=&keyword=&url=#{target}")
21
+ Nokogiri::HTML(open(uri).read).at('#shortened-url')['value']
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Mitten" do
4
+ before(:all) do
5
+ @mitten = Mitten::Core.new
6
+ end
7
+
8
+ it 'Mitten::Core Instantiation' do
9
+ @mitten.class.should == Mitten::Core
10
+ end
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mitten'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mitten
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomohiro, TAIRA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-21 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: Mitten is A Ruby IRC Bot Pluggable Framework
26
+ email: tomohiro.t@gmail.com
27
+ executables:
28
+ - daemon
29
+ - server
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README.rdoc
35
+ files:
36
+ - .document
37
+ - .gitignore
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - bin/daemon
43
+ - bin/server
44
+ - configs/example_environment.yaml
45
+ - configs/time_call.yaml
46
+ - example/sample.rb
47
+ - lib/mitten.rb
48
+ - lib/plugin.rb
49
+ - lib/utils.rb
50
+ - mitten.gemspec
51
+ - plugins/amazon_search.rb
52
+ - plugins/bmi.rb
53
+ - plugins/codepad.rb
54
+ - plugins/fortune.rb
55
+ - plugins/gasoline.rb
56
+ - plugins/gmail.rb
57
+ - plugins/google_profile.rb
58
+ - plugins/google_transit.rb
59
+ - plugins/google_weather.rb
60
+ - plugins/mixi_voice.rb
61
+ - plugins/nanapi.rb
62
+ - plugins/newspaper_headlines.rb
63
+ - plugins/openpne_new_diary_check.rb
64
+ - plugins/ramen.rb
65
+ - plugins/rate.rb
66
+ - plugins/screen_time_search.rb
67
+ - plugins/sun_sign_astrology.rb
68
+ - plugins/time_call.rb
69
+ - plugins/tweet.rb
70
+ - plugins/typhoon.rb
71
+ - plugins/uri_shorten.rb
72
+ - spec/mitten_spec.rb
73
+ - spec/spec.opts
74
+ - spec/spec_helper.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/Tomohiro/mitten
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: IRC Bot Framework
103
+ test_files:
104
+ - spec/mitten_spec.rb
105
+ - spec/spec_helper.rb