dragoon 0.0.3 → 0.0.4
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/color.rb +3 -4
- data/lib/dragoon/commands.rb +0 -1
- data/lib/dragoon/event.rb +2 -2
- data/lib/dragoon/event_manager.rb +1 -2
- data/lib/dragoon/version.rb +1 -1
- data/lib/dragoon.rb +11 -10
- data/spec/event_spec.rb +1 -0
- metadata +4 -4
data/lib/dragoon/color.rb
CHANGED
@@ -3,9 +3,9 @@ module Dragoon
|
|
3
3
|
|
4
4
|
# borrowed from Term::ANSIColors
|
5
5
|
COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9])?m/
|
6
|
-
# :yellow is reserved for
|
7
|
-
@@color_list = [:red, :green, :blue, :magenta, :cyan, :white]
|
6
|
+
@@color_list = [:red, :green, :blue, :magenta, :cyan, :white] # :yellow is reserved for highlighting keywords
|
8
7
|
|
8
|
+
# assign a permanent color to a text
|
9
9
|
def colorize(text)
|
10
10
|
@c_table ||= {}
|
11
11
|
color = @c_table.fetch(text) rescue @c_table[text] = next_color
|
@@ -20,8 +20,7 @@ module Dragoon
|
|
20
20
|
keywords.sort_by(&:length).reverse.inject(text) do |result, keyword|
|
21
21
|
result.gsub(keyword) { |word|
|
22
22
|
to_left_of_word, to_right_of_word = $`, $'
|
23
|
-
|
24
|
-
# check if inside exisitng highlighted word via ANSI ESCAPE
|
23
|
+
# check if inside exisitng highlighted word
|
25
24
|
if to_left_of_word =~ /#{COLORED_REGEXP}\S+$/ && to_right_of_word =~ /^\S+#{COLORED_REGEXP}/
|
26
25
|
word
|
27
26
|
else
|
data/lib/dragoon/commands.rb
CHANGED
data/lib/dragoon/event.rb
CHANGED
@@ -17,8 +17,8 @@ module Dragoon
|
|
17
17
|
self.new(:startup, Message.new(:text => line))
|
18
18
|
when /^PING :(\S+)/
|
19
19
|
self.new(:ping, Message.new(:text => line, :server => $1))
|
20
|
-
when
|
21
|
-
self.new(:mode, Message.new(:text => line))
|
20
|
+
when /^:(\S+) MODE \S+ :.*/
|
21
|
+
self.new(:mode, Message.new(:text => line, :nickname => $1))
|
22
22
|
when /^:(\S+)!(\S+)@(\S+) JOIN (\S+)/
|
23
23
|
self.new(:join, Message.new(:text => line,
|
24
24
|
:nickname => $1,
|
@@ -10,9 +10,8 @@ module Dragoon
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# register callbacks for certain events
|
13
|
-
# valid events are found on constant VALID_EVENTS
|
14
13
|
def on(event_name, &callback)
|
15
|
-
@handlers
|
14
|
+
@handlers ||= {}
|
16
15
|
@handlers[event_name] = callback
|
17
16
|
end
|
18
17
|
|
data/lib/dragoon/version.rb
CHANGED
data/lib/dragoon.rb
CHANGED
@@ -26,7 +26,7 @@ module Dragoon
|
|
26
26
|
DEFAULT_PORT = 6667
|
27
27
|
CONFIG_FILE = File.expand_path("~/.dragoon")
|
28
28
|
|
29
|
-
def initialize
|
29
|
+
def initialize
|
30
30
|
@event_manager = EventManager.new
|
31
31
|
load_config
|
32
32
|
init_callbacks
|
@@ -35,17 +35,21 @@ module Dragoon
|
|
35
35
|
def load_config
|
36
36
|
begin
|
37
37
|
if File.exist?(CONFIG_FILE)
|
38
|
-
puts("*** Loading config file
|
38
|
+
puts("*** Loading config file #{CONFIG_FILE}")
|
39
39
|
config = JSON.parse(File.read(CONFIG_FILE))
|
40
|
+
@nickname = config["nickname"]
|
41
|
+
@network = config["network"]
|
42
|
+
@channels = config["channels"]
|
43
|
+
@keywords = config["keywords"]
|
40
44
|
else
|
41
45
|
config = {
|
42
|
-
"nickname" => "
|
46
|
+
"nickname" => "fenix#{rand(10)}#{rand(10)}#{rand(10)}",
|
43
47
|
"network" => "irc.freenode.net",
|
44
48
|
"channels" => %w[ #ubuntu #ruby #rubyonrails #linux #programming #javascript ],
|
45
49
|
"keywords" => %w[ and how who ]
|
46
50
|
}
|
47
51
|
File.open(CONFIG_FILE,'w+') {|f| f.write(JSON.pretty_generate(config)) }
|
48
|
-
puts("Config file does not exist...created one at #{CONFIG_FILE}".red)
|
52
|
+
puts("Config file does not exist...created a default one at #{CONFIG_FILE}".red)
|
49
53
|
puts("Please modify it according to your preference".red)
|
50
54
|
exit 1
|
51
55
|
end
|
@@ -53,10 +57,6 @@ module Dragoon
|
|
53
57
|
$stderr.puts e.message
|
54
58
|
exit 1
|
55
59
|
end
|
56
|
-
@nickname = config["nickname"]
|
57
|
-
@network = config["network"]
|
58
|
-
@channels = config["channels"]
|
59
|
-
@keywords = config["keywords"]
|
60
60
|
end
|
61
61
|
|
62
62
|
def init_callbacks
|
@@ -74,7 +74,7 @@ module Dragoon
|
|
74
74
|
end
|
75
75
|
|
76
76
|
on :mode do |msg|
|
77
|
-
puts "*** Logged in as #{
|
77
|
+
puts "*** Logged in as #{msg.nickname}"
|
78
78
|
join_channels
|
79
79
|
end
|
80
80
|
|
@@ -96,7 +96,7 @@ module Dragoon
|
|
96
96
|
if system("which growlnotify > /dev/null")
|
97
97
|
if keyword = self.keywords.detect { |keyword| msg.text.include?(keyword) }
|
98
98
|
system("growlnotify " +
|
99
|
-
"-t \"#{keyword}\" " +
|
99
|
+
"-t \"#{msg.channel} - #{keyword}\" " +
|
100
100
|
"-m \"#{escape_double_quotes(msg.privmsg)}\"")
|
101
101
|
end
|
102
102
|
end
|
@@ -115,6 +115,7 @@ module Dragoon
|
|
115
115
|
|
116
116
|
def connect
|
117
117
|
puts "*** Connecting to #{@network} on port #{DEFAULT_PORT}"
|
118
|
+
puts "*** Press Ctrl + c to stop the program"
|
118
119
|
TCPSocket.new(@network, DEFAULT_PORT)
|
119
120
|
end
|
120
121
|
|
data/spec/event_spec.rb
CHANGED
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
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-01-
|
18
|
+
date: 2012-01-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|