dragoon 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -45,6 +45,11 @@ Helpful links
45
45
  - http://www.paperplanes.de/2011/4/25/eventmachine-how-does-it-work.html (EM vs lower level socket prog, ie select, poll)
46
46
  - http://cia.vc/doc/
47
47
  - https://www6.software.ibm.com/developerworks/education/l-rubysocks/l-rubysocks-a4.pdf
48
+ - http://stackoverflow.com/questions/231647/how-do-i-set-the-socket-timeout-in-ruby
49
+ - http://peasleer.wordpress.com/2006/11/14/non-blocking-networking-in-ruby/
50
+ - http://www.troubleshooters.com/codecorn/sockets/ (socket read blocking in C)
51
+
52
+ - http://tomayko.com/writings/unicorn-is-unix
48
53
 
49
54
  Ncurses
50
55
 
@@ -23,7 +23,6 @@ module Dragoon
23
23
 
24
24
  def_delegators :@event_manager, :on, :dispatch
25
25
 
26
- DEFAULT_PORT = 6667
27
26
  CONFIG_FILE = File.expand_path("~/.dragoon")
28
27
 
29
28
  def initialize
@@ -37,18 +36,20 @@ module Dragoon
37
36
  if File.exist?(CONFIG_FILE)
38
37
  puts("*** Loading config file #{CONFIG_FILE}")
39
38
  config = JSON.parse(File.read(CONFIG_FILE))
39
+ @network = config["network"]
40
+ @port = config["port"]
40
41
  @nickname = config["nickname"]
41
42
  @password = config["password"]
42
- @network = config["network"]
43
43
  @channels = config["channels"]
44
44
  @keywords = config["keywords"]
45
45
  else
46
46
 
47
47
  config = (<<-EOF).gsub(/^\s{10}/,"")
48
48
  {
49
+ "network": "chat.freenode.net",
50
+ "port": "6667",
49
51
  "nickname": "fenix#{rand(10)}#{rand(10)}#{rand(10)}",
50
52
  "password": "",
51
- "network": "chat.freenode.net",
52
53
  "channels": [
53
54
  "#ubuntu",
54
55
  "#ruby",
@@ -111,11 +112,11 @@ module Dragoon
111
112
  end
112
113
 
113
114
  on :privmsg do |msg|
114
- if system("which growlnotify > /dev/null")
115
+ if growlnotify_supported?
115
116
  if keyword = @keywords.detect { |keyword| msg.text.include?(keyword) }
116
117
  system("growlnotify " +
117
118
  "-t \"#{msg.channel} - #{keyword}\" " +
118
- "-m \"#{escape_double_quotes(msg.privmsg)}\"")
119
+ "-m \"#{msg.privmsg.escape_double_quotes}\"")
119
120
  end
120
121
  end
121
122
  puts "#{colorize(msg.channel)} <#{msg.nickname}> #{highlight_keywords(msg.privmsg,@keywords)}"
@@ -133,22 +134,24 @@ module Dragoon
133
134
  end
134
135
 
135
136
  def connect
136
- puts "*** Connecting to #{@network} on port #{DEFAULT_PORT}"
137
+ puts "*** Connecting to #{@network} on port #{@port}"
137
138
  puts "*** Press Ctrl + c to stop the program"
138
- TCPSocket.new(@network, DEFAULT_PORT)
139
- end
140
-
141
- def escape_double_quotes(text)
142
- text.gsub("\"", "\\\"")
139
+ TCPSocket.new(@network, @port)
143
140
  end
144
141
 
145
142
  def stop
146
- @socket.close
147
143
  puts
148
144
  puts "*** Program stopped"
145
+ @socket.close
149
146
  exit
150
147
  end
151
148
 
149
+ private
150
+
151
+ def growlnotify_supported?
152
+ @growlnotify_supported ||= system("which growlnotify > /dev/null")
153
+ end
154
+
152
155
  end
153
156
  end
154
157
 
@@ -1,3 +1,9 @@
1
1
  class String
2
+
2
3
  include Term::ANSIColor
4
+
5
+ def escape_double_quotes
6
+ self.gsub("\"", "\\\"")
7
+ end
8
+
3
9
  end
@@ -1,10 +1,12 @@
1
1
  module Dragoon
2
+ # only supports a very basic one-to-one mapping of events
3
+ # currently no support for event heirarchy
2
4
  class EventManager
3
5
 
4
6
  attr_reader :handlers
5
7
 
6
8
  def dispatch(event)
7
- if @handlers.include?(event.name) && event.name != :unknown
9
+ if @handlers.include?(event.name)
8
10
  @handlers[event.name].call(event.message)
9
11
  end
10
12
  end
@@ -1,3 +1,3 @@
1
1
  module Dragoon
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
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-02-02 00:00:00 Z
18
+ date: 2012-02-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec