vetinari 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/lib/vetinari/bot.rb +17 -0
- data/lib/vetinari/callback_container.rb +8 -0
- data/lib/vetinari/channel.rb +5 -3
- data/lib/vetinari/channel_container.rb +6 -0
- data/lib/vetinari/irc.rb +3 -3
- data/lib/vetinari/version.rb +1 -1
- data/spec/bot_spec.rb +30 -0
- data/spec/callback_spec.rb +4 -0
- data/spec/channel_management_spec.rb +2 -0
- data/spec/channel_spec.rb +4 -0
- data/spec/default_callbacks_spec.rb +2 -0
- data/spec/join_spec.rb +2 -0
- data/spec/rename_spec.rb +2 -0
- data/spec/user_management_spec.rb +4 -0
- data/spec/user_spec.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe414b4c35924d0c5fa15e67e84494b74b23f31f
|
4
|
+
data.tar.gz: 5e82b546876eb70fe159d0c9480fdeffbecbfacf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0c60adeae677929cb9d903674432787c854c9185fd924e89443a65ffc5b1c1f1668e4c26e3fd2ea307405c453324f4a7faa509b6e12de97890ce80065742227
|
7
|
+
data.tar.gz: 9760ed1524abde7e444ada03ec74c4728467ceffb65ec21879ff0b7bcdab9c989af0fc1e9a88e77751e648ea9c12eeca763e5ded23e794d5f60df0e3baad82a0
|
data/lib/vetinari/bot.rb
CHANGED
@@ -4,6 +4,8 @@ module Vetinari
|
|
4
4
|
|
5
5
|
attr_reader :config, :users, :user, :channels, :server_manager, :callbacks
|
6
6
|
|
7
|
+
finalizer :finalize
|
8
|
+
|
7
9
|
def initialize(&block)
|
8
10
|
@actor = Actor.current
|
9
11
|
@config = Configuration.new(&block)
|
@@ -75,6 +77,21 @@ module Vetinari
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
80
|
+
def finalize
|
81
|
+
if connected?
|
82
|
+
quit
|
83
|
+
@socket.close rescue nil
|
84
|
+
end
|
85
|
+
|
86
|
+
@callbacks.terminate_callbacks
|
87
|
+
@users.terminate
|
88
|
+
@channels.terminate
|
89
|
+
|
90
|
+
links.each do |actor|
|
91
|
+
actor.terminate if actor.alive?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
78
95
|
private
|
79
96
|
|
80
97
|
def disconnected
|
data/lib/vetinari/channel.rb
CHANGED
@@ -17,6 +17,8 @@ module Vetinari
|
|
17
17
|
@modes = {}
|
18
18
|
@lists = Hash.new { |hash, key| hash[key] = [] }
|
19
19
|
@mutex = Mutex.new
|
20
|
+
|
21
|
+
link(@bot)
|
20
22
|
end
|
21
23
|
|
22
24
|
# Experimental, no tests so far.
|
@@ -105,7 +107,7 @@ module Vetinari
|
|
105
107
|
callbacks << @bot.on(:join) do |env|
|
106
108
|
if env[:channel].name == @name
|
107
109
|
condition.signal :joined
|
108
|
-
callbacks.each { |cb| cb.remove_and_terminate }
|
110
|
+
callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
|
109
111
|
end
|
110
112
|
end
|
111
113
|
|
@@ -122,14 +124,14 @@ module Vetinari
|
|
122
124
|
|
123
125
|
if channel_name == @name
|
124
126
|
condition.signal msg
|
125
|
-
callbacks.each { |cb| cb.remove_and_terminate }
|
127
|
+
callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
|
126
128
|
end
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
130
132
|
after(5) do
|
131
133
|
condition.signal :timeout
|
132
|
-
callbacks.each { |cb| cb.remove_and_terminate }
|
134
|
+
callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
|
133
135
|
end
|
134
136
|
|
135
137
|
if key
|
data/lib/vetinari/irc.rb
CHANGED
@@ -19,7 +19,7 @@ module Vetinari
|
|
19
19
|
callbacks << on(:nick_change) do |env|
|
20
20
|
if env[:user].bot?
|
21
21
|
condition.signal env[:user].nick
|
22
|
-
callbacks.each { |cb| cb.remove_and_terminate }
|
22
|
+
callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -31,13 +31,13 @@ module Vetinari
|
|
31
31
|
raw_messages.each do |raw, msg|
|
32
32
|
callbacks << on(raw) do |env|
|
33
33
|
condition.signal(msg)
|
34
|
-
callbacks.each { |cb| cb.remove_and_terminate }
|
34
|
+
callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
after(5) do
|
39
39
|
condition.signal(:timeout)
|
40
|
-
callbacks.each { |cb| cb.remove_and_terminate }
|
40
|
+
callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
|
41
41
|
end
|
42
42
|
|
43
43
|
raw "NICK :#{nick}"
|
data/lib/vetinari/version.rb
CHANGED
data/spec/bot_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vetinari::Bot.new do
|
4
|
+
subject { Vetinari::Bot.new { |c| c.verbose = false } }
|
5
|
+
before(:each) do
|
6
|
+
Celluloid.shutdown
|
7
|
+
Celluloid.boot
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'terminates all linked actors on termination' do
|
11
|
+
expect do
|
12
|
+
subject.parse(':server 001 Vetinari :Welcome message')
|
13
|
+
subject.parse(':server 376 Vetinari :End of /MOTD command.')
|
14
|
+
subject.parse(':Vetinari!foo@bar JOIN #mended_drum')
|
15
|
+
subject.parse(':TheLibrarian!foo@bar JOIN #mended_drum')
|
16
|
+
subject.terminate
|
17
|
+
end.to_not change { Celluloid::Actor.all.size }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'terminates all linked actors on termination with wild channels' do
|
21
|
+
expect do
|
22
|
+
subject.parse(':server 001 Vetinari :Welcome message')
|
23
|
+
subject.parse(':server 376 Vetinari :End of /MOTD command.')
|
24
|
+
subject.parse(':Vetinari!foo@bar JOIN #mended_drum')
|
25
|
+
subject.parse(':TheLibrarian!foo@bar JOIN #mended_drum')
|
26
|
+
Vetinari::Channel.new('#unseen_university', subject)
|
27
|
+
subject.terminate
|
28
|
+
end.to_not change { Celluloid::Actor.all.size }
|
29
|
+
end
|
30
|
+
end
|
data/spec/callback_spec.rb
CHANGED
@@ -3,6 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe 'Callback' do
|
4
4
|
subject { Vetinari::Bot.new { |c| c.verbose = false } }
|
5
5
|
let(:callbacks) { subject.callbacks.instance_variable_get('@callbacks') }
|
6
|
+
before(:each) do
|
7
|
+
Celluloid.shutdown
|
8
|
+
Celluloid.boot
|
9
|
+
end
|
6
10
|
|
7
11
|
it 'is added correctly' do
|
8
12
|
expect(callbacks[:channel]).to have(1).callback
|
@@ -4,6 +4,8 @@ describe 'Channel Management' do
|
|
4
4
|
subject { Vetinari::Bot.new { |c| c.verbose = false } }
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
+
Celluloid.shutdown
|
8
|
+
Celluloid.boot
|
7
9
|
subject.parse(':server 001 Vetinari :Welcome message')
|
8
10
|
subject.parse(':server 376 Vetinari :End of /MOTD command.')
|
9
11
|
end
|
data/spec/channel_spec.rb
CHANGED
@@ -3,6 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe Vetinari::Channel do
|
4
4
|
bot = Vetinari::Bot.new
|
5
5
|
subject { Vetinari::Channel.new('#mended_drum', bot) }
|
6
|
+
before(:each) do
|
7
|
+
Celluloid.shutdown
|
8
|
+
Celluloid.boot
|
9
|
+
end
|
6
10
|
|
7
11
|
it 'responds to #to_s' do
|
8
12
|
expect(subject.to_s).to eq('#mended_drum')
|
data/spec/join_spec.rb
CHANGED
data/spec/rename_spec.rb
CHANGED
@@ -4,6 +4,8 @@ describe 'Bot#rename' do
|
|
4
4
|
subject { Vetinari::Bot.new { |c| c.verbose = false } }
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
+
Celluloid.shutdown
|
8
|
+
Celluloid.boot
|
7
9
|
subject.parse(':server 001 Vetinari :Welcome message')
|
8
10
|
subject.parse(':server 376 Vetinari :End of /MOTD command.')
|
9
11
|
subject.parse(':server 005 Vetinari NICKLEN=10')
|
@@ -2,6 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'User Management' do
|
4
4
|
subject { Vetinari::Bot.new { |c| c.verbose = false } }
|
5
|
+
before(:each) do
|
6
|
+
Celluloid.shutdown
|
7
|
+
Celluloid.boot
|
8
|
+
end
|
5
9
|
|
6
10
|
context 'Connecting to the server' do
|
7
11
|
it 'adds itself to the user_list when connected to the server' do
|
data/spec/user_spec.rb
CHANGED
@@ -3,6 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe Vetinari::User do
|
4
4
|
bot = Vetinari::Bot.new
|
5
5
|
subject { Vetinari::User.new('Ridcully', bot) }
|
6
|
+
before(:each) do
|
7
|
+
Celluloid.shutdown
|
8
|
+
Celluloid.boot
|
9
|
+
end
|
6
10
|
|
7
11
|
it 'responds to #to_s' do
|
8
12
|
expect(subject.to_s).to eq('Ridcully')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vetinari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Bühlmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid-io
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/vetinari/user.rb
|
115
115
|
- lib/vetinari/user_container.rb
|
116
116
|
- lib/vetinari/version.rb
|
117
|
+
- spec/bot_spec.rb
|
117
118
|
- spec/callback_spec.rb
|
118
119
|
- spec/channel_management_spec.rb
|
119
120
|
- spec/channel_spec.rb
|
@@ -150,6 +151,7 @@ signing_key:
|
|
150
151
|
specification_version: 4
|
151
152
|
summary: Multithreaded IRC Bot Framework.
|
152
153
|
test_files:
|
154
|
+
- spec/bot_spec.rb
|
153
155
|
- spec/callback_spec.rb
|
154
156
|
- spec/channel_management_spec.rb
|
155
157
|
- spec/channel_spec.rb
|