fantasy-irc 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/Gemfile.lock +29 -0
- data/README.md +5 -2
- data/Rakefile +7 -0
- data/docs/example.rb +3 -5
- data/fantasy-irc.gemspec +3 -3
- data/lib/fantasy-irc/events.rb +10 -14
- data/lib/fantasy-irc/irc.rb +30 -9
- data/lib/fantasy-irc/rooms.rb +5 -2
- data/lib/fantasy-irc/users.rb +6 -0
- data/spec/lib/fantasy-event_spec.rb +31 -0
- data/spec/lib/fantasy-irc_spec.rb +58 -0
- data/spec/spec_helper.rb +1 -0
- metadata +10 -4
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
array-hooked (1.1.4)
|
5
|
+
identifies_as
|
6
|
+
module-cluster
|
7
|
+
array-unique (1.1.1)
|
8
|
+
array-hooked
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
identifies_as (1.1.0)
|
11
|
+
module-cluster (2.0.5)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rspec (2.12.0)
|
14
|
+
rspec-core (~> 2.12.0)
|
15
|
+
rspec-expectations (~> 2.12.0)
|
16
|
+
rspec-mocks (~> 2.12.0)
|
17
|
+
rspec-core (2.12.2)
|
18
|
+
rspec-expectations (2.12.1)
|
19
|
+
diff-lcs (~> 1.1.3)
|
20
|
+
rspec-mocks (2.12.1)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
array-unique (~> 1.1.1)
|
27
|
+
rake
|
28
|
+
rspec
|
29
|
+
rspec-mocks
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# fantasy-irc
|
2
2
|
|
3
|
-
A modular, event-driven IRC client gem
|
3
|
+
A modular, event-driven IRC client/bot Ruby gem with plugin support
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -32,7 +32,6 @@ TLDR:
|
|
32
32
|
Support?
|
33
33
|
|
34
34
|
irc.jdqirc.net #fantasy
|
35
|
-
|
36
35
|
irc://irc.jdqirc.net/fantasy
|
37
36
|
|
38
37
|
## Contributing
|
@@ -43,3 +42,7 @@ Support?
|
|
43
42
|
4. Push to the branch (`git push origin my-new-feature`)
|
44
43
|
5. Create new Pull Request
|
45
44
|
|
45
|
+
|
46
|
+
|
47
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/v2px/fantasy-irc/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
48
|
+
|
data/Rakefile
ADDED
data/docs/example.rb
CHANGED
@@ -9,15 +9,13 @@ bot.plugins.load 'corecommands'
|
|
9
9
|
|
10
10
|
# log in once we are connected
|
11
11
|
connected = Proc.new do
|
12
|
-
bot.login :
|
12
|
+
bot.login nickname: "example", username: "example", realname: "GECOS field"
|
13
13
|
end
|
14
14
|
bot.events.by_name('connected').register &connected
|
15
15
|
|
16
16
|
# join a room and say hi
|
17
17
|
loggedin = Proc.new do
|
18
|
-
|
19
|
-
room = bot.rooms.new(r).join.say "ohai"
|
20
|
-
end
|
18
|
+
bot.rooms.new("#test").join.say "ohai"
|
21
19
|
end
|
22
20
|
bot.events.by_name('loggedin').register &loggedin
|
23
21
|
|
@@ -33,5 +31,5 @@ channel_message = Proc.new do |room, user, text|
|
|
33
31
|
end
|
34
32
|
bot.events.by_name('channel_message').register &channel_message
|
35
33
|
|
36
|
-
bot.connect :
|
34
|
+
bot.connect server: "irc.example.com", ssl: true, port: 6697
|
37
35
|
bot.run
|
data/fantasy-irc.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.authors = ["Jens Becker"]
|
3
3
|
s.email = ["v2px@v2px.de"]
|
4
|
-
s.description = "A modular, event-driven IRC client/bot gem
|
5
|
-
s.summary = "A modular, event-driven IRC client/bot gem
|
4
|
+
s.description = "A modular, event-driven IRC client/bot Ruby gem with plugin support"
|
5
|
+
s.summary = "A modular, event-driven IRC client/bot Ruby gem with plugin support"
|
6
6
|
s.homepage = "http://v2px.github.com/fantasy-irc"
|
7
7
|
|
8
8
|
s.files = `git ls-files`.split("\n")
|
9
9
|
s.name = "fantasy-irc"
|
10
10
|
s.require_paths = ['lib']
|
11
|
-
s.version = "0.1.
|
11
|
+
s.version = "0.1.2"
|
12
12
|
|
13
13
|
s.rubyforge_project = s.name
|
14
14
|
s.add_runtime_dependency "array-unique", "~> 1.1.1"
|
data/lib/fantasy-irc/events.rb
CHANGED
@@ -5,28 +5,28 @@ module Fantasy
|
|
5
5
|
class Factory
|
6
6
|
def initialize
|
7
7
|
puts "Initializing new Event::Factory #{self}"
|
8
|
-
@
|
8
|
+
@events = Hash.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def create name
|
12
12
|
name.downcase!
|
13
13
|
|
14
|
-
if not @
|
15
|
-
return @
|
14
|
+
if not @events[name].nil? then
|
15
|
+
return @events[name]
|
16
16
|
# TODO: log warning
|
17
17
|
end
|
18
18
|
|
19
|
-
@
|
19
|
+
@events[name] = Event.new(name)
|
20
20
|
end
|
21
21
|
|
22
22
|
def by_name name
|
23
23
|
name.downcase!
|
24
24
|
|
25
|
-
if not @
|
25
|
+
if not @events[name] then
|
26
26
|
raise "Tried to access unknown event \"#{name}\" in Event::Factory \"#{self}\""
|
27
27
|
end
|
28
28
|
|
29
|
-
@
|
29
|
+
@events[name]
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -36,26 +36,22 @@ module Fantasy
|
|
36
36
|
def initialize(name)
|
37
37
|
puts "New Event with name #{name}"
|
38
38
|
@name = name
|
39
|
-
@
|
39
|
+
@callbacks = Hash.new
|
40
40
|
end
|
41
41
|
|
42
42
|
def register(&callback)
|
43
43
|
uuid = SecureRandom.uuid()
|
44
44
|
|
45
|
-
|
46
|
-
@data[:callbacks] = Hash.new
|
47
|
-
end
|
48
|
-
|
49
|
-
@data[:callbacks][uuid] = callback
|
45
|
+
@callbacks[uuid] = callback
|
50
46
|
puts "#{self}: registered callback #{callback} with uuid #{uuid}."
|
51
47
|
end
|
52
48
|
|
53
49
|
def call(args=nil)
|
54
|
-
if @
|
50
|
+
if @callbacks.empty? then
|
55
51
|
return
|
56
52
|
end
|
57
53
|
|
58
|
-
@
|
54
|
+
@callbacks.each { |uuid, proc|
|
59
55
|
proc.call(args)
|
60
56
|
}
|
61
57
|
end
|
data/lib/fantasy-irc/irc.rb
CHANGED
@@ -2,11 +2,6 @@ require 'socket' # TCPSocket
|
|
2
2
|
require 'openssl'
|
3
3
|
require 'array-unique'
|
4
4
|
|
5
|
-
#require "fantasy-irc/rooms"
|
6
|
-
#require "fantasy-irc/users"
|
7
|
-
#require "fantasy-irc/events"
|
8
|
-
#require "fantasy-irc/plugins"
|
9
|
-
|
10
5
|
module Fantasy
|
11
6
|
class IRC
|
12
7
|
attr_reader :events, :rooms, :users, :plugins
|
@@ -26,7 +21,7 @@ module Fantasy
|
|
26
21
|
@users = User::Factory.new self
|
27
22
|
@plugins = Plugins.new
|
28
23
|
|
29
|
-
%w{tick loggedin connected user_joined channel_message}.each do |e|
|
24
|
+
%w{tick loggedin connected user_joined user_parted user_quit channel_message}.each do |e|
|
30
25
|
@events.create(e)
|
31
26
|
end
|
32
27
|
end
|
@@ -39,7 +34,7 @@ module Fantasy
|
|
39
34
|
data[:username] = data[:nickname]
|
40
35
|
end
|
41
36
|
if not data[:realname] then
|
42
|
-
data[:realname] = "https://
|
37
|
+
data[:realname] = "https://rubygems.org/gems/fantasy-irc"
|
43
38
|
end
|
44
39
|
|
45
40
|
if not data[:nickname] then
|
@@ -123,8 +118,6 @@ module Fantasy
|
|
123
118
|
self.events.by_name('user_joined').call([room, user])
|
124
119
|
|
125
120
|
elsif (tok[1] == "PRIVMSG") then
|
126
|
-
# tok = s.split(' ', 4)
|
127
|
-
|
128
121
|
# channel or private message
|
129
122
|
if (tok[2][0,1] == "#") then
|
130
123
|
# channel message
|
@@ -146,7 +139,35 @@ module Fantasy
|
|
146
139
|
end
|
147
140
|
end
|
148
141
|
|
142
|
+
elsif (tok[1] == "PART") then
|
143
|
+
# user parted
|
144
|
+
room = self.rooms.by_name(tok[2])
|
145
|
+
user = self.users.create(tok[0][1,tok[0].length])
|
146
|
+
|
147
|
+
# remove user from room and room from user
|
148
|
+
room.users.delete user
|
149
|
+
user.rooms.delete room
|
150
|
+
|
151
|
+
return if user.ignored?
|
152
|
+
|
153
|
+
# TODO part text?
|
154
|
+
self.events.by_name('user_parted').call([room, user])
|
155
|
+
|
156
|
+
elsif (tok[1] == "QUIT") then
|
157
|
+
# user quit
|
158
|
+
user = self.users.create(tok[0][1,tok[0].length])
|
159
|
+
|
160
|
+
puts "!!! user #{user} quit."
|
161
|
+
# remove user from all rooms
|
162
|
+
self.rooms.all.values.each do |room|
|
163
|
+
room.users.delete user
|
164
|
+
end
|
165
|
+
user.reset
|
166
|
+
|
167
|
+
self.events.by_name('user_quit').call([user])
|
168
|
+
|
149
169
|
else
|
170
|
+
|
150
171
|
# puts "[!] UNKNOWN PROTOCOL PART: #{s}"
|
151
172
|
end
|
152
173
|
else
|
data/lib/fantasy-irc/rooms.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
#require "fantasy-irc/connection"
|
2
|
-
|
3
1
|
module Fantasy
|
4
2
|
module Room
|
5
3
|
class Factory
|
@@ -26,10 +24,15 @@ module Fantasy
|
|
26
24
|
|
27
25
|
if not @data[:rooms][name] then
|
28
26
|
raise "Tried to access unknown room \"#{name}\" in Room::Factory \"#{self}\""
|
27
|
+
#TODO: log
|
29
28
|
end
|
30
29
|
|
31
30
|
@data[:rooms][name]
|
32
31
|
end
|
32
|
+
|
33
|
+
def all
|
34
|
+
@data[:rooms]
|
35
|
+
end
|
33
36
|
end
|
34
37
|
|
35
38
|
class Room
|
data/lib/fantasy-irc/users.rb
CHANGED
@@ -48,6 +48,12 @@ module Fantasy
|
|
48
48
|
@rooms = Array::Unique.new
|
49
49
|
end
|
50
50
|
|
51
|
+
# resets user information
|
52
|
+
def reset
|
53
|
+
puts "Resetting user #{self.object_id} with name #{@name}"
|
54
|
+
@rooms = Array::Unique.new
|
55
|
+
end
|
56
|
+
|
51
57
|
def say message
|
52
58
|
@connection.send('PRIVMSG '+@name+' :'+message)
|
53
59
|
return self
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fantasy::Event do
|
4
|
+
describe Fantasy::Event::Event do
|
5
|
+
describe "#new" do
|
6
|
+
it "takes a name as arument and returns a Fantasy::Event::Event object" do
|
7
|
+
e = Fantasy::Event::Event.new("rspec_event")
|
8
|
+
e.should be_an_instance_of Fantasy::Event::Event
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Fantasy::Event::Factory do
|
14
|
+
before :each do
|
15
|
+
@fac = Fantasy::Event::Factory.new
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#new" do
|
19
|
+
it "takes no arguments and returns a Fantasy::Event::Factory object" do
|
20
|
+
@fac.should be_an_instance_of Fantasy::Event::Factory
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "create" do
|
25
|
+
it "takes a name as arument, creates a new event with this name in lowercase and returns it" do
|
26
|
+
event = @fac.create("rspec_event")
|
27
|
+
event.should be_an_instance_of Fantasy::Event::Event
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fantasy::IRC do
|
4
|
+
before :each do
|
5
|
+
@bot = Fantasy::IRC.new
|
6
|
+
|
7
|
+
# stub the send ethod
|
8
|
+
@bot.stub(:send) { }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#new" do
|
12
|
+
it "takes no parameter and returns a Fantasy::IRC object" do
|
13
|
+
@bot.should be_an_instance_of Fantasy::IRC
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "login" do
|
18
|
+
it "takes no arguments and raises an error" do
|
19
|
+
expect { @bot.login }.to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it "takes a nickname as argument and proceeds to log in" do
|
23
|
+
@bot.should_receive(:send).with(/^USER rspec_nick /)
|
24
|
+
@bot.should_receive(:send).with(/^NICK rspec_nick$/)
|
25
|
+
@bot.login(:nickname => 'rspec_nick')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "takes a username as argument and proceeds to log in" do
|
29
|
+
@bot.should_receive(:send).with(/^USER rspec_uname /)
|
30
|
+
@bot.should_receive(:send).with(/^NICK rspec_uname$/)
|
31
|
+
@bot.login(:username => 'rspec_uname')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "takes a username and a nickname as argument and proceeds to log in with both" do
|
35
|
+
@bot.should_receive(:send).with(/^USER rspec_uname /)
|
36
|
+
@bot.should_receive(:send).with(/^NICK rspec_nick$/)
|
37
|
+
@bot.login(:username => 'rspec_uname', :nickname => 'rspec_nick')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "takes a (username and a) realname and sets the realname too" do
|
41
|
+
@bot.should_receive(:send).with(/^USER rspec_uname [^:]+:rspec realname$/)
|
42
|
+
@bot.login(:username => 'rspec_uname', :realname => "rspec realname")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "connect" do
|
47
|
+
it "takes no arguments and raises an error" do
|
48
|
+
expect { @bot.connect }.to raise_error
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "parse" do
|
53
|
+
it "parses at least the PING message" do
|
54
|
+
@bot.should_receive(:send).with(/^PONG :rspec_test$/)
|
55
|
+
@bot.parse("PING :rspec_test")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'fantasy-irc'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fantasy-irc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: array-unique
|
@@ -27,15 +27,18 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.1.1
|
30
|
-
description: A modular, event-driven IRC client/bot gem
|
30
|
+
description: A modular, event-driven IRC client/bot Ruby gem with plugin support
|
31
31
|
email:
|
32
32
|
- v2px@v2px.de
|
33
33
|
executables: []
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
37
39
|
- LICENSE.md
|
38
40
|
- README.md
|
41
|
+
- Rakefile
|
39
42
|
- docs/PLUGINS.md
|
40
43
|
- docs/example.rb
|
41
44
|
- fantasy-irc.gemspec
|
@@ -46,6 +49,9 @@ files:
|
|
46
49
|
- lib/fantasy-irc/rooms.rb
|
47
50
|
- lib/fantasy-irc/users.rb
|
48
51
|
- lib/plugins/corecommands.rb
|
52
|
+
- spec/lib/fantasy-event_spec.rb
|
53
|
+
- spec/lib/fantasy-irc_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
49
55
|
homepage: http://v2px.github.com/fantasy-irc
|
50
56
|
licenses: []
|
51
57
|
post_install_message:
|
@@ -69,5 +75,5 @@ rubyforge_project: fantasy-irc
|
|
69
75
|
rubygems_version: 1.8.25
|
70
76
|
signing_key:
|
71
77
|
specification_version: 3
|
72
|
-
summary: A modular, event-driven IRC client/bot gem
|
78
|
+
summary: A modular, event-driven IRC client/bot Ruby gem with plugin support
|
73
79
|
test_files: []
|