mitten 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,38 +5,13 @@
5
5
  Mitten is A Ruby IRC Bot Pluggable Framework.
6
6
 
7
7
 
8
- == Require
9
-
10
- === RubyGems
11
-
12
- 1. gemcutter
13
-
14
- $ sudo gem install gemcutter
15
-
16
- 2. rake
17
-
18
- $ sudo gem install rake
19
-
20
- 3. rspec
21
-
22
- $ sudo gem install rspec
23
-
24
- 4. net-irc
25
-
26
- $ sudo gem install net-irc
27
-
28
- 5. daemons
29
-
30
- $ sudo gem install daemons
31
-
32
-
33
8
  == Installation
34
9
 
35
- 1. RubyGems
10
+ - RubyGems
36
11
 
37
12
  $ sudo gem install mitten
38
13
 
39
- 2. GitHub
14
+ - GitHub
40
15
 
41
16
  $ git clone http://github.com/Tomohiro/mitten.git
42
17
 
@@ -103,6 +78,4 @@ Copyright (c) 2010 Tomohiro, TAIRA.
103
78
 
104
79
  == Licence
105
80
 
106
- The MIT License
107
-
108
- See LICENSE for details.
81
+ The MIT License. See LICENSE for details.
data/Rakefile CHANGED
@@ -10,7 +10,11 @@ begin
10
10
  gem.email = 'tomohiro.t@gmail.com'
11
11
  gem.homepage = 'http://github.com/Tomohiro/mitten'
12
12
  gem.authors = ['Tomohiro, TAIRA']
13
+ gem.add_dependency 'net-irc', '>= 0.0.9'
14
+ gem.add_dependency 'daemons', '>= 1.0.10'
15
+ gem.add_dependency 'json_pure', '>= 1.2.0'
13
16
  gem.add_development_dependency 'rspec', '>= 1.2.9'
17
+ gem.add_development_dependency 'rake', '>= 0.8.7'
14
18
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
19
  end
16
20
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,4 +1,3 @@
1
- ---
2
1
  time:
3
2
  0900: '9時をお知らせするよ♪'
4
3
  1000: '10時をお知らせするよ♪'
@@ -0,0 +1,3 @@
1
+ bot_list:
2
+ '今日は何の日': 'nannohi'
3
+ '貯水率教えて': 'i_am_dam'
data/lib/mitten.rb CHANGED
@@ -73,24 +73,24 @@ module Mitten
73
73
 
74
74
  def run_plugins
75
75
  threads = []
76
- @plugins = load_plugins(@server['plugin_dir'], @config.plugins)
76
+ load_plugins(@server['plugin_dir'], @config.plugins)
77
77
 
78
78
  threads.push(
79
79
  Thread.fork do
80
80
  while line = @socket.gets
81
81
  message = Message.parse(line)
82
82
  if message.command.upcase == 'PRIVMSG'
83
- @plugins.each do |plugin|
84
- plugin.on_privmsg(message.prefix, message[0], message[1])
83
+ @response_plugins.each do |plugin|
84
+ plugin.response(message.prefix, message[0], message[1])
85
85
  end
86
86
  end
87
87
  end
88
88
  end
89
89
  )
90
90
 
91
- @plugins.each do |plugin|
91
+ @notify_plugins.each do |plugin|
92
92
  plugin.before_hook
93
- threads.push(Thread.fork(plugin) { |p| p.notify })
93
+ threads.push(Thread.fork { plugin.notify })
94
94
  end
95
95
 
96
96
  threads.each { |t| t.join }
@@ -118,16 +118,27 @@ module Mitten
118
118
  end
119
119
 
120
120
  plugins = instantiation(class_tables)
121
+ instance_categorize(plugins)
121
122
  end
122
123
 
123
124
  def instantiation(class_tables)
124
125
  plugins = []
125
126
  class_tables.each do |name, plugin|
126
- plugins << plugin[:class].new(plugin[:configs], @socket)
127
+ plugins << plugin[:class].new(plugin[:configs], @opts, @socket)
127
128
  puts "Plugin: #{name} is loaded"
128
129
  end
129
130
 
130
131
  plugins
131
132
  end
133
+
134
+ def instance_categorize(plugins)
135
+ @response_plugins = []
136
+ @notify_plugins = []
137
+
138
+ plugins.each do |plugin|
139
+ @response_plugins << plugin if plugin.respond_to? 'on_privmsg'
140
+ @notify_plugins << plugin if plugin.respond_to? 'main'
141
+ end
142
+ end
132
143
  end
133
144
  end
data/lib/plugin.rb CHANGED
@@ -4,33 +4,46 @@ require 'net/irc'
4
4
  module Mitten
5
5
  DEFAULT_SLEEP = 360
6
6
 
7
- class Plugin < Net::IRC::Client
8
- def initialize(config, socket)
7
+ class Plugin
8
+ include Net::IRC
9
+ include Constants
10
+
11
+ def initialize(config, server, socket)
9
12
  @config = config || {}
13
+ @server = server
10
14
  @socket = socket
11
- @channels = @config['channels'] || @config['channel']
15
+ @channels = @config['channels'] || @config['channel'] || @server.channel
12
16
  @sleep = @config['sleep'] || DEFAULT_SLEEP
13
17
  end
14
18
 
15
- def post(command, *params)
16
- @socket << Message.new(nil, command, params.map { |s| s.gsub(/\r|\n/, " ") })
19
+ def post(command, *args)
20
+ @socket << Message.new(nil, command, args.map { |s| s.gsub(/\r|\n/, " ") })
17
21
  end
18
22
 
19
- def notice(*params)
20
- post(NOTICE, *params)
23
+ def notice(*args)
24
+ post(NOTICE, *args)
21
25
  end
22
26
 
23
- def message(*params)
24
- post(PRIVMSG, *params)
27
+ def message(*args)
28
+ post(PRIVMSG, *args)
25
29
  end
26
30
 
27
- def on_privmsg(prefix, channel, message)
31
+ def response(*args)
32
+ begin
33
+ on_privmsg(*args)
34
+ rescue Exception => e
35
+ post(NOTICE, @server.channel, "#{e.class} #{e.to_s}") if @server.channel
36
+ end
28
37
  end
29
38
 
30
39
  def notify
31
- loop do
32
- main
33
- sleep @sleep
40
+ begin
41
+ loop do
42
+ main
43
+ sleep @sleep
44
+ end
45
+ rescue Exception => e
46
+ post(NOTICE, @server.channel, "#{e.class} #{e.to_s}") if @server.channel
34
47
  end
35
48
  end
36
49
  end
data/mitten.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mitten}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tomohiro, TAIRA"]
12
- s.date = %q{2010-02-21}
12
+ s.date = %q{2010-02-25}
13
13
  s.description = %q{Mitten is A Ruby IRC Bot Pluggable Framework}
14
14
  s.email = %q{tomohiro.t@gmail.com}
15
15
  s.executables = ["daemon", "server"]
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "bin/server",
29
29
  "configs/example_environment.yaml",
30
30
  "configs/time_call.yaml",
31
+ "configs/twitter_bot.yaml",
31
32
  "example/sample.rb",
32
33
  "lib/mitten.rb",
33
34
  "lib/plugin.rb",
@@ -42,6 +43,8 @@ Gem::Specification.new do |s|
42
43
  "plugins/google_profile.rb",
43
44
  "plugins/google_transit.rb",
44
45
  "plugins/google_weather.rb",
46
+ "plugins/holoscope.rb",
47
+ "plugins/loo_holoscope.rb",
45
48
  "plugins/mixi_voice.rb",
46
49
  "plugins/nanapi.rb",
47
50
  "plugins/newspaper_headlines.rb",
@@ -49,9 +52,9 @@ Gem::Specification.new do |s|
49
52
  "plugins/ramen.rb",
50
53
  "plugins/rate.rb",
51
54
  "plugins/screen_time_search.rb",
52
- "plugins/sun_sign_astrology.rb",
53
55
  "plugins/time_call.rb",
54
56
  "plugins/tweet.rb",
57
+ "plugins/twitter_bot.rb",
55
58
  "plugins/typhoon.rb",
56
59
  "plugins/uri_shorten.rb",
57
60
  "spec/mitten_spec.rb",
@@ -61,7 +64,7 @@ Gem::Specification.new do |s|
61
64
  s.homepage = %q{http://github.com/Tomohiro/mitten}
62
65
  s.rdoc_options = ["--charset=UTF-8"]
63
66
  s.require_paths = ["lib"]
64
- s.rubygems_version = %q{1.3.5}
67
+ s.rubygems_version = %q{1.3.6}
65
68
  s.summary = %q{IRC Bot Framework}
66
69
  s.test_files = [
67
70
  "spec/spec_helper.rb",
@@ -73,12 +76,24 @@ Gem::Specification.new do |s|
73
76
  s.specification_version = 3
74
77
 
75
78
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
79
+ s.add_runtime_dependency(%q<net-irc>, [">= 0.0.9"])
80
+ s.add_runtime_dependency(%q<daemons>, [">= 1.0.10"])
81
+ s.add_runtime_dependency(%q<json_pure>, [">= 1.2.0"])
76
82
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
83
+ s.add_development_dependency(%q<rake>, [">= 0.8.7"])
77
84
  else
85
+ s.add_dependency(%q<net-irc>, [">= 0.0.9"])
86
+ s.add_dependency(%q<daemons>, [">= 1.0.10"])
87
+ s.add_dependency(%q<json_pure>, [">= 1.2.0"])
78
88
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
89
+ s.add_dependency(%q<rake>, [">= 0.8.7"])
79
90
  end
80
91
  else
92
+ s.add_dependency(%q<net-irc>, [">= 0.0.9"])
93
+ s.add_dependency(%q<daemons>, [">= 1.0.10"])
94
+ s.add_dependency(%q<json_pure>, [">= 1.2.0"])
81
95
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
96
+ s.add_dependency(%q<rake>, [">= 0.8.7"])
82
97
  end
83
98
  end
84
99
 
@@ -3,7 +3,7 @@ require 'nkf'
3
3
  require 'open-uri'
4
4
  require 'nokogiri'
5
5
 
6
- class SunSignAstrology < Mitten::Plugin
6
+ class Holoscope < Mitten::Plugin
7
7
  def initialize(*args)
8
8
  super
9
9
  @suffix = @config['suffix'] || 'の運勢教えて'
@@ -0,0 +1,51 @@
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
@@ -0,0 +1,32 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ class TwitterBot < Mitten::Plugin
7
+ def initialize(*args)
8
+ super
9
+
10
+ @config_file = @config['config']
11
+ @bot_list = load_config
12
+ end
13
+
14
+ def load_config
15
+ OpenStruct.new(File.open(@config_file) { |f| YAML.load(f) }).bot_list
16
+ end
17
+
18
+ def on_privmsg(prefix, channel, message)
19
+ @bot_list.each_key do |key|
20
+ notice(channel, get_tweet(@bot_list[key])) if message =~ Regexp.new(/#{key}(|?|\?)/)
21
+ end
22
+ end
23
+
24
+ def get_tweet(bot)
25
+ html = Nokogiri::HTML(open("http://twitter.com/#{bot}").read)
26
+
27
+ tweet = (html/'.entry-content').first
28
+ if !tweet.nil?
29
+ tweet = tweet.text
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mitten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 4
9
+ version: 0.0.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Tomohiro, TAIRA
@@ -9,19 +14,79 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-21 00:00:00 +09:00
17
+ date: 2010-02-25 00:00:00 +09:00
13
18
  default_executable:
14
19
  dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: net-irc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 9
31
+ version: 0.0.9
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: daemons
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 10
45
+ version: 1.0.10
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: json_pure
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ - 0
59
+ version: 1.2.0
60
+ type: :runtime
61
+ version_requirements: *id003
15
62
  - !ruby/object:Gem::Dependency
16
63
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
20
66
  requirements:
21
67
  - - ">="
22
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ - 9
23
73
  version: 1.2.9
24
- version:
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: rake
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 8
86
+ - 7
87
+ version: 0.8.7
88
+ type: :development
89
+ version_requirements: *id005
25
90
  description: Mitten is A Ruby IRC Bot Pluggable Framework
26
91
  email: tomohiro.t@gmail.com
27
92
  executables:
@@ -43,6 +108,7 @@ files:
43
108
  - bin/server
44
109
  - configs/example_environment.yaml
45
110
  - configs/time_call.yaml
111
+ - configs/twitter_bot.yaml
46
112
  - example/sample.rb
47
113
  - lib/mitten.rb
48
114
  - lib/plugin.rb
@@ -57,6 +123,8 @@ files:
57
123
  - plugins/google_profile.rb
58
124
  - plugins/google_transit.rb
59
125
  - plugins/google_weather.rb
126
+ - plugins/holoscope.rb
127
+ - plugins/loo_holoscope.rb
60
128
  - plugins/mixi_voice.rb
61
129
  - plugins/nanapi.rb
62
130
  - plugins/newspaper_headlines.rb
@@ -64,9 +132,9 @@ files:
64
132
  - plugins/ramen.rb
65
133
  - plugins/rate.rb
66
134
  - plugins/screen_time_search.rb
67
- - plugins/sun_sign_astrology.rb
68
135
  - plugins/time_call.rb
69
136
  - plugins/tweet.rb
137
+ - plugins/twitter_bot.rb
70
138
  - plugins/typhoon.rb
71
139
  - plugins/uri_shorten.rb
72
140
  - spec/mitten_spec.rb
@@ -85,18 +153,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
153
  requirements:
86
154
  - - ">="
87
155
  - !ruby/object:Gem::Version
156
+ segments:
157
+ - 0
88
158
  version: "0"
89
- version:
90
159
  required_rubygems_version: !ruby/object:Gem::Requirement
91
160
  requirements:
92
161
  - - ">="
93
162
  - !ruby/object:Gem::Version
163
+ segments:
164
+ - 0
94
165
  version: "0"
95
- version:
96
166
  requirements: []
97
167
 
98
168
  rubyforge_project:
99
- rubygems_version: 1.3.5
169
+ rubygems_version: 1.3.6
100
170
  signing_key:
101
171
  specification_version: 3
102
172
  summary: IRC Bot Framework