mitten 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -24
- data/Gemfile +4 -0
- data/LICENSE +5 -4
- data/README.markdown +53 -0
- data/Rakefile +19 -45
- data/VERSION +1 -1
- data/bin/mitten +7 -0
- data/configs/example_environment.yaml +6 -5
- data/example/{sample.rb → echo.rb} +8 -2
- data/lib/mitten.rb +7 -9
- data/lib/{plugin.rb → mitten/plugin.rb} +9 -4
- data/lib/{utils.rb → mitten/utils.rb} +3 -2
- data/lib/mitten/version.rb +3 -0
- data/mitten.gemspec +16 -92
- metadata +58 -151
- data/.document +0 -5
- data/README.rdoc +0 -81
- data/bin/client +0 -10
- data/bin/daemon +0 -8
- data/configs/time_call.yaml +0 -13
- data/configs/twitter_bot.yaml +0 -3
- data/plugins/amazon_search.rb +0 -62
- data/plugins/bmi.rb +0 -48
- data/plugins/codepad.rb +0 -63
- data/plugins/fortune.rb +0 -40
- data/plugins/gasoline.rb +0 -46
- data/plugins/gmail.rb +0 -64
- data/plugins/google_profile.rb +0 -37
- data/plugins/google_transit.rb +0 -56
- data/plugins/google_weather.rb +0 -34
- data/plugins/holoscope.rb +0 -63
- data/plugins/loo_holoscope.rb +0 -51
- data/plugins/mixi_voice.rb +0 -139
- data/plugins/nanapi.rb +0 -31
- data/plugins/newspaper_headlines.rb +0 -48
- data/plugins/openpne_new_diary_check.rb +0 -66
- data/plugins/ramen.rb +0 -33
- data/plugins/rate.rb +0 -31
- data/plugins/screen_time_search.rb +0 -96
- data/plugins/time_call.rb +0 -25
- data/plugins/tweet.rb +0 -32
- data/plugins/twitter_bot.rb +0 -32
- data/plugins/typhoon.rb +0 -37
- data/plugins/uri_shorten.rb +0 -23
- data/spec/mitten_spec.rb +0 -11
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -9
data/plugins/codepad.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'mechanize'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class CodePad < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
|
8
|
-
@agent = Mechanize.new
|
9
|
-
proxy = ENV['https_proxy'] || ENV['http_proxy']
|
10
|
-
if proxy
|
11
|
-
proxy = URI.parse(proxy)
|
12
|
-
@agent.set_proxy(proxy.host, proxy.port)
|
13
|
-
end
|
14
|
-
@prefixes = ['C', 'Haskell', 'Lua', 'OCaml', 'PHP', 'Perl', 'Python', 'Ruby', 'Scheme']
|
15
|
-
end
|
16
|
-
|
17
|
-
def on_privmsg(prefix, channel, message)
|
18
|
-
@language, @code = nil, nil
|
19
|
-
@prefixes.select do |item|
|
20
|
-
if message =~ Regexp.new("^#{item}:(.+)$")
|
21
|
-
@language = item
|
22
|
-
@code = $1.gsub('\\', '').strip
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
unless @language == nil
|
27
|
-
notice(channel, @language)
|
28
|
-
notice(channel, run_code)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def run_code
|
35
|
-
output = nil
|
36
|
-
|
37
|
-
begin
|
38
|
-
@agent.get('http://codepad.org/') do |run_page|
|
39
|
-
result = run_page.form_with(:action => '/') do |f|
|
40
|
-
f.radiobutton_with(:value => @language).check
|
41
|
-
f.code = code_prefix(@language) + @code
|
42
|
-
end.submit
|
43
|
-
doc = Nokogiri::HTML(result.body)
|
44
|
-
output = (doc/'pre').last.text
|
45
|
-
end
|
46
|
-
output
|
47
|
-
rescue Exception
|
48
|
-
'なんかだめー/(^o^)\'
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def code_prefix(language)
|
53
|
-
prefix = ''
|
54
|
-
case language
|
55
|
-
when 'C'
|
56
|
-
prefix = "#include <stdio.h>\n"
|
57
|
-
when 'PHP'
|
58
|
-
prefix = "<?php \n"
|
59
|
-
else
|
60
|
-
prefix
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/plugins/fortune.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class Fortune < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
|
8
|
-
@sex = {
|
9
|
-
:male => 'http://legacy.fortune.yahoo.co.jp/fortune/bin/omikuji?sex=m',
|
10
|
-
:female => 'http://legacy.fortune.yahoo.co.jp/fortune/bin/omikuji?sex=f'
|
11
|
-
}
|
12
|
-
@prefix = @config['prefix'] || 'おみくじ'
|
13
|
-
end
|
14
|
-
|
15
|
-
def on_privmsg(prefix, channel, message)
|
16
|
-
case message
|
17
|
-
when /^#{@prefix}/
|
18
|
-
notice(channel, read_fortune)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def read_fortune
|
25
|
-
html = Nokogiri::HTML(open(@sex.values.choice).read)
|
26
|
-
fortunes = {}
|
27
|
-
message = ''
|
28
|
-
|
29
|
-
(html/'table/tr/td').each do |content|
|
30
|
-
if content.inner_text =~ /^今日のあなたの(.+?)は(.+?)。/
|
31
|
-
fortunes[$1] = $2
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
fortunes.reverse_each do |genre, fortune|
|
36
|
-
message << "#{genre}:#{fortune} "
|
37
|
-
end
|
38
|
-
"今日のあなたは #{message}こんな感じだよ♪"
|
39
|
-
end
|
40
|
-
end
|
data/plugins/gasoline.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class Gasoline < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
|
8
|
-
@suffix = @config['suffix'] || 'ガソリンいくら'
|
9
|
-
@base_uri = 'http://gogo.gs'
|
10
|
-
@rank_uri = @base_uri + '/rank/result/?pref=47&ws=&p_mode=0&mm=0&service%5B3%5D=3&desd=0&x=24&y=17'
|
11
|
-
end
|
12
|
-
|
13
|
-
def on_privmsg(prefix, channel, message)
|
14
|
-
case message
|
15
|
-
when /^#{@suffix}$/
|
16
|
-
gasoline_ranking.each do |gs|
|
17
|
-
notice(channel, gs)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def gasoline_ranking
|
25
|
-
ranking = []
|
26
|
-
|
27
|
-
begin
|
28
|
-
lists = Nokogiri::HTML(open(@rank_uri).read, nil, 'EUC-JP')/'.tableType02'/'tr'
|
29
|
-
lists[2..6].each do |line|
|
30
|
-
next unless line.at('td[@colspan="5"]').nil?
|
31
|
-
|
32
|
-
rank = line.at('.crownBig001').text
|
33
|
-
price = line.at('.priceLevelBig5').text
|
34
|
-
station = line.at('strong').text
|
35
|
-
address = line.at('small').text
|
36
|
-
detail = URI.short(@base_uri + line.at('strong/a').attributes['href'])
|
37
|
-
|
38
|
-
ranking << "#{rank}位 #{price}円 #{station} #{address} (#{detail})"
|
39
|
-
end
|
40
|
-
rescue Exception => e
|
41
|
-
ranking << 'こわれたっ/(^o^)\'
|
42
|
-
end
|
43
|
-
|
44
|
-
ranking
|
45
|
-
end
|
46
|
-
end
|
data/plugins/gmail.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'sdbm'
|
3
|
-
require 'nokogiri'
|
4
|
-
|
5
|
-
=begin
|
6
|
-
|
7
|
-
ex. environment.yaml
|
8
|
-
|
9
|
-
Gmail:
|
10
|
-
sleep: 60
|
11
|
-
channel: '#Mitten@freenode'
|
12
|
-
account: 'account'
|
13
|
-
password: 'password'
|
14
|
-
|
15
|
-
=end
|
16
|
-
class Gmail < Mitten::Plugin
|
17
|
-
def initialize(*args)
|
18
|
-
super
|
19
|
-
|
20
|
-
@account = @config['account']
|
21
|
-
@password = @config['password']
|
22
|
-
|
23
|
-
proxy = ENV['https_proxy'] || ENV['http_proxy']
|
24
|
-
if proxy
|
25
|
-
@https = Net::HTTP::Proxy(URI.parse(proxy).host, URI.parse(proxy).port).new('mail.google.com', 443)
|
26
|
-
else
|
27
|
-
@https = Net::HTTP.new('mail.google.com', 443)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def before_hook
|
32
|
-
login
|
33
|
-
end
|
34
|
-
|
35
|
-
def login
|
36
|
-
@https.use_ssl = true
|
37
|
-
@https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
38
|
-
@request = Net::HTTP::Get.new('/mail/feed/atom')
|
39
|
-
@request.basic_auth(@account, @password)
|
40
|
-
end
|
41
|
-
|
42
|
-
def main
|
43
|
-
begin
|
44
|
-
db = SDBM.open("/tmp/gmail_#{@account}.db")
|
45
|
-
mail_list = Nokogiri::XML(@https.request(@request).body)
|
46
|
-
(mail_list/'entry').each do |entry|
|
47
|
-
id = entry.at('id').content
|
48
|
-
unless db.include? id
|
49
|
-
db[id] = '1'
|
50
|
-
title = entry.at('title').text
|
51
|
-
name = entry.at('name').text
|
52
|
-
link = entry.at('link')['href']
|
53
|
-
|
54
|
-
@channels.each do |channel|
|
55
|
-
notice(channel, "Gmail: (#{name}) #{title} #{URI.short(link)}")
|
56
|
-
sleep 5
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
ensure
|
61
|
-
db.close
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/plugins/google_profile.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
|
-
class GoogleProfile < Mitten::Plugin
|
4
|
-
def initialize(*args)
|
5
|
-
super
|
6
|
-
|
7
|
-
@suffix = @config['suffix'] || 'のプロフィールが知りたい'
|
8
|
-
@limit = @config['limit'] || 3
|
9
|
-
end
|
10
|
-
|
11
|
-
def on_privmsg(prefix, channel, message)
|
12
|
-
case message
|
13
|
-
when /^(.+?)#{@suffix}/
|
14
|
-
get_profile($1).each { |profile| notice(channel, profile) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def get_profile(target)
|
21
|
-
profiles = []
|
22
|
-
uri = URI.escape("http://www.google.com/profiles?q=#{target}")
|
23
|
-
result = Nokogiri::HTML(Kconv.toutf8(open(uri).read))/'div.profile-result'
|
24
|
-
|
25
|
-
unless result.count == 0
|
26
|
-
result[0...@limit].each do |profile|
|
27
|
-
detail = profile.at('div.profile-result-text-block').text
|
28
|
-
uri = URI.short("http://www.google.com#{profile.at('a')['href']}")
|
29
|
-
|
30
|
-
profiles << "#{detail} (#{uri})"
|
31
|
-
end
|
32
|
-
else
|
33
|
-
profiles << 'そんな人いにゃい o(>_<)o'
|
34
|
-
end
|
35
|
-
profiles
|
36
|
-
end
|
37
|
-
end
|
data/plugins/google_transit.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class GoogleTransit < Mitten::Plugin
|
5
|
-
def on_privmsg(prefix, channel, message)
|
6
|
-
case message
|
7
|
-
when /^(.+)から(.+)(へ|まで|に)行.+/
|
8
|
-
search_route($1, $2).each { |route| notice(channel, route) }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def search_route(search_from, search_to)
|
15
|
-
from = URI.escape(search_from.toutf8)
|
16
|
-
to = URI.escape(search_to.toutf8)
|
17
|
-
query = "http://maps.google.co.jp/maps?f=q&source=s_q&hl=ja&geocode=&q=from%3A+#{from}+to%3A+#{to}"
|
18
|
-
|
19
|
-
begin
|
20
|
-
html = Nokogiri::HTML(open(query).read)
|
21
|
-
route = html/'#transit_route_0'
|
22
|
-
|
23
|
-
unless route.empty?
|
24
|
-
start_place = (html/'#ddw_addr_area_0/#sxaddr/div.sa').text.toutf8
|
25
|
-
end_place = (html/'#ddw_addr_area_1/#sxaddr/div.sa').text.toutf8
|
26
|
-
time = (html/'#transit_route_0').search('span.ts_jtime').text.toutf8
|
27
|
-
cost = (html/'#transit_route_0').search('span.ts_routecost').text.toutf8
|
28
|
-
|
29
|
-
messages = ["#{start_place} から #{end_place} へ行くにはね,"]
|
30
|
-
messages << "だいたい #{time} で #{cost} ぐらいかかるみたい!"
|
31
|
-
|
32
|
-
(route/'table.ts_step').each_with_index do |step, counter|
|
33
|
-
counter += 1
|
34
|
-
longline = (step/'span.longline').text.toutf8
|
35
|
-
action = (step/'span.action').text.toutf8
|
36
|
-
|
37
|
-
unless longline.empty?
|
38
|
-
locations = step/'span.location'
|
39
|
-
|
40
|
-
messages << "#{counter} : #{action} で「#{longline}」に乗る"
|
41
|
-
messages << " [発] #{locations[0].text.toutf8}"
|
42
|
-
messages << " [着] #{locations[1].text.toutf8}"
|
43
|
-
else
|
44
|
-
location = (step/'span.location').text.toutf8
|
45
|
-
messages << "#{counter} : #{location} #{action}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
messages << "詳しくはここ見てね♪ (#{URI.short(query)})"
|
49
|
-
else
|
50
|
-
'/(^o^)\ 迷子!'
|
51
|
-
end
|
52
|
-
rescue Exception
|
53
|
-
'/(^o^)\ 迷子!'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/plugins/google_weather.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
|
-
class GoogleWeather < Mitten::Plugin
|
4
|
-
def initialize(*args)
|
5
|
-
super
|
6
|
-
|
7
|
-
@suffix = @config['suffix'] || 'の天気教えて'
|
8
|
-
@indexes = {'今日の' => 0, '明日の' => 1, '明後日の' => 2, '明々後日の' => 3}
|
9
|
-
end
|
10
|
-
|
11
|
-
def on_privmsg(prefix, channel, message)
|
12
|
-
case message
|
13
|
-
when /^(.+?の|)(.+?)#{@suffix}/
|
14
|
-
option = '今日の'
|
15
|
-
option = $1 unless $1 == ''
|
16
|
-
keyword = $2
|
17
|
-
|
18
|
-
notice(channel, get_weather(keyword, option))
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def get_weather(keyword, option)
|
25
|
-
uri = URI.escape("http://www.google.co.jp/search?q=#{keyword}+週間天気")
|
26
|
-
html = Nokogiri::HTML(Kconv.toutf8(open(uri).read))
|
27
|
-
|
28
|
-
city = (html/'h3.r/b').first.text
|
29
|
-
weather = ((html/'div[@align="center"]')/'img')[@indexes[option]]['title']
|
30
|
-
temperature = ((html/'div[@align="center"]')/'nobr')[@indexes[option]].text
|
31
|
-
|
32
|
-
"#{option}#{city}の天気は #{weather} だよっ [#{temperature}] (#{URI.short(uri)})"
|
33
|
-
end
|
34
|
-
end
|
data/plugins/holoscope.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'nkf'
|
2
|
-
|
3
|
-
require 'open-uri'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
class Holoscope < 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
|
data/plugins/loo_holoscope.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'nkf'
|
2
|
-
|
3
|
-
require 'open-uri'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
class LooHoloscope < Mitten::Plugin
|
7
|
-
def initialize(*args)
|
8
|
-
super
|
9
|
-
|
10
|
-
@suffix = @config['suffix'] || 'の運勢教えて'
|
11
|
-
@signs = {
|
12
|
-
'おひつじ座' => 'http://lou5.jp/uranai/aries/',
|
13
|
-
'おうし座' => 'http://lou5.jp/uranai/taurus/',
|
14
|
-
'ふたご座' => 'http://lou5.jp/uranai/gemini/',
|
15
|
-
'かに座' => 'http://lou5.jp/uranai/cancer/',
|
16
|
-
'しし座' => 'http://lou5.jp/uranai/leo/',
|
17
|
-
'おとめ座' => 'http://lou5.jp/uranai/virgo/',
|
18
|
-
'てんびん座' => 'http://lou5.jp/uranai/libra/',
|
19
|
-
'さそり座' => 'http://lou5.jp/uranai/scorpio/',
|
20
|
-
'いて座' => 'http://lou5.jp/uranai/sagittarius/',
|
21
|
-
'やぎ座' => 'http://lou5.jp/uranai/capricorn/',
|
22
|
-
'みずがめ座' => 'http://lou5.jp/uranai/aquarius/',
|
23
|
-
'うお座' => 'http://lou5.jp/uranai/pisces/',
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
def on_privmsg(prefix, channel, message)
|
28
|
-
case message
|
29
|
-
when /^(.+)#{@suffix}$/
|
30
|
-
result = get_result(@signs[$1])
|
31
|
-
|
32
|
-
if result == nil
|
33
|
-
notice(channel, '/(^o^)\ わかにゃいっ')
|
34
|
-
else
|
35
|
-
notice(channel, result)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def get_result(uri)
|
43
|
-
begin
|
44
|
-
doc = Nokogiri::HTML(open(uri).read)
|
45
|
-
|
46
|
-
loo = (doc/'div.box-inner/p').first.text.gsub("\n", '') + ' ってルーさんが言ってたよ♪'
|
47
|
-
rescue Exception => e
|
48
|
-
e.to_s
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|