ircbot 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/README +43 -21
  2. data/Rakefile +9 -6
  3. data/bin/ircbot +3 -27
  4. data/lib/ircbot.rb +12 -15
  5. data/lib/ircbot/client.rb +32 -0
  6. data/lib/ircbot/client/commands.rb +34 -0
  7. data/lib/ircbot/client/config.rb +55 -0
  8. data/lib/ircbot/client/config/channels.rb +40 -0
  9. data/lib/ircbot/client/config/plugins.rb +16 -0
  10. data/lib/ircbot/client/encoding.rb +17 -0
  11. data/lib/ircbot/client/plugins.rb +64 -0
  12. data/lib/ircbot/core_ext/delegation.rb +135 -0
  13. data/lib/ircbot/core_ext/extending.rb +80 -0
  14. data/lib/ircbot/core_ext/message.rb +18 -0
  15. data/lib/ircbot/framework.rb +22 -40
  16. data/lib/ircbot/plugin.rb +63 -0
  17. data/lib/ircbot/plugins.rb +141 -0
  18. data/lib/ircbot/version.rb +4 -0
  19. data/plugins/echo.rb +14 -0
  20. data/plugins/irc.rb +19 -0
  21. data/plugins/plugins.rb +59 -0
  22. data/spec/config_spec.rb +83 -0
  23. data/spec/fixtures/sama-zu.yml +8 -0
  24. data/spec/framework_spec.rb +18 -0
  25. data/spec/its_helper.rb +15 -0
  26. data/spec/plugin_spec.rb +70 -0
  27. data/spec/plugins_spec.rb +30 -0
  28. data/spec/provide_helper.rb +36 -0
  29. data/spec/spec_helper.rb +16 -0
  30. metadata +40 -19
  31. data/lib/irc/agent.rb +0 -177
  32. data/lib/irc/client.rb +0 -476
  33. data/lib/irc/const.rb +0 -242
  34. data/lib/irc/irc.rb +0 -324
  35. data/lib/irc/localize.rb +0 -260
  36. data/lib/ircbot/agent_manager.rb +0 -89
  37. data/lib/ircbot/config_client.rb +0 -369
  38. data/lib/ircbot/core_ext/digest.rb +0 -14
  39. data/lib/ircbot/core_ext/irc.rb +0 -61
  40. data/lib/ircbot/core_ext/rand-polimorphism.rb +0 -23
  41. data/lib/ircbot/core_ext/writefile.rb +0 -45
  42. data/lib/ircbot/ordered_hash.rb +0 -91
  43. data/lib/ircbot/reply_client.rb +0 -328
@@ -0,0 +1,4 @@
1
+ module Ircbot
2
+ VERSION = '0.1.0' unless defined?(Ircbot::VERSION)
3
+ HOMEPAGE = "http://github.com/maiha/ircbot"
4
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'ircbot'
5
+
6
+ class EchoPlugin < Ircbot::Plugin
7
+ def help
8
+ "[Echo] echo back privmsg"
9
+ end
10
+
11
+ def reply(text)
12
+ return "[#{text}]"
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'ircbot'
5
+
6
+ class IrcPlugin < Ircbot::Plugin
7
+ def reply(text)
8
+ if direct?
9
+ if text[0] == ?!
10
+ command, params = text[1..-1].strip.split(/\s+/,2)
11
+ command = Net::IRC::Constants.const_get(command.to_s.upcase)
12
+ bot.__send__(:post, command, params)
13
+ throw :halt
14
+ end
15
+ end
16
+ return nil
17
+ end
18
+ end
19
+
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'ircbot'
5
+
6
+ class PluginsPlugin < Ircbot::Plugin
7
+ def help
8
+ <<-EOF
9
+ [control plugins]
10
+ usage: #{config.nick}.COMMANDS [PLUGIN_NAME]
11
+ commands: load, start, stop, delete
12
+ #{plugins_help}
13
+ EOF
14
+ end
15
+
16
+ def reply(text)
17
+ text.strip.gsub(/^#{config.nick}\./) {
18
+ command, arg = $'.split(/\s+/,2)
19
+ arg = arg.to_s.strip
20
+
21
+ case command.to_s
22
+ when "load", "register"
23
+ plugins << Array(arg.split)
24
+ throw :halt, "Loaded #{arg}"
25
+
26
+ when "delete", "remove"
27
+ plugins.remove arg
28
+ throw :halt, "Removed #{arg}"
29
+
30
+ when "start"
31
+ plugins.start arg
32
+ throw :halt, "Started #{arg}"
33
+
34
+ when "stop"
35
+ plugins.stop arg
36
+ throw :halt, "Stopped #{arg}"
37
+
38
+ when "help"
39
+ if arg.empty?
40
+ throw :halt, [bot_help, plugins_help].join("\n")
41
+ else
42
+ throw :halt, plugins[arg].help
43
+ end
44
+ end
45
+ }
46
+ return nil
47
+ end
48
+
49
+ private
50
+ def plugins_help
51
+ "plugins: %s" % plugins.map(&:to_s).join(', ')
52
+ end
53
+
54
+ def bot_help
55
+ config.help ||
56
+ "%s bot [%s (ver:%s)]" % [config.nick, Ircbot::HOMEPAGE, Ircbot::VERSION]
57
+ end
58
+ end
59
+
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
4
+
5
+ describe Ircbot::Client do
6
+ it "should provide .new" do
7
+ Ircbot::Client.should respond_to(:new)
8
+ end
9
+
10
+ describe ".new" do
11
+ it "should accept a hash" do
12
+ lambda {
13
+ Ircbot::Client.new({})
14
+ }.should_not raise_error
15
+ end
16
+ end
17
+
18
+ describe "#config" do
19
+ before do
20
+ @config = {
21
+ :nick => "sama-zu",
22
+ :user => "samazu",
23
+ :real => "sama~zu",
24
+ :host => "localhost",
25
+ :port => "6667",
26
+ }
27
+ end
28
+
29
+ subject { Ircbot::Client.new(@config).config }
30
+
31
+ its(:nick) { should == "sama-zu" }
32
+ its(:user) { should == "samazu" }
33
+ its(:real) { should == "sama~zu" }
34
+ its(:host) { should == "localhost" }
35
+ its(:port) { should == "6667" }
36
+
37
+ describe "#channels" do
38
+ it "should return the array when an array is given" do
39
+ @config[:channels] = ["#ircbot"]
40
+ subject.channels.should == ["#ircbot"]
41
+ end
42
+
43
+ it "should return array when a string is given" do
44
+ @config[:channels] = "#ircbot"
45
+ subject.channels.should == ["#ircbot"]
46
+ end
47
+
48
+ it "should return [] when nil" do
49
+ @config[:channels] = nil
50
+ subject.channels.should == []
51
+ end
52
+ end
53
+ end
54
+
55
+ ######################################################################
56
+ ### Initialize from file
57
+
58
+ it "should provide .from_file" do
59
+ Ircbot::Client.should respond_to(:from_file)
60
+ end
61
+
62
+ ######################################################################
63
+ ### Readers
64
+
65
+ describe Ircbot::Client::Config do
66
+ describe "#read" do
67
+ it "should delegate to read_yml" do
68
+ # mock(subject).read_yml(__FILE__)
69
+ # subject.read(__FILE__)
70
+ end
71
+ end
72
+
73
+ describe "#read_yml" do
74
+ it do
75
+ hash = Ircbot::Client::Config.read(path("sama-zu.yml"))
76
+ hash.should be_a_kind_of(Mash)
77
+ hash["nick"].should == "sama-zu"
78
+ hash[:nick].should == "sama-zu"
79
+ end
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,8 @@
1
+ host: localhost
2
+ port: 6667
3
+ nick: sama-zu
4
+ user: samazu
5
+ real: sama~zu
6
+ help: sama-zu bot (2010/01/09)
7
+ channels: "#test"
8
+ plugins: irc plugins
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
4
+
5
+ describe Ircbot do
6
+ provide :root
7
+ provide :root=
8
+ provide :push_path
9
+ provide :glob_for
10
+
11
+ describe ".glob_for" do
12
+ it do
13
+ dir = Pathname(File.dirname(__FILE__))
14
+ Ircbot.push_path(:spec, dir)
15
+ Ircbot.glob_for(:spec, "sama-zu").should == [dir + "fixtures" + "sama-zu.yml"]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Spec
2
+ module Example
3
+ module Subject
4
+ module ExampleGroupMethods
5
+ def its(*args, &block)
6
+ describe(args.first) do
7
+ define_method(:subject) { super().send(*args) }
8
+ it(&block)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
4
+
5
+ describe Ircbot::Plugin do
6
+ class Foo < Ircbot::Plugin; end
7
+ class Bar < Ircbot::Plugin; end
8
+ class BarPlugin < Ircbot::Plugin; end
9
+
10
+ subject { Ircbot::Plugin.new }
11
+
12
+ ######################################################################
13
+ ### plugin name
14
+
15
+ provide :plugin_name
16
+
17
+ its(:plugin_name) { should == 'plugin' }
18
+ describe "#plugin_name" do
19
+ it { Foo.new.plugin_name.should == "foo" }
20
+ it { Bar.new.plugin_name.should == "bar" }
21
+ it { BarPlugin.new.plugin_name.should == "bar" }
22
+ end
23
+
24
+ provide :message
25
+ its(:message) { should be_kind_of(Ircbot::Plugin::InitialMessage) }
26
+
27
+ provide :plugins
28
+ provide :running
29
+ provide :config
30
+ provide :client
31
+ provide :bot
32
+
33
+ ######################################################################
34
+ ### private methods
35
+
36
+ provide :plugin
37
+ provide :plugin!
38
+ provide :direct?
39
+
40
+ ######################################################################
41
+ ### Not connected
42
+
43
+ context "(not connected)" do
44
+ subject{ Ircbot::Plugin.new }
45
+
46
+ its(:plugin , :foo) { should be_kind_of(Ircbot::Plugin::Null) }
47
+ its(:plugin!, :foo) { lambda {subject}.should raise_error(Ircbot::PluginNotFound) }
48
+ its(:direct? ) { should == false }
49
+ end
50
+
51
+ ######################################################################
52
+ ### Connected
53
+
54
+ describe "(connected)" do
55
+ before do
56
+ @client = Ircbot::Client.new({})
57
+ @plugins = Ircbot::Plugins.new(@client)
58
+ @foo = Foo.new
59
+ @bar = Bar.new
60
+ @plugins << @foo << @bar
61
+ end
62
+ subject{ Ircbot::Plugin.new(@plugins) }
63
+
64
+ its(:plugin , :foo) { should == @foo }
65
+ its(:plugin!, :foo) { should == @foo }
66
+ its(:direct? ) { should == false }
67
+ end
68
+
69
+ end
70
+
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
4
+
5
+ describe Ircbot::Plugins do
6
+
7
+ ######################################################################
8
+ ### accessor methods
9
+
10
+ provide :client
11
+ provide :plugins
12
+ provide :active
13
+ provide :load_plugins
14
+ provide :load_plugin
15
+ provide :[]
16
+ provide :<<
17
+ provide :bot
18
+ provide :start
19
+ provide :stop
20
+ provide :delete
21
+
22
+ ######################################################################
23
+ ### Enumerable
24
+
25
+ provide :each
26
+ it "should be enumerable" do
27
+ subject.class.ancestors.should include(Enumerable)
28
+ end
29
+
30
+ end
@@ -0,0 +1,36 @@
1
+ ######################################################################
2
+ ### provide matcher
3
+ Spec::Matchers.define :provide do |expected|
4
+ match do |obj|
5
+ (obj.public_methods + obj.protected_methods + obj.private_methods).include?(expected.to_s)
6
+ end
7
+ end
8
+
9
+ module Spec
10
+ module Example
11
+ module Subject
12
+ module ExampleGroupMethods
13
+ # == Examples
14
+ #
15
+ # describe User do
16
+ # subject { User.new }
17
+ # provide :name
18
+ #
19
+ # [intead of]
20
+ #
21
+ # it "should provide #name" do
22
+ # methods = subject.public_methods + subject.protected_methods + subject.private_methods
23
+ # methods.should include("name")
24
+ # end
25
+ # end
26
+ #
27
+ def provide(name)
28
+ it "should provide ##{name}" do
29
+ subject.should provide(name)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,16 @@
1
+
2
+ require 'spec'
3
+ require 'rr'
4
+
5
+ require File.join(File.dirname(__FILE__), '/../lib/ircbot')
6
+ require File.join(File.dirname(__FILE__), '/its_helper')
7
+ require File.join(File.dirname(__FILE__), '/provide_helper')
8
+
9
+
10
+ def path(key)
11
+ Pathname(File.join(File.dirname(__FILE__) + "/fixtures/#{key}"))
12
+ end
13
+
14
+ def data(key)
15
+ path(key).read{}
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ircbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maiha
@@ -9,20 +9,30 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-02 00:00:00 +09:00
12
+ date: 2010-01-09 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: activesupport
16
+ name: extlib
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.0.0
23
+ version: 0.9.14
24
24
  version:
25
- description: old fashioned irc bot
25
+ - !ruby/object:Gem::Dependency
26
+ name: net-irc
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.9
34
+ version:
35
+ description: An irc bot framework that offers easy-to-use by plugins
26
36
  email: maiha@wota.jp
27
37
  executables:
28
38
  - ircbot
@@ -35,21 +45,32 @@ files:
35
45
  - MIT-LICENSE
36
46
  - README
37
47
  - Rakefile
38
- - lib/irc/agent.rb
39
- - lib/irc/const.rb
40
- - lib/irc/client.rb
41
- - lib/irc/localize.rb
42
- - lib/irc/irc.rb
43
48
  - lib/ircbot/framework.rb
44
- - lib/ircbot/ordered_hash.rb
45
- - lib/ircbot/reply_client.rb
46
- - lib/ircbot/core_ext/digest.rb
47
- - lib/ircbot/core_ext/rand-polimorphism.rb
48
- - lib/ircbot/core_ext/writefile.rb
49
- - lib/ircbot/core_ext/irc.rb
50
- - lib/ircbot/agent_manager.rb
51
- - lib/ircbot/config_client.rb
49
+ - lib/ircbot/client.rb
50
+ - lib/ircbot/client/config.rb
51
+ - lib/ircbot/client/config/channels.rb
52
+ - lib/ircbot/client/config/plugins.rb
53
+ - lib/ircbot/client/encoding.rb
54
+ - lib/ircbot/client/commands.rb
55
+ - lib/ircbot/client/plugins.rb
56
+ - lib/ircbot/core_ext/extending.rb
57
+ - lib/ircbot/core_ext/message.rb
58
+ - lib/ircbot/core_ext/delegation.rb
59
+ - lib/ircbot/plugins.rb
60
+ - lib/ircbot/version.rb
61
+ - lib/ircbot/plugin.rb
52
62
  - lib/ircbot.rb
63
+ - spec/config_spec.rb
64
+ - spec/plugin_spec.rb
65
+ - spec/provide_helper.rb
66
+ - spec/fixtures/sama-zu.yml
67
+ - spec/its_helper.rb
68
+ - spec/spec_helper.rb
69
+ - spec/framework_spec.rb
70
+ - spec/plugins_spec.rb
71
+ - plugins/echo.rb
72
+ - plugins/plugins.rb
73
+ - plugins/irc.rb
53
74
  has_rdoc: true
54
75
  homepage: http://github.com/maiha/ircbot
55
76
  licenses: []
@@ -77,6 +98,6 @@ rubyforge_project: asakusarb
77
98
  rubygems_version: 1.3.5
78
99
  signing_key:
79
100
  specification_version: 3
80
- summary: old fashioned irc bot
101
+ summary: easy irc bot framework
81
102
  test_files: []
82
103