fabriq 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +16 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +20 -0
- data/README.md +7 -0
- data/Rakefile +42 -0
- data/TODO.md +1 -0
- data/VERSION +1 -0
- data/bin/fabriq +4 -0
- data/fabriq.gemspec +79 -0
- data/lib/fabriq.rb +43 -0
- data/lib/fabriq/adapter.rb +95 -0
- data/lib/fabriq/adapter/rype_adapter.rb +49 -0
- data/lib/fabriq/cli.rb +37 -0
- data/lib/fabriq/logging.rb +26 -0
- data/lib/fabriq/plugin_port.rb +60 -0
- data/lib/fabriq/skype.rb +36 -0
- data/lib/fabriq/skype/message.rb +27 -0
- data/lib/fabriq/skype/room.rb +30 -0
- data/lib/fabriq/skype_proxy.rb +83 -0
- data/spec/helper.rb +18 -0
- data/spec/lib/fabriq/adapter_spec.rb +153 -0
- data/spec/lib/fabriq/cli_spec.rb +43 -0
- data/spec/lib/fabriq/config_spec.rb +92 -0
- data/spec/lib/fabriq/logging_spec.rb +33 -0
- data/spec/lib/fabriq/plugin_port_spec.rb +106 -0
- data/spec/lib/fabriq/skype/message_spec.rb +49 -0
- data/spec/lib/fabriq/skype/room_spec.rb +67 -0
- data/spec/lib/fabriq/skype_proxy_spec.rb +167 -0
- data/spec/lib/fabriq/skype_spec.rb +71 -0
- data/spec/lib/fabriq_spec.rb +65 -0
- metadata +146 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ffi (1.0.11)
|
5
|
+
git (1.2.5)
|
6
|
+
guard (1.0.1)
|
7
|
+
ffi (>= 0.5.0)
|
8
|
+
thor (~> 0.14.6)
|
9
|
+
guard-minitest (0.5.0)
|
10
|
+
guard (>= 0.4)
|
11
|
+
jeweler (1.8.3)
|
12
|
+
bundler (~> 1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
rdoc
|
16
|
+
json (1.6.5)
|
17
|
+
metaclass (0.0.1)
|
18
|
+
minitest (2.11.4)
|
19
|
+
mocha (0.10.5)
|
20
|
+
metaclass (~> 0.0.1)
|
21
|
+
rake (0.9.2.2)
|
22
|
+
rb-fsevent (0.9.0)
|
23
|
+
rdoc (3.12)
|
24
|
+
json (~> 1.4)
|
25
|
+
ruby-dbus (0.7.0)
|
26
|
+
ruby_gntp (0.3.4)
|
27
|
+
rype (0.0.4)
|
28
|
+
ruby-dbus (>= 0.6)
|
29
|
+
thor (0.14.6)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
guard-minitest
|
36
|
+
jeweler (~> 1.8.3)
|
37
|
+
minitest
|
38
|
+
mocha
|
39
|
+
rb-fsevent
|
40
|
+
rdoc
|
41
|
+
ruby_gntp
|
42
|
+
rype
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Andreas Wolff
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
require 'rake'
|
6
|
+
require 'jeweler'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rdoc/task'
|
9
|
+
|
10
|
+
begin
|
11
|
+
Bundler.setup(:default, :development)
|
12
|
+
rescue Bundler::BundlerError => e
|
13
|
+
$stderr.puts e.message
|
14
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
15
|
+
exit e.status_code
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :test
|
19
|
+
|
20
|
+
Jeweler::Tasks.new do |gem|
|
21
|
+
gem.name = "fabriq"
|
22
|
+
gem.homepage = "http://github.com/rubyphunk/fabriq"
|
23
|
+
gem.license = "MIT"
|
24
|
+
gem.summary = "A Skype bot fabriqation hall"
|
25
|
+
gem.description = "A daemon that allows you to run Skype bots and give them power through plugins."
|
26
|
+
gem.email = "rubyphunk@gmail.com"
|
27
|
+
gem.authors = ["Andreas Wolff"]
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.pattern = 'spec/**/*_spec.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
38
|
+
rdoc.rdoc_dir = 'rdoc'
|
39
|
+
rdoc.title = "Fabriq #{version}"
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
data/TODO.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# TODO
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/fabriq
ADDED
data/fabriq.gemspec
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "fabriq"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andreas Wolff"]
|
12
|
+
s.date = "2012-04-04"
|
13
|
+
s.description = "A daemon that allows you to run Skype bots and give them power through plugins."
|
14
|
+
s.email = "rubyphunk@gmail.com"
|
15
|
+
s.executables = ["fabriq"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"TODO.md",
|
27
|
+
"VERSION",
|
28
|
+
"bin/fabriq",
|
29
|
+
"fabriq.gemspec",
|
30
|
+
"lib/fabriq.rb",
|
31
|
+
"lib/fabriq/adapter.rb",
|
32
|
+
"lib/fabriq/adapter/rype_adapter.rb",
|
33
|
+
"lib/fabriq/cli.rb",
|
34
|
+
"lib/fabriq/logging.rb",
|
35
|
+
"lib/fabriq/plugin_port.rb",
|
36
|
+
"lib/fabriq/skype.rb",
|
37
|
+
"lib/fabriq/skype/message.rb",
|
38
|
+
"lib/fabriq/skype/room.rb",
|
39
|
+
"lib/fabriq/skype_proxy.rb",
|
40
|
+
"spec/helper.rb",
|
41
|
+
"spec/lib/fabriq/adapter_spec.rb",
|
42
|
+
"spec/lib/fabriq/cli_spec.rb",
|
43
|
+
"spec/lib/fabriq/config_spec.rb",
|
44
|
+
"spec/lib/fabriq/logging_spec.rb",
|
45
|
+
"spec/lib/fabriq/plugin_port_spec.rb",
|
46
|
+
"spec/lib/fabriq/skype/message_spec.rb",
|
47
|
+
"spec/lib/fabriq/skype/room_spec.rb",
|
48
|
+
"spec/lib/fabriq/skype_proxy_spec.rb",
|
49
|
+
"spec/lib/fabriq/skype_spec.rb",
|
50
|
+
"spec/lib/fabriq_spec.rb"
|
51
|
+
]
|
52
|
+
s.homepage = "http://github.com/rubyphunk/fabriq"
|
53
|
+
s.licenses = ["MIT"]
|
54
|
+
s.require_paths = ["lib"]
|
55
|
+
s.rubygems_version = "1.8.21"
|
56
|
+
s.summary = "A Skype bot fabriqation hall"
|
57
|
+
|
58
|
+
if s.respond_to? :specification_version then
|
59
|
+
s.specification_version = 3
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_runtime_dependency(%q<rype>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rype>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
69
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<rype>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
75
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
data/lib/fabriq.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
require_relative 'fabriq/cli'
|
5
|
+
require_relative 'fabriq/logging'
|
6
|
+
require_relative 'fabriq/adapter'
|
7
|
+
require_relative 'fabriq/config'
|
8
|
+
require_relative 'fabriq/plugin_port'
|
9
|
+
require_relative 'fabriq/skype'
|
10
|
+
require_relative 'fabriq/skype_proxy'
|
11
|
+
|
12
|
+
module Fabriq
|
13
|
+
extend self
|
14
|
+
|
15
|
+
def root
|
16
|
+
Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), "..")))
|
17
|
+
end
|
18
|
+
|
19
|
+
def config(&block)
|
20
|
+
yield Fabriq::Config
|
21
|
+
end
|
22
|
+
|
23
|
+
def boot
|
24
|
+
Fabriq::Config.load
|
25
|
+
Fabriq::Adapter.load
|
26
|
+
Fabriq::Adapter.run { load_environment }
|
27
|
+
end
|
28
|
+
|
29
|
+
def argv
|
30
|
+
ARGV
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_environment
|
34
|
+
if self.argv.size > 0
|
35
|
+
Fabriq::CLI.run(self.argv)
|
36
|
+
else
|
37
|
+
Fabriq::PluginPort.initialize_plugins
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Empty namespace for plugins
|
43
|
+
module Plugins; end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require_relative 'adapter/rype_adapter'
|
2
|
+
|
3
|
+
module Fabriq
|
4
|
+
module Adapter
|
5
|
+
extend self
|
6
|
+
|
7
|
+
attr_accessor :adapter, :proxy, :rooms
|
8
|
+
attr_accessor :skype_proxy_class
|
9
|
+
|
10
|
+
def skype_proxy_class
|
11
|
+
@skype_proxy_class || Fabriq::SkypeProxy
|
12
|
+
end
|
13
|
+
|
14
|
+
def load
|
15
|
+
@adapter = Fabriq::Config.adapter.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(&block)
|
19
|
+
init_skype_proxy
|
20
|
+
self.adapter.attach
|
21
|
+
find_available_rooms do |rooms|
|
22
|
+
@rooms = rooms
|
23
|
+
block.call if block_given?
|
24
|
+
end
|
25
|
+
self.adapter.wait
|
26
|
+
end
|
27
|
+
|
28
|
+
def init_skype_proxy
|
29
|
+
self.proxy = skype_proxy_class.new(self)
|
30
|
+
self.proxy.start
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_skype_room_by_id(room_id)
|
34
|
+
@rooms.each do |room|
|
35
|
+
return room if room.id == room_id
|
36
|
+
end
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def enqueue_outgoing_message(message)
|
41
|
+
self.proxy.outgoing_messages << message
|
42
|
+
end
|
43
|
+
|
44
|
+
def subscribe_to_incoming_messages(&block)
|
45
|
+
self.proxy.on_incoming_message(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def message_received(&block)
|
49
|
+
self.adapter.message_received do |raw_message|
|
50
|
+
skype_room = find_skype_room_by_id(raw_message[:room_id])
|
51
|
+
block.call(build_skype_message(skype_room, raw_message)) if block_given?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def send_message(message)
|
56
|
+
self.adapter.send_message(message.room.raw, message.body)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def find_available_rooms(&block)
|
63
|
+
self.adapter.available_rooms do |available_rooms|
|
64
|
+
recursively_load_rooms(available_rooms) do |rooms|
|
65
|
+
yield rooms
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def recursively_load_rooms(rooms, loaded_rooms = [], &block)
|
71
|
+
if rooms.length == 0
|
72
|
+
yield loaded_rooms
|
73
|
+
else
|
74
|
+
adapter_room = rooms.shift
|
75
|
+
self.adapter.load_room_information(adapter_room) do |loaded_room|
|
76
|
+
loaded_rooms << build_skype_room(loaded_room)
|
77
|
+
recursively_load_rooms(rooms, loaded_rooms, &block)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_skype_room(raw_room_information)
|
83
|
+
Fabriq::Skype::Room.new(self, raw_room_information[:id], raw_room_information[:members], raw_room_information[:raw]).tap do |room|
|
84
|
+
room.topic = raw_room_information[:topic]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def build_skype_message(skype_room, raw_message_information)
|
89
|
+
Fabriq::Skype::Message.new(skype_room, raw_message_information[:body]).tap do |message|
|
90
|
+
message.from_name = raw_message_information[:from_name]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rype'
|
2
|
+
|
3
|
+
module Fabriq
|
4
|
+
module Adapter
|
5
|
+
|
6
|
+
class RypeAdapter
|
7
|
+
|
8
|
+
def attach(&block)
|
9
|
+
::Rype.attach
|
10
|
+
end
|
11
|
+
|
12
|
+
def wait
|
13
|
+
::Rype.thread.join
|
14
|
+
end
|
15
|
+
|
16
|
+
def message_received(&block)
|
17
|
+
Rype.on(:chatmessage_received) do |chatmessage|
|
18
|
+
chatmessage.chat do |chat|
|
19
|
+
chatmessage.body do |body|
|
20
|
+
chatmessage.from_name do |from_name|
|
21
|
+
Thread.new { yield({ from_name: from_name, body: body, room_id: chat.chatname }) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def send_message(chat, body)
|
29
|
+
chat.send_message(body)
|
30
|
+
end
|
31
|
+
|
32
|
+
def available_rooms(&block)
|
33
|
+
Rype::Chat.all do |chats|
|
34
|
+
yield chats
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_room_information(room, &block)
|
39
|
+
room.topic do |topic|
|
40
|
+
room.members do |members|
|
41
|
+
yield({ topic: topic, id: room.chatname, members: members, raw: room })
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/fabriq/cli.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Fabriq
|
2
|
+
module CLI
|
3
|
+
extend self
|
4
|
+
|
5
|
+
attr_accessor :skype
|
6
|
+
|
7
|
+
def skype
|
8
|
+
@skype || Fabriq::Skype
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(args)
|
12
|
+
case args.first
|
13
|
+
when "rooms"
|
14
|
+
list_available_rooms
|
15
|
+
end
|
16
|
+
|
17
|
+
exit(0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_available_rooms
|
21
|
+
cli_out "\n*** Available Rooms: ***\n"
|
22
|
+
|
23
|
+
skype.rooms.each do |room|
|
24
|
+
topic = room.topic == "" ? "<not set>" : room.topic
|
25
|
+
cli_out "* ID: %s\t Topic: %s" % [room.id, topic]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def cli_out(msg)
|
33
|
+
puts msg
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|