dragoon 0.0.4 → 0.0.5
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/TODO +12 -0
- data/lib/dragoon.rb +34 -15
- data/lib/dragoon/commands.rb +12 -8
- data/lib/dragoon/version.rb +1 -1
- data/spec/event_spec.rb +4 -4
- metadata +5 -5
data/TODO
CHANGED
@@ -8,6 +8,9 @@ TODO
|
|
8
8
|
- [ ] - multiple networks
|
9
9
|
- [x] login
|
10
10
|
- [x] join channels
|
11
|
+
- [x] - normal channels
|
12
|
+
- [ ] - channels that need you to be identified with nickserv
|
13
|
+
- [ ] - more than 50 channels
|
11
14
|
- [x] Event Parsing
|
12
15
|
- [x] during msg events (PRIVMSG)
|
13
16
|
- [x] - parse message
|
@@ -41,8 +44,17 @@ Helpful links
|
|
41
44
|
- http://www.scribd.com/doc/28253878/EventMachine-scalable-non-blocking-i-o-in-ruby
|
42
45
|
- http://www.paperplanes.de/2011/4/25/eventmachine-how-does-it-work.html (EM vs lower level socket prog, ie select, poll)
|
43
46
|
- http://cia.vc/doc/
|
47
|
+
- https://www6.software.ibm.com/developerworks/education/l-rubysocks/l-rubysocks-a4.pdf
|
48
|
+
|
49
|
+
Ncurses
|
50
|
+
|
51
|
+
- http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/pdf/NCURSES-Programming-HOWTO.pdf
|
52
|
+
- http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/Curses.pdf
|
53
|
+
- http://invisible-island.net/ncurses/ncurses-intro.html
|
54
|
+
|
44
55
|
|
45
56
|
Existing IRC clients/bots to get ideas from
|
46
57
|
-------------------------------------------
|
47
58
|
- https://github.com/cinchrb/cinch
|
48
59
|
- https://github.com/RISCFuture/autumn
|
60
|
+
|
data/lib/dragoon.rb
CHANGED
@@ -38,17 +38,34 @@ module Dragoon
|
|
38
38
|
puts("*** Loading config file #{CONFIG_FILE}")
|
39
39
|
config = JSON.parse(File.read(CONFIG_FILE))
|
40
40
|
@nickname = config["nickname"]
|
41
|
+
@password = config["password"]
|
41
42
|
@network = config["network"]
|
42
43
|
@channels = config["channels"]
|
43
44
|
@keywords = config["keywords"]
|
44
45
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
"
|
49
|
-
"
|
46
|
+
|
47
|
+
config = (<<-EOF).gsub(/^\s{10}/,"")
|
48
|
+
{
|
49
|
+
"nickname": "fenix#{rand(10)}#{rand(10)}#{rand(10)}",
|
50
|
+
"password": "",
|
51
|
+
"network": "chat.freenode.net",
|
52
|
+
"channels": [
|
53
|
+
"#ubuntu",
|
54
|
+
"#ruby",
|
55
|
+
"#rubyonrails",
|
56
|
+
"#linux",
|
57
|
+
"#programming",
|
58
|
+
"#javascript"
|
59
|
+
],
|
60
|
+
"keywords": [
|
61
|
+
"and",
|
62
|
+
"how",
|
63
|
+
"who"
|
64
|
+
]
|
50
65
|
}
|
51
|
-
|
66
|
+
EOF
|
67
|
+
|
68
|
+
File.open(CONFIG_FILE,'w+') {|f| f.write(config) }
|
52
69
|
puts("Config file does not exist...created a default one at #{CONFIG_FILE}".red)
|
53
70
|
puts("Please modify it according to your preference".red)
|
54
71
|
exit 1
|
@@ -64,8 +81,9 @@ module Dragoon
|
|
64
81
|
puts msg.text
|
65
82
|
if msg.text =~ /.*Found your hostname.*/
|
66
83
|
# login
|
67
|
-
|
68
|
-
|
84
|
+
pass(@password) if !@password.empty?
|
85
|
+
user(@nickname, 0, 0, @nickname)
|
86
|
+
nick(@nickname)
|
69
87
|
end
|
70
88
|
end
|
71
89
|
|
@@ -79,35 +97,36 @@ module Dragoon
|
|
79
97
|
end
|
80
98
|
|
81
99
|
on :join do |msg|
|
82
|
-
puts "*** Listening on channel #{colorize(msg.channel)}" if
|
100
|
+
puts "*** Listening on channel #{colorize(msg.channel)}" if @nickname == msg.nickname
|
83
101
|
end
|
84
102
|
|
85
103
|
on :err do |msg|
|
86
104
|
$stderr.puts msg.text.red unless msg.error_code == '470' # channel forwarding
|
87
105
|
if msg.error_code == '433' # nick already in use
|
88
106
|
print("Enter another nickname: ")
|
89
|
-
|
90
|
-
user(
|
91
|
-
nick(
|
107
|
+
@nickname = gets.chomp
|
108
|
+
user(@nickname, 0, 0, @nickname)
|
109
|
+
nick(@nickname)
|
92
110
|
end
|
93
111
|
end
|
94
112
|
|
95
113
|
on :privmsg do |msg|
|
96
114
|
if system("which growlnotify > /dev/null")
|
97
|
-
if keyword =
|
115
|
+
if keyword = @keywords.detect { |keyword| msg.text.include?(keyword) }
|
98
116
|
system("growlnotify " +
|
99
117
|
"-t \"#{msg.channel} - #{keyword}\" " +
|
100
118
|
"-m \"#{escape_double_quotes(msg.privmsg)}\"")
|
101
119
|
end
|
102
120
|
end
|
103
|
-
puts "#{colorize(msg.channel)} <#{msg.nickname}> #{highlight_keywords(msg.privmsg
|
121
|
+
puts "#{colorize(msg.channel)} <#{msg.nickname}> #{highlight_keywords(msg.privmsg,@keywords)}"
|
104
122
|
end
|
105
123
|
end
|
106
124
|
|
107
125
|
def run
|
126
|
+
trap("INT") { stop}
|
108
127
|
@socket = connect
|
128
|
+
|
109
129
|
while line = @socket.gets
|
110
|
-
trap('INT') { stop }
|
111
130
|
@event = Event.parse(line)
|
112
131
|
dispatch(@event)
|
113
132
|
end
|
data/lib/dragoon/commands.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
module Dragoon
|
2
2
|
module Commands
|
3
3
|
|
4
|
-
def nick(
|
5
|
-
write "NICK #{
|
4
|
+
def nick(nickname)
|
5
|
+
write "NICK #{nickname}"
|
6
6
|
end
|
7
7
|
|
8
|
-
def user(
|
9
|
-
write "USER #{
|
8
|
+
def user(username, hostname, servername, realname)
|
9
|
+
write "USER #{username} #{hostname} #{servername} #{realname}"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
write "
|
12
|
+
def pass(password)
|
13
|
+
write "PASS #{password}"
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
write "
|
16
|
+
def pong(server)
|
17
|
+
write "PONG #{server}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def join(channel)
|
21
|
+
write "JOIN #{channel}"
|
18
22
|
end
|
19
23
|
|
20
24
|
def join_channels
|
data/lib/dragoon/version.rb
CHANGED
data/spec/event_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe Dragoon::Event do
|
|
14
14
|
msg = "PING :zelazny.freenode.net"
|
15
15
|
event = Dragoon::Event.parse(msg)
|
16
16
|
event.name.should == :ping
|
17
|
-
event.message.text.should ==
|
17
|
+
event.message.text.should == msg
|
18
18
|
event.message.server.should == "zelazny.freenode.net"
|
19
19
|
end
|
20
20
|
|
@@ -22,7 +22,7 @@ describe Dragoon::Event do
|
|
22
22
|
msg = ":favor212 MODE favor212 :+i"
|
23
23
|
event = Dragoon::Event.parse(msg)
|
24
24
|
event.name.should == :mode
|
25
|
-
event.message.text.should ==
|
25
|
+
event.message.text.should == msg
|
26
26
|
event.message.nickname.should == "favor212"
|
27
27
|
end
|
28
28
|
|
@@ -30,7 +30,7 @@ describe Dragoon::Event do
|
|
30
30
|
msg = ":zigcat_Fox!~zigcat_fox@hostname JOIN #time_to_show_off"
|
31
31
|
event = Dragoon::Event.parse(msg)
|
32
32
|
event.name.should == :join
|
33
|
-
event.message.text.should ==
|
33
|
+
event.message.text.should == msg
|
34
34
|
event.message.nickname.should == "zigcat_Fox"
|
35
35
|
event.message.user.should == "~zigcat_fox"
|
36
36
|
event.message.hostname.should == "hostname"
|
@@ -41,7 +41,7 @@ describe Dragoon::Event do
|
|
41
41
|
msg = ":nick!~user@hostname PRIVMSG #ruby :array << 0 if array.size.odd?"
|
42
42
|
event = Dragoon::Event.parse(msg)
|
43
43
|
event.name.should == :privmsg
|
44
|
-
event.message.text.should ==
|
44
|
+
event.message.text.should == msg
|
45
45
|
event.message.nickname.should == "nick"
|
46
46
|
event.message.user.should == "~user"
|
47
47
|
event.message.hostname.should == "hostname"
|
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
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-02-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
requirements: []
|
118
118
|
|
119
119
|
rubyforge_project: dragoon
|
120
|
-
rubygems_version: 1.8.
|
120
|
+
rubygems_version: 1.8.15
|
121
121
|
signing_key:
|
122
122
|
specification_version: 3
|
123
123
|
summary: IRC bot for keyword notification
|