mitten 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -20,7 +20,7 @@ Mitten is A Ruby IRC Bot Pluggable Framework.
20
20
 
21
21
  1. Usage
22
22
 
23
- $ ./bin/server -h
23
+ $ ./bin/client -h
24
24
  $ ./bin/daemon run -- -h
25
25
 
26
26
  2. Start
@@ -41,7 +41,7 @@ Mitten is A Ruby IRC Bot Pluggable Framework.
41
41
 
42
42
  6. Run on the top(not daemonize)
43
43
 
44
- $ ./bin/server
44
+ $ ./bin/client
45
45
  $ ./bin/daemon run
46
46
 
47
47
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  gem.summary = 'IRC Bot Framework'
9
9
  gem.description = 'Mitten is A Ruby IRC Bot Pluggable Framework'
10
10
  gem.email = 'tomohiro.t@gmail.com'
11
- gem.homepage = 'http://github.com/Tomohiro/mitten'
11
+ gem.homepage = 'http://rubygems.org/gems/mitten'
12
12
  gem.authors = ['Tomohiro, TAIRA']
13
13
  gem.add_dependency 'net-irc', '>= 0.0.9'
14
14
  gem.add_dependency 'daemons', '>= 1.0.10'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -6,5 +6,5 @@ $: << MITTEN_ROOT
6
6
 
7
7
  require 'lib/mitten.rb'
8
8
 
9
- puts 'Booting Mitten Server...'
10
- Mitten::Core.boot
9
+ puts 'Booting Mitten ...'
10
+ Mitten::Bot.boot
data/bin/daemon CHANGED
@@ -5,4 +5,4 @@ require 'daemons'
5
5
 
6
6
  root = File.expand_path(File.dirname(__FILE__))
7
7
 
8
- Daemons.run("#{root}/server", {:app_name => 'mittend'})
8
+ Daemons.run("#{root}/client", {:app_name => 'mittend'})
data/lib/mitten.rb CHANGED
@@ -16,7 +16,7 @@ require 'lib/plugin'
16
16
  module Mitten
17
17
  DEFAULT_CONFIG_FILE_PATH = 'configs/environment.yaml'
18
18
 
19
- class Core < Net::IRC::Client
19
+ class Bot < Net::IRC::Client
20
20
  def self.boot
21
21
  new.boot
22
22
  end
@@ -43,7 +43,7 @@ module Mitten
43
43
  o.parse!
44
44
  end
45
45
 
46
- @config = OpenStruct.new(File.open(config_file) { |f| YAML.load(f) })
46
+ @config = OpenStruct.new(YAML.load_file config_file)
47
47
  @server = @config.method(@mode).call
48
48
  end
49
49
 
data/mitten.gemspec CHANGED
@@ -5,14 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mitten}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
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-25}
12
+ s.date = %q{2010-03-16}
13
13
  s.description = %q{Mitten is A Ruby IRC Bot Pluggable Framework}
14
14
  s.email = %q{tomohiro.t@gmail.com}
15
- s.executables = ["daemon", "server"]
15
+ s.executables = ["daemon", "client"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
18
  "README.rdoc"
@@ -24,8 +24,8 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
+ "bin/client",
27
28
  "bin/daemon",
28
- "bin/server",
29
29
  "configs/example_environment.yaml",
30
30
  "configs/time_call.yaml",
31
31
  "configs/twitter_bot.yaml",
@@ -61,7 +61,7 @@ Gem::Specification.new do |s|
61
61
  "spec/spec.opts",
62
62
  "spec/spec_helper.rb"
63
63
  ]
64
- s.homepage = %q{http://github.com/Tomohiro/mitten}
64
+ s.homepage = %q{http://rubygems.org/gems/mitten}
65
65
  s.rdoc_options = ["--charset=UTF-8"]
66
66
  s.require_paths = ["lib"]
67
67
  s.rubygems_version = %q{1.3.6}
data/plugins/gmail.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'net/https'
2
+ require 'sdbm'
2
3
  require 'nokogiri'
3
4
 
4
5
  =begin
@@ -25,7 +26,6 @@ class Gmail < Mitten::Plugin
25
26
  else
26
27
  @https = Net::HTTP.new('mail.google.com', 443)
27
28
  end
28
- @mail_cache = {}
29
29
  end
30
30
 
31
31
  def before_hook
@@ -40,20 +40,25 @@ class Gmail < Mitten::Plugin
40
40
  end
41
41
 
42
42
  def main
43
- mail_list = Nokogiri::XML(@https.request(@request).body)
44
- (mail_list/'entry').each do |entry|
45
- id = entry.at('id').content
46
- unless @mail_cache.key? id
47
- @mail_cache[id] = true
48
- title = entry.at('title').text
49
- name = entry.at('name').text
50
- link = entry.at('link')['href']
51
-
52
- @channels.each do |channel|
53
- notice(channel, "Gmail: (#{name}) #{title} #{URI.short(link)}")
54
- sleep 5
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
55
58
  end
56
59
  end
60
+ ensure
61
+ db.close
57
62
  end
58
63
  end
59
64
  end
@@ -1,3 +1,4 @@
1
+ require 'sdbm'
1
2
  require 'mechanize'
2
3
  require 'nokogiri'
3
4
 
@@ -20,7 +21,6 @@ class OpenPNENewDiaryCheck < Mitten::Plugin
20
21
  @uri = @config['uri']
21
22
  @username = @config['username']
22
23
  @password = @config['password']
23
- @diaries = {}
24
24
  end
25
25
 
26
26
  def before_hook
@@ -38,23 +38,29 @@ class OpenPNENewDiaryCheck < Mitten::Plugin
38
38
  end
39
39
 
40
40
  def main
41
- diary_page = @agent.get "#{@uri}/?m=pc&a=page_h_diary_list_all"
42
- diaries = Nokogiri::HTML(diary_page.body)/'div.item'
41
+ begin
42
+ db = SDBM.open("/tmp/openpnenewdiarycheck_#{@username}.db")
43
+ diary_page = @agent.get "#{@uri}/?m=pc&a=page_h_diary_list_all"
44
+ diaries = Nokogiri::HTML(diary_page.body)/'div.item'
43
45
 
44
- diaries[1...diaries.size].each do |diary|
45
- uri = "#{@uri}/#{(diary/'td.photo/a').first.attributes['href']}"
46
- redo if uri == nil or uri == ''
46
+ diaries[1...diaries.size].each do |diary|
47
+ uri = "#{@uri}/#{(diary/'td.photo/a').first.attributes['href']}"
48
+ redo if uri == nil or uri == ''
47
49
 
48
- unless @diaries.has_key? uri
49
- @diaries[uri] = true
50
- nick = ((diary/'td').to_a)[1].text.gsub(/ \(.*\)$/, '')
51
- title = ((diary/'td').to_a)[2].text.gsub(/ \([0-9].?\)/, '')
52
- message = "#{nick}さんが「#{title}」を投稿しました! (#{uri})"
50
+ unless db.include? uri
51
+ db[uri] = '1'
52
+ nick = ((diary/'td').to_a)[1].text.gsub(/ \(.*\)$/, '')
53
+ title = ((diary/'td').to_a)[2].text.gsub(/ \([0-9].?\)/, '')
54
+ message = "#{nick}さんが「#{title}」を投稿しました! (#{uri})"
53
55
 
54
- @channels.each do |channel|
55
- notice(channel, message) if @diaries.size > 20
56
+ @channels.each do |channel|
57
+ notice(channel, message)
58
+ sleep 5
59
+ end
56
60
  end
57
61
  end
62
+ ensure
63
+ db.close
58
64
  end
59
65
  end
60
66
  end
data/spec/mitten_spec.rb CHANGED
@@ -2,10 +2,10 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Mitten" do
4
4
  before(:all) do
5
- @mitten = Mitten::Core.new
5
+ @mitten = Mitten::Bot.new
6
6
  end
7
7
 
8
- it 'Mitten::Core Instantiation' do
9
- @mitten.class.should == Mitten::Core
8
+ it 'Mitten::Bot Instantiation' do
9
+ @mitten.class.should == Mitten::Bot
10
10
  end
11
11
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tomohiro, TAIRA
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-25 00:00:00 +09:00
17
+ date: 2010-03-16 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -91,7 +91,7 @@ description: Mitten is A Ruby IRC Bot Pluggable Framework
91
91
  email: tomohiro.t@gmail.com
92
92
  executables:
93
93
  - daemon
94
- - server
94
+ - client
95
95
  extensions: []
96
96
 
97
97
  extra_rdoc_files:
@@ -104,8 +104,8 @@ files:
104
104
  - README.rdoc
105
105
  - Rakefile
106
106
  - VERSION
107
+ - bin/client
107
108
  - bin/daemon
108
- - bin/server
109
109
  - configs/example_environment.yaml
110
110
  - configs/time_call.yaml
111
111
  - configs/twitter_bot.yaml
@@ -141,7 +141,7 @@ files:
141
141
  - spec/spec.opts
142
142
  - spec/spec_helper.rb
143
143
  has_rdoc: true
144
- homepage: http://github.com/Tomohiro/mitten
144
+ homepage: http://rubygems.org/gems/mitten
145
145
  licenses: []
146
146
 
147
147
  post_install_message: