dragoon 0.0.9 → 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.
- data/lib/dragoon.rb +9 -4
- data/lib/dragoon/event.rb +1 -1
- data/lib/dragoon/receiver.rb +22 -0
- data/lib/dragoon/version.rb +1 -1
- data/spec/dragoon_spec.rb +1 -1
- data/spec/event_spec.rb +11 -1
- data/spec/receiver_spec.rb +36 -0
- data/spec/spec_helper.rb +2 -2
- metadata +7 -5
data/lib/dragoon.rb
CHANGED
@@ -7,6 +7,7 @@ require 'json'
|
|
7
7
|
require 'active_support/core_ext/hash/indifferent_access'
|
8
8
|
|
9
9
|
require 'dragoon/event'
|
10
|
+
require 'dragoon/receiver'
|
10
11
|
require 'dragoon/network'
|
11
12
|
require 'dragoon/event_manager'
|
12
13
|
require 'dragoon/color'
|
@@ -99,14 +100,14 @@ module Dragoon
|
|
99
100
|
end
|
100
101
|
|
101
102
|
on :privmsg do |msg, source|
|
102
|
-
if growlnotify_supported?
|
103
|
+
if growlnotify_supported? && growl_running?
|
103
104
|
if keyword = @keywords.detect { |keyword| msg.text.include?(keyword) }
|
104
105
|
system("growlnotify " +
|
105
|
-
"-t \"#{msg.
|
106
|
+
"-t \"#{msg.receiver} - #{keyword}\" " +
|
106
107
|
"-m \"#{msg.privmsg.escape_double_quotes}\"")
|
107
108
|
end
|
108
109
|
end
|
109
|
-
log "#{colorize(msg.
|
110
|
+
log "#{colorize(msg.receiver)} <#{msg.nickname}> #{highlight_keywords(msg.privmsg,@keywords)}"
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
@@ -136,7 +137,7 @@ module Dragoon
|
|
136
137
|
dispatch(@event,
|
137
138
|
@networks.select{ |n|
|
138
139
|
n.server == socket.peeraddr[2] &&
|
139
|
-
n.port
|
140
|
+
n.port == socket.peeraddr[1]
|
140
141
|
}.first
|
141
142
|
)
|
142
143
|
end
|
@@ -167,6 +168,10 @@ module Dragoon
|
|
167
168
|
@growlnotify_supported ||= system("which growlnotify > /dev/null")
|
168
169
|
end
|
169
170
|
|
171
|
+
def growl_running?
|
172
|
+
`ps ax | grep -i growl | grep -v grep | wc -l `.strip.to_i == 1
|
173
|
+
end
|
174
|
+
|
170
175
|
end
|
171
176
|
end
|
172
177
|
|
data/lib/dragoon/event.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dragoon
|
2
|
+
# RFC 1459 section 4.4.1
|
3
|
+
#
|
4
|
+
# a receiver can be
|
5
|
+
# a nickname,
|
6
|
+
# a channel
|
7
|
+
#
|
8
|
+
class Receiver < String
|
9
|
+
|
10
|
+
def initialize(raw_string)
|
11
|
+
super(raw_string)
|
12
|
+
end
|
13
|
+
# checks if first character of is #
|
14
|
+
def channel?
|
15
|
+
self[0].chr == "#"
|
16
|
+
end
|
17
|
+
|
18
|
+
def nickname?
|
19
|
+
!channel?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/dragoon/version.rb
CHANGED
data/spec/dragoon_spec.rb
CHANGED
data/spec/event_spec.rb
CHANGED
@@ -49,8 +49,18 @@ describe Dragoon::Event do
|
|
49
49
|
event.message.nickname.should == "nick"
|
50
50
|
event.message.user.should == "~user"
|
51
51
|
event.message.hostname.should == "hostname"
|
52
|
-
event.message.
|
52
|
+
event.message.receiver.should == "#ruby"
|
53
53
|
event.message.privmsg.should == "array << 0 if array.size.odd?"
|
54
|
+
|
55
|
+
msg = ":NeoStats!Neo@NeoStats.QuartzNet.Org PRIVMSG fenix456 :VERSION"
|
56
|
+
event = Dragoon::Event.parse(msg)
|
57
|
+
event.name.should == :privmsg
|
58
|
+
event.message.text.should == msg
|
59
|
+
event.message.nickname.should == "NeoStats"
|
60
|
+
event.message.user.should == "Neo"
|
61
|
+
event.message.hostname.should == "NeoStats.QuartzNet.Org"
|
62
|
+
event.message.receiver.should == "fenix456"
|
63
|
+
event.message.privmsg.should == "VERSION"
|
54
64
|
end
|
55
65
|
|
56
66
|
it "should process error reply event" do
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dragoon::Receiver do
|
4
|
+
context "when its a nickname" do
|
5
|
+
before(:each) do
|
6
|
+
@raw_string = "fenix456"
|
7
|
+
@receiver = Dragoon::Receiver.new(@raw_string)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be a nickname" do
|
11
|
+
@receiver.nickname?.should == true
|
12
|
+
@receiver.channel?.should == false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have nickname as value" do
|
16
|
+
@receiver.should == @raw_string
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when its a channel" do
|
21
|
+
before(:each) do
|
22
|
+
@raw_string = "#coffeescript"
|
23
|
+
@receiver = Dragoon::Receiver.new(@raw_string)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be a channel" do
|
27
|
+
@receiver.channel?.should == true
|
28
|
+
@receiver.nickname?.should == false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have channel as value" do
|
32
|
+
@receiver.should == @raw_string
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,13 +16,13 @@ class LocalServer
|
|
16
16
|
@port = port
|
17
17
|
end
|
18
18
|
|
19
|
+
# child processes spawned from accepting new connection would automatically quit upon client exit
|
19
20
|
def run
|
20
21
|
server = TCPServer.new('localhost', @port)
|
21
|
-
server.listen(5)
|
22
22
|
@pid = fork {
|
23
23
|
while socket = server.accept
|
24
24
|
fork {
|
25
|
-
trap("PIPE") { exit }
|
25
|
+
trap("PIPE") { exit } # exit on write attempt after client exits
|
26
26
|
loop { socket.write("localhost port #{socket.addr[1]} dumping text\r\n") }
|
27
27
|
}
|
28
28
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragoon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.9
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Reginald Tan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -99,7 +99,6 @@ extra_rdoc_files: []
|
|
99
99
|
files:
|
100
100
|
- .gitignore
|
101
101
|
- Gemfile
|
102
|
-
- Gemfile.lock
|
103
102
|
- README.md
|
104
103
|
- Rakefile
|
105
104
|
- TODO
|
@@ -111,12 +110,14 @@ files:
|
|
111
110
|
- lib/dragoon/event.rb
|
112
111
|
- lib/dragoon/event_manager.rb
|
113
112
|
- lib/dragoon/network.rb
|
113
|
+
- lib/dragoon/receiver.rb
|
114
114
|
- lib/dragoon/version.rb
|
115
115
|
- sample_config
|
116
116
|
- spec/colors_spec.rb
|
117
117
|
- spec/dragoon_spec.rb
|
118
118
|
- spec/event_manager_spec.rb
|
119
119
|
- spec/event_spec.rb
|
120
|
+
- spec/receiver_spec.rb
|
120
121
|
- spec/spec_helper.rb
|
121
122
|
homepage: https://github.com/redgetan/dragoon
|
122
123
|
licenses: []
|
@@ -156,5 +157,6 @@ test_files:
|
|
156
157
|
- spec/dragoon_spec.rb
|
157
158
|
- spec/event_manager_spec.rb
|
158
159
|
- spec/event_spec.rb
|
160
|
+
- spec/receiver_spec.rb
|
159
161
|
- spec/spec_helper.rb
|
160
162
|
has_rdoc:
|