dragoon 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in ..gemspec
4
3
  gemspec
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Dragoon
2
2
  ============
3
3
 
4
- An IRC bot that notifies you of keyword occurences in your favorite chatrooms. You can listen to multiple channels but right now, i've only tested it on freenode.net. Support for multiple networks will be done soon.
4
+ An IRC bot that alerts you whenever certain keywords pop up in your favorite channels. You can listen to multiple channels but right now, you can only connect to one network at a time. And I've only tested it on freenode.net. Support for multiple networks will be done soon.
5
5
 
6
6
 
7
7
  Dependencies
@@ -15,13 +15,19 @@ P.S. You can still run the program even without growl, you'll only see the keywo
15
15
  Usage
16
16
  -----
17
17
 
18
- 1. `git clone git://github.com/redgetan/dragoon.git`
19
- 2. Create a configuration file under config/ directory and name it "config.yml". See "config.yml.example" for reference.
20
- 3. If you have growl support, make sure it's turned on
21
- 4. To start the program, type `./bin/dragoon`
18
+ gem install dragoon
19
+
20
+ dragoon
21
+
22
+ Once you run dragoon, A default config file would be created under your home directory called .dragoon if it doesnt exist. You will have to edit it accordingly. Once the file exists, the program will automatically load the config file on startup.
23
+
24
+ If you have growl support, make sure it's turned on
22
25
 
23
- P.S. will gemify this soon so you only have to do 'gem install dragoon', then 'dragoon'
24
26
 
25
27
  Screenshot
26
28
  ---------
27
29
  http://farm8.staticflickr.com/7027/6733543233_6f354d61d0_b.jpg
30
+
31
+ Questions and Feedback
32
+ ---------
33
+ I would love to hear any suggestions for improvement. You can email me at redge.tan@gmail.com. I'm also looking for mentors that can help me improve as a software developer. if you're interested in helping me, I'd love to hear from you.
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_development_dependency "rspec"
22
- s.add_runtime_dependency "term/ansicolor"
22
+ s.add_dependency "term-ansicolor"
23
23
  end
@@ -1,7 +1,7 @@
1
1
  require 'socket'
2
2
  require 'ostruct'
3
3
  require 'forwardable'
4
- require 'yaml'
4
+ require 'json'
5
5
 
6
6
  require 'term/ansicolor'
7
7
 
@@ -19,11 +19,12 @@ module Dragoon
19
19
  include Commands
20
20
  include Color
21
21
 
22
- attr_accessor :nickname, :networks, :channels, :keywords
22
+ attr_accessor :nickname, :network, :channels, :keywords
23
23
 
24
24
  def_delegators :@event_manager, :on, :dispatch
25
25
 
26
26
  DEFAULT_PORT = 6667
27
+ CONFIG_FILE = File.expand_path("~/.dragoon")
27
28
 
28
29
  def initialize(&blk)
29
30
  @event_manager = EventManager.new
@@ -33,13 +34,27 @@ module Dragoon
33
34
 
34
35
  def load_config
35
36
  begin
36
- config = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "./../config/config.yml")))
37
+ if File.exist?(CONFIG_FILE)
38
+ puts("*** Loading config file ~/.dragoon")
39
+ config = JSON.parse(File.read(CONFIG_FILE))
40
+ else
41
+ config = {
42
+ "nickname" => "your_nick",
43
+ "network" => "irc.freenode.net",
44
+ "channels" => %w[ #ubuntu #ruby #rubyonrails #linux #programming #javascript ],
45
+ "keywords" => %w[ and how who ]
46
+ }
47
+ 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)
49
+ puts("Please modify it according to your preference".red)
50
+ exit 1
51
+ end
37
52
  rescue => e
38
53
  $stderr.puts e.message
39
54
  exit 1
40
55
  end
41
56
  @nickname = config["nickname"]
42
- @networks = config["networks"]
57
+ @network = config["network"]
43
58
  @channels = config["channels"]
44
59
  @keywords = config["keywords"]
45
60
  end
@@ -59,7 +74,7 @@ module Dragoon
59
74
  end
60
75
 
61
76
  on :mode do |msg|
62
- puts "*** Logged in as #{@nickname}"
77
+ puts "*** Logged in as #{self.nickname}"
63
78
  join_channels
64
79
  end
65
80
 
@@ -68,7 +83,13 @@ module Dragoon
68
83
  end
69
84
 
70
85
  on :err do |msg|
71
- puts "err: #{msg.text}" unless msg.error_code == '470' # channel forwarding
86
+ $stderr.puts msg.text.red unless msg.error_code == '470' # channel forwarding
87
+ if msg.error_code == '433' # nick already in use
88
+ print("Enter another nickname: ")
89
+ self.nickname = gets.chomp
90
+ user(self.nickname)
91
+ nick(self.nickname)
92
+ end
72
93
  end
73
94
 
74
95
  on :privmsg do |msg|
@@ -86,20 +107,28 @@ module Dragoon
86
107
  def run
87
108
  @socket = connect
88
109
  while line = @socket.gets
110
+ trap('INT') { stop }
89
111
  @event = Event.parse(line)
90
112
  dispatch(@event)
91
113
  end
92
114
  end
93
115
 
94
116
  def connect
95
- puts "*** Connecting to #{@networks.first} on port #{DEFAULT_PORT}"
96
- TCPSocket.new(@networks.first, DEFAULT_PORT)
117
+ puts "*** Connecting to #{@network} on port #{DEFAULT_PORT}"
118
+ TCPSocket.new(@network, DEFAULT_PORT)
97
119
  end
98
120
 
99
121
  def escape_double_quotes(text)
100
122
  text.gsub("\"", "\\\"")
101
123
  end
102
124
 
125
+ def stop
126
+ @socket.close
127
+ puts
128
+ puts "*** Program stopped"
129
+ exit
130
+ end
131
+
103
132
  end
104
133
  end
105
134
 
@@ -24,6 +24,7 @@ module Dragoon
24
24
  private
25
25
 
26
26
  def write(text)
27
+ $stdout.puts text
27
28
  @socket.write "#{text}\r\n"
28
29
  end
29
30
 
@@ -1,3 +1,3 @@
1
1
  module Dragoon
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
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-22 00:00:00 Z
18
+ date: 2012-01-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -32,7 +32,7 @@ dependencies:
32
32
  type: :development
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: term/ansicolor
35
+ name: term-ansicolor
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
@@ -62,8 +62,6 @@ files:
62
62
  - Rakefile
63
63
  - TODO
64
64
  - bin/dragoon
65
- - config/config.yml
66
- - config/config.yml.example
67
65
  - dragoon.gemspec
68
66
  - lib/dragoon.rb
69
67
  - lib/dragoon/color.rb
@@ -1,4 +0,0 @@
1
- nickname: fenix45
2
- networks: [ irc.freenode.net ]
3
- channels: [ '#ubuntu', '#ruby', '#rubyonrails', '#linux', '#javascript', '#programming' ]
4
- keywords: [ why, how, who, and ]
@@ -1,4 +0,0 @@
1
- nickname: fenix45
2
- networks: [ irc.freenode.net ]
3
- channels: [ '#ubuntu', '#ruby', '#rubyonrails', '#linux', '#javascript', '#programming' ]
4
- keywords: [ why, how, who, and ]