ponder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Ponder
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def force_encoding(arg)
3
+ self
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ponder'
3
+ s.version = '0.0.1'
4
+ s.summary = 'IRC bot framework'
5
+ s.description = 'Ponder (Stibbons) is a Domain Specific Language for writing IRC Bots using the EventMachine library.'
6
+
7
+ s.author = 'Tobias Bühlmann'
8
+ s.email = 'tobias.buehlmann@gmx.de'
9
+ s.homepage = 'http://github.com/tbuehlmann/ponder'
10
+
11
+ s.required_ruby_version = '>= 1.8.6'
12
+ s.add_dependency('eventmachine', '>= 0.12.10')
13
+ s.files = ['examples/echo.rb',
14
+ 'examples/github_blog.rb',
15
+ 'lib/ponder/async_irc.rb',
16
+ 'lib/ponder/callback.rb',
17
+ 'lib/ponder/connection.rb',
18
+ 'lib/ponder/delegate.rb',
19
+ 'lib/ponder/filter.rb',
20
+ 'lib/ponder/formatting.rb',
21
+ 'lib/ponder/irc.rb',
22
+ 'lib/ponder/logger',
23
+ 'lib/ponder/thaum.rb',
24
+ 'lib/ponder/version.rb',
25
+ 'lib/ponder/logger/blind_io.rb',
26
+ 'lib/ponder/logger/twoflogger.rb',
27
+ 'lib/ponder/logger/twoflogger18.rb',
28
+ 'lib/ruby/1.8/string.rb',
29
+ 'lib/ponder.rb',
30
+ 'test/all_tests.rb',
31
+ 'test/test_async_irc.rb',
32
+ 'test/test_callback.rb',
33
+ 'test/test_helper.rb',
34
+ 'test/test_irc.rb',
35
+ 'LICENSE',
36
+ 'ponder.gemspec',
37
+ 'README.md']
38
+ end
39
+
@@ -0,0 +1,7 @@
1
+ require 'pathname'
2
+ $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.expand_path
3
+
4
+ require 'test_callback'
5
+ require 'test_async_irc'
6
+ require 'test_irc'
7
+
@@ -0,0 +1,108 @@
1
+ require 'pathname'
2
+ $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.expand_path
3
+ require 'test_helper'
4
+ require 'ponder/async_irc'
5
+
6
+ module Ponder
7
+ module AsyncIRC
8
+ def raw(*args)
9
+ end
10
+ end
11
+ end
12
+
13
+ include Ponder::AsyncIRC
14
+
15
+ class TestIRC < Test::Unit::TestCase
16
+ def setup
17
+ @observer_queues = {}
18
+ end
19
+
20
+ def test_get_topic_no_topic_set
21
+ topic = Thread.new do
22
+ assert_equal({:raw_numeric => 331, :message => 'No topic is set'}, get_topic('#mended_drum'))
23
+ end
24
+
25
+ event_loop = Thread.new do
26
+ loop do
27
+ message = ':server 331 Ponder #mended_drum :No topic is set.'
28
+ @observer_queues.each do |queue, regexps|
29
+ regexps.each do |regexp|
30
+ if message =~ regexp
31
+ queue << message
32
+ end
33
+ end
34
+ end
35
+
36
+ sleep 0.1
37
+ end
38
+ end
39
+ topic.join
40
+ end
41
+
42
+ def test_get_topic
43
+ topic = Thread.new do
44
+ assert_equal({:raw_numeric => 332, :message => 'No dwarfs in here!'}, get_topic('#mended_drum'))
45
+ end
46
+
47
+ event_loop = Thread.new do
48
+ loop do
49
+ message = ':server 332 Ponder #mended_drum :No dwarfs in here!'
50
+ @observer_queues.each do |queue, regexps|
51
+ regexps.each do |regexp|
52
+ if message =~ regexp
53
+ queue << message
54
+ end
55
+ end
56
+ end
57
+
58
+ sleep 0.1
59
+ end
60
+ end
61
+ topic.join
62
+ end
63
+
64
+ def test_get_topic_no_such_channel
65
+ topic = Thread.new do
66
+ assert_equal({:raw_numeric => 403, :message => 'No such channel'}, get_topic('#mended_drum'))
67
+ end
68
+
69
+ event_loop = Thread.new do
70
+ loop do
71
+ message = ':server 403 Ponder #mended_drum :No such channel'
72
+ @observer_queues.each do |queue, regexps|
73
+ regexps.each do |regexp|
74
+ if message =~ regexp
75
+ queue << message
76
+ end
77
+ end
78
+ end
79
+
80
+ sleep 0.1
81
+ end
82
+ end
83
+ topic.join
84
+ end
85
+
86
+ def test_get_topic_you_are_not_on_that_channel
87
+ topic = Thread.new do
88
+ assert_equal({:raw_numeric => 442, :message => "You're not on that channel"}, get_topic('#mended_drum'))
89
+ end
90
+
91
+ event_loop = Thread.new do
92
+ loop do
93
+ message = ":server 442 Ponder #mended_drum :You're not on that channel"
94
+ @observer_queues.each do |queue, regexps|
95
+ regexps.each do |regexp|
96
+ if message =~ regexp
97
+ queue << message
98
+ end
99
+ end
100
+ end
101
+
102
+ sleep 0.1
103
+ end
104
+ end
105
+ topic.join
106
+ end
107
+ end
108
+
@@ -0,0 +1,55 @@
1
+ require 'pathname'
2
+ $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.expand_path
3
+ require 'test_helper'
4
+ require 'ponder/callback'
5
+
6
+ module Ponder
7
+ class Callback
8
+ attr_reader :event_type, :match, :proc
9
+ end
10
+ end
11
+
12
+ class TestCallback < Test::Unit::TestCase
13
+ def setup
14
+ @empty_proc = Proc.new { }
15
+ end
16
+
17
+ def test_perfect_case
18
+ callback = Ponder::Callback.new(:channel, /foo/, @empty_proc)
19
+
20
+ assert_equal(:channel, callback.event_type)
21
+ assert_equal(/foo/, callback.match)
22
+ assert_equal(@empty_proc, callback.proc)
23
+ end
24
+
25
+ def test_unsupported_event_type
26
+ assert_raise(TypeError) do
27
+ Ponder::Callback.new('fu', /foo/, @empty_proc)
28
+ end
29
+ end
30
+
31
+ def test_regexp
32
+ assert_raise(TypeError) do
33
+ Ponder::Callback.new(:channel, 8, @empty_proc)
34
+ end
35
+ end
36
+
37
+ def test_proc
38
+ assert_raise(TypeError) do
39
+ Ponder::Callback.new(:channel, /foo/, 8)
40
+ end
41
+ end
42
+
43
+ def test__trivial_proc
44
+ proc = Proc.new { 7 + 1 }
45
+
46
+ assert_equal(proc, Ponder::Callback.new(:channel, //, proc).proc)
47
+ end
48
+
49
+ def test_call
50
+ proc = Proc.new { 8 }
51
+
52
+ assert_equal(8, Ponder::Callback.new(:channel, /wizzard/, proc).call(:channel, {:message => 'I like wizzards'}))
53
+ assert_nil(Ponder::Callback.new(:channel, /wizzard/, proc).call(:channel, {:message => 'I am a wizard'}))
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+
3
+ $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.join('..', 'lib').expand_path
@@ -0,0 +1,130 @@
1
+ require 'pathname'
2
+ $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.expand_path
3
+ require 'test_helper'
4
+ require 'ponder/irc'
5
+ require 'ostruct'
6
+
7
+ include Ponder::IRC
8
+
9
+ module Ponder
10
+ module IRC
11
+ def raw(message)
12
+ $output << "#{message}\r\n"
13
+ return "#{message}\r\n"
14
+ end
15
+ end
16
+ end
17
+
18
+ class TestIRC < Test::Unit::TestCase
19
+ def setup
20
+ @config = ::OpenStruct.new({:nick => 'Ponder',
21
+ :username => 'Ponder',
22
+ :real_name => 'Ponder Stibbons',
23
+ :password => 'secret',
24
+ :reconnect => true
25
+ })
26
+ $output = []
27
+ end
28
+
29
+ def test_message
30
+ assert_equal("PRIVMSG recipient :foo bar baz\r\n", Ponder::IRC.message('recipient', 'foo bar baz')) # `message` is already defined, so we need to use Ponder::IRC
31
+ end
32
+
33
+ def test_register
34
+ register
35
+
36
+ assert_equal(["NICK Ponder\r\n", "USER Ponder * * :Ponder Stibbons\r\n", "PASS secret\r\n"], $output)
37
+ end
38
+
39
+ def test_register_without_password
40
+ @config.password = nil
41
+ register
42
+
43
+ assert_equal(["NICK Ponder\r\n", "USER Ponder * * :Ponder Stibbons\r\n"], $output)
44
+ end
45
+
46
+ def test_notice
47
+ assert_equal("NOTICE Ponder :You are cool!\r\n", notice('Ponder', 'You are cool!'))
48
+ end
49
+
50
+ def test_mode
51
+ assert_equal("MODE Ponder +ao\r\n", mode('Ponder', '+ao'))
52
+ end
53
+
54
+ def test_kick
55
+ assert_equal("KICK #channel Nanny_Ogg\r\n", kick('#channel', 'Nanny_Ogg'))
56
+ end
57
+
58
+ def test_kick_with_reason
59
+ assert_equal("KICK #channel Nanny_Ogg :Go away!\r\n", kick('#channel', 'Nanny_Ogg', 'Go away!'))
60
+ end
61
+
62
+ def test_action
63
+ assert_equal("PRIVMSG #channel :\001ACTION HEX is working!\001\r\n", action('#channel', 'HEX is working!'))
64
+ end
65
+
66
+ def test_topic
67
+ assert_equal("TOPIC #channel :I like dried frog pills.\r\n", topic('#channel', 'I like dried frog pills.'))
68
+ end
69
+
70
+ def test_join
71
+ assert_equal("JOIN #channel\r\n", join('#channel'))
72
+ end
73
+
74
+ def test_join_with_password
75
+ assert_equal("JOIN #channel secret\r\n", join('#channel', 'secret'))
76
+ end
77
+
78
+ def test_part
79
+ assert_equal("PART #channel\r\n", part('#channel'))
80
+ end
81
+
82
+ def test_part_with_message
83
+ assert_equal("PART #channel :Partpart\r\n", part('#channel', 'Partpart'))
84
+ end
85
+
86
+ def test_quit
87
+ quit
88
+
89
+ assert_equal(["QUIT\r\n"], $output)
90
+ end
91
+
92
+ def test_quit_with_message
93
+ quit('GONE')
94
+
95
+ assert_equal(["QUIT :GONE\r\n"], $output)
96
+ end
97
+
98
+ def test_quit_reconnect_change
99
+ assert_equal(true, @config.reconnect)
100
+
101
+ quit
102
+
103
+ assert_equal(false, @config.reconnect)
104
+ end
105
+
106
+ def test_rename
107
+ assert_equal("NICK :Ridcully\r\n", rename('Ridcully'))
108
+ end
109
+
110
+ def test_away
111
+ assert_equal("AWAY\r\n", away)
112
+ end
113
+
114
+ def test_away_with_message
115
+ assert_equal("AWAY :At the Mended Drum\r\n", away('At the Mended Drum'))
116
+ end
117
+
118
+ def test_back
119
+ assert_equal("AWAY\r\n", back)
120
+ end
121
+
122
+ def test_invite
123
+ assert_equal("INVITE TheLibrarian #mended_drum\r\n", invite('TheLibrarian', '#mended_drum'))
124
+ end
125
+
126
+ def test_ban
127
+ assert_equal("MODE #mended_drum +b foo!bar@baz\r\n", ban('#mended_drum', 'foo!bar@baz'))
128
+ end
129
+ end
130
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ponder
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Tobias B\xC3\xBChlmann"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-09 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: eventmachine
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 12
33
+ - 10
34
+ version: 0.12.10
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Ponder (Stibbons) is a Domain Specific Language for writing IRC Bots using the EventMachine library.
38
+ email: tobias.buehlmann@gmx.de
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - examples/echo.rb
47
+ - examples/github_blog.rb
48
+ - lib/ponder/async_irc.rb
49
+ - lib/ponder/callback.rb
50
+ - lib/ponder/connection.rb
51
+ - lib/ponder/delegate.rb
52
+ - lib/ponder/filter.rb
53
+ - lib/ponder/formatting.rb
54
+ - lib/ponder/irc.rb
55
+ - lib/ponder/thaum.rb
56
+ - lib/ponder/version.rb
57
+ - lib/ponder/logger/blind_io.rb
58
+ - lib/ponder/logger/twoflogger.rb
59
+ - lib/ponder/logger/twoflogger18.rb
60
+ - lib/ruby/1.8/string.rb
61
+ - lib/ponder.rb
62
+ - test/all_tests.rb
63
+ - test/test_async_irc.rb
64
+ - test/test_callback.rb
65
+ - test/test_helper.rb
66
+ - test/test_irc.rb
67
+ - LICENSE
68
+ - ponder.gemspec
69
+ - README.md
70
+ has_rdoc: true
71
+ homepage: http://github.com/tbuehlmann/ponder
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 59
85
+ segments:
86
+ - 1
87
+ - 8
88
+ - 6
89
+ version: 1.8.6
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: IRC bot framework
106
+ test_files: []
107
+