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 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 highlight keywords
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
@@ -24,7 +24,6 @@ module Dragoon
24
24
  private
25
25
 
26
26
  def write(text)
27
- $stdout.puts text
28
27
  @socket.write "#{text}\r\n"
29
28
  end
30
29
 
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 /^:\S+ MODE \S+ :.*/
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 = {} if @handlers.nil?
14
+ @handlers ||= {}
16
15
  @handlers[event_name] = callback
17
16
  end
18
17
 
@@ -1,3 +1,3 @@
1
1
  module Dragoon
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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(&blk)
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 ~/.dragoon")
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" => "your_nick",
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 #{self.nickname}"
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
@@ -23,6 +23,7 @@ describe Dragoon::Event do
23
23
  event = Dragoon::Event.parse(msg)
24
24
  event.name.should == :mode
25
25
  event.message.text.should == ":favor212 MODE favor212 :+i"
26
+ event.message.nickname.should == "favor212"
26
27
  end
27
28
 
28
29
  it "should process join event" do
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
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-23 00:00:00 Z
18
+ date: 2012-01-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec