fbomb 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +93 -0
- data/README.md +130 -0
- data/Rakefile +41 -9
- data/bin/fbomb +226 -31
- data/fbomb.gemspec +51 -8
- data/images/planet/1dEzGbz.jpg +0 -0
- data/images/planet/3aASzbv.jpg +0 -0
- data/images/planet/BCfEwgl.jpg +0 -0
- data/images/planet/EPbgqjy.jpg +0 -0
- data/images/planet/FoiDgwc.jpg +0 -0
- data/images/planet/HJiUPV2.jpg +0 -0
- data/images/planet/KOcvGjw.jpg +0 -0
- data/images/planet/L5n5lPK.jpg +0 -0
- data/images/planet/MaGKipv.jpg +0 -0
- data/images/planet/QVRALtz.jpg +0 -0
- data/images/planet/W3fWkTZ.jpg +0 -0
- data/images/planet/about.md +1 -0
- data/images/planet/nWqdkF7.jpg +0 -0
- data/images/planet/w41sv1T.jpg +0 -0
- data/images/planet/xySa4GD.jpg +0 -0
- data/images/planet/yzw8pOQ.jpg +0 -0
- data/lib/fbomb.rb +99 -19
- data/lib/fbomb/campfire.rb +39 -11
- data/lib/fbomb/command.rb +52 -15
- data/lib/fbomb/commands/builtin.rb +720 -9
- data/lib/fbomb/commands/system.rb +52 -10
- data/lib/fbomb/flowdock.rb +307 -0
- data/lib/fbomb/util.rb +65 -0
- data/lib/fbomb/uuid.rb +312 -0
- data/notes/ara.txt +54 -0
- metadata +229 -113
- data/README +0 -20
data/fbomb.gemspec
CHANGED
@@ -3,17 +3,38 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "fbomb"
|
6
|
-
spec.version = "
|
6
|
+
spec.version = "2.0.0"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "fbomb"
|
9
9
|
spec.description = "description: fbomb kicks the ass"
|
10
|
+
spec.license = "Ruby"
|
10
11
|
|
11
12
|
spec.files =
|
12
|
-
["
|
13
|
+
["Gemfile",
|
14
|
+
"Gemfile.lock",
|
15
|
+
"README.md",
|
13
16
|
"Rakefile",
|
14
17
|
"bin",
|
15
18
|
"bin/fbomb",
|
16
19
|
"fbomb.gemspec",
|
20
|
+
"images",
|
21
|
+
"images/planet",
|
22
|
+
"images/planet/1dEzGbz.jpg",
|
23
|
+
"images/planet/3aASzbv.jpg",
|
24
|
+
"images/planet/BCfEwgl.jpg",
|
25
|
+
"images/planet/EPbgqjy.jpg",
|
26
|
+
"images/planet/FoiDgwc.jpg",
|
27
|
+
"images/planet/HJiUPV2.jpg",
|
28
|
+
"images/planet/KOcvGjw.jpg",
|
29
|
+
"images/planet/L5n5lPK.jpg",
|
30
|
+
"images/planet/MaGKipv.jpg",
|
31
|
+
"images/planet/QVRALtz.jpg",
|
32
|
+
"images/planet/W3fWkTZ.jpg",
|
33
|
+
"images/planet/about.md",
|
34
|
+
"images/planet/nWqdkF7.jpg",
|
35
|
+
"images/planet/w41sv1T.jpg",
|
36
|
+
"images/planet/xySa4GD.jpg",
|
37
|
+
"images/planet/yzw8pOQ.jpg",
|
17
38
|
"lib",
|
18
39
|
"lib/fbomb",
|
19
40
|
"lib/fbomb.rb",
|
@@ -22,7 +43,11 @@ Gem::Specification::new do |spec|
|
|
22
43
|
"lib/fbomb/commands",
|
23
44
|
"lib/fbomb/commands/builtin.rb",
|
24
45
|
"lib/fbomb/commands/system.rb",
|
25
|
-
"lib/fbomb/
|
46
|
+
"lib/fbomb/flowdock.rb",
|
47
|
+
"lib/fbomb/util.rb",
|
48
|
+
"lib/fbomb/uuid.rb",
|
49
|
+
"notes",
|
50
|
+
"notes/ara.txt"]
|
26
51
|
|
27
52
|
spec.executables = ["fbomb"]
|
28
53
|
|
@@ -31,15 +56,33 @@ Gem::Specification::new do |spec|
|
|
31
56
|
spec.test_files = nil
|
32
57
|
|
33
58
|
|
34
|
-
spec.add_dependency(*["
|
59
|
+
spec.add_dependency(*["flowdock", ">= 0.4.0"])
|
35
60
|
|
36
|
-
spec.add_dependency(*["
|
61
|
+
spec.add_dependency(*["eventmachine", ">= 1.0.3"])
|
37
62
|
|
38
|
-
spec.add_dependency(*["
|
63
|
+
spec.add_dependency(*["em-http-request", ">= 1.1.2"])
|
39
64
|
|
40
|
-
spec.add_dependency(*["
|
65
|
+
spec.add_dependency(*["json", ">= 1.8.1"])
|
41
66
|
|
42
|
-
spec.add_dependency(*["
|
67
|
+
spec.add_dependency(*["coerce", ">= 0.0.6"])
|
68
|
+
|
69
|
+
spec.add_dependency(*["fukung", ">= 1.1.0"])
|
70
|
+
|
71
|
+
spec.add_dependency(*["main", ">= 4.7.6"])
|
72
|
+
|
73
|
+
spec.add_dependency(*["nokogiri", ">= 1.5.0"])
|
74
|
+
|
75
|
+
spec.add_dependency(*["google-search", ">= 1.0.2"])
|
76
|
+
|
77
|
+
spec.add_dependency(*["unidecode", ">= 1.0.0"])
|
78
|
+
|
79
|
+
spec.add_dependency(*["systemu", ">= 2.3.0"])
|
80
|
+
|
81
|
+
spec.add_dependency(*["pry", ">= 0.9.6.2"])
|
82
|
+
|
83
|
+
spec.add_dependency(*["mechanize", ">= 2.7.3"])
|
84
|
+
|
85
|
+
spec.add_dependency(*["mime-types", ">= 1.16"])
|
43
86
|
|
44
87
|
|
45
88
|
spec.extensions.push(*[])
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
http://imgur.com/a/Ilw2G
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/fbomb.rb
CHANGED
@@ -5,11 +5,14 @@
|
|
5
5
|
require 'net/http'
|
6
6
|
require 'net/https'
|
7
7
|
require 'open-uri'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'tmpdir'
|
10
|
+
require 'yaml'
|
8
11
|
|
9
12
|
# libs
|
10
13
|
#
|
11
14
|
module FBomb
|
12
|
-
Version = '
|
15
|
+
Version = '2.0.0' unless defined?(Version)
|
13
16
|
|
14
17
|
def version
|
15
18
|
FBomb::Version
|
@@ -17,11 +20,20 @@
|
|
17
20
|
|
18
21
|
def dependencies
|
19
22
|
{
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
23
|
+
'flowdock' => [ 'flowdock' , '>= 0.4.0' ] ,
|
24
|
+
'eventmachine' => [ 'eventmachine' , '>= 1.0.3' ] ,
|
25
|
+
'em-http' => [ 'em-http-request' , '>= 1.1.2' ] ,
|
26
|
+
'json' => [ 'json' , '>= 1.8.1' ] ,
|
27
|
+
'coerce' => [ 'coerce' , '>= 0.0.6' ] ,
|
28
|
+
'fukung' => [ 'fukung' , '>= 1.1.0' ] ,
|
29
|
+
'main' => [ 'main' , '>= 4.7.6' ] ,
|
30
|
+
'nokogiri' => [ 'nokogiri' , '>= 1.5.0' ] ,
|
31
|
+
'google-search' => [ 'google-search' , '>= 1.0.2' ] ,
|
32
|
+
'unidecode' => [ 'unidecode' , '>= 1.0.0' ] ,
|
33
|
+
'systemu' => [ 'systemu' , '>= 2.3.0' ] ,
|
34
|
+
'pry' => [ 'pry' , '>= 0.9.6.2' ] ,
|
35
|
+
'mechanize' => [ 'mechanize' , '>= 2.7.3' ] ,
|
36
|
+
'mime/types' => [ 'mime-types' , '>= 1.16' ]
|
25
37
|
}
|
26
38
|
end
|
27
39
|
|
@@ -44,39 +56,103 @@
|
|
44
56
|
FBomb.libdir{ libs.each{|lib| Kernel.load(lib) } }
|
45
57
|
end
|
46
58
|
|
59
|
+
def messages
|
60
|
+
@messages ||= Array.new
|
61
|
+
end
|
62
|
+
|
63
|
+
def leader
|
64
|
+
'.'
|
65
|
+
end
|
66
|
+
|
67
|
+
def uuid
|
68
|
+
UUID.create.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_accessor :message
|
72
|
+
attr_accessor :debug
|
73
|
+
|
47
74
|
extend(FBomb)
|
48
75
|
end
|
49
76
|
|
50
|
-
|
77
|
+
## isolate gems
|
51
78
|
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
79
|
+
require 'rubygems'
|
80
|
+
|
81
|
+
libdir = File.expand_path(File.join('~', '.fbomb', 'isolate'))
|
82
|
+
options = {:file => false, :path => libdir}
|
83
|
+
|
84
|
+
deps = true
|
85
|
+
::FBomb.dependencies.each do |lib, dependency|
|
86
|
+
unless Gem.try_activate(dependency.first)
|
87
|
+
deps = false
|
88
|
+
lib, version = dependency
|
89
|
+
command = "gem install #{ lib.inspect } --version #{ version.inspect }"
|
90
|
+
#STDERR.puts(command)
|
91
|
+
end
|
56
92
|
end
|
57
93
|
|
58
|
-
|
59
|
-
|
94
|
+
::FBomb.dependencies.each do |lib, dependency|
|
95
|
+
begin
|
60
96
|
gem(*dependency)
|
61
|
-
|
97
|
+
rescue Gem::LoadError
|
98
|
+
raise
|
99
|
+
lib, version = dependency
|
100
|
+
command = "gem install #{ lib.inspect } --version #{ version.inspect }"
|
101
|
+
system(command)
|
102
|
+
retry
|
62
103
|
end
|
63
104
|
end
|
64
105
|
|
65
|
-
|
66
|
-
|
106
|
+
## load gems
|
107
|
+
#
|
108
|
+
::FBomb.dependencies.each do |lib, dependency|
|
109
|
+
require(lib)
|
110
|
+
end
|
67
111
|
|
112
|
+
## load fbomb
|
113
|
+
#
|
68
114
|
FBomb.load %w[
|
69
115
|
util.rb
|
70
|
-
|
116
|
+
flowdock.rb
|
71
117
|
command.rb
|
118
|
+
uuid.rb
|
72
119
|
]
|
73
120
|
|
121
|
+
##
|
122
|
+
#
|
123
|
+
if Coerce.boolean(ENV['FBOMB_DEBUG'])
|
124
|
+
FBomb.debug = true
|
125
|
+
end
|
126
|
+
|
74
127
|
## openssl - STFU!
|
75
128
|
#
|
129
|
+
verbose = $VERBOSE
|
130
|
+
begin
|
131
|
+
require 'openssl'
|
132
|
+
$VERBOSE = nil
|
133
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
134
|
+
rescue Object => e
|
135
|
+
:STFU
|
136
|
+
ensure
|
137
|
+
$VERBOSE = verbose
|
138
|
+
end
|
139
|
+
|
76
140
|
class Net::HTTP
|
77
|
-
|
78
|
-
|
141
|
+
require 'net/https'
|
142
|
+
|
143
|
+
module STFU
|
144
|
+
def warn(msg)
|
145
|
+
#Kernel.warn(msg) unless msg == "warning: peer certificate won't be verified in this SSL session"
|
146
|
+
end
|
147
|
+
|
148
|
+
def use_ssl=(flag)
|
149
|
+
super
|
150
|
+
ensure
|
151
|
+
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
152
|
+
end
|
79
153
|
end
|
154
|
+
|
155
|
+
include(STFU)
|
80
156
|
end
|
81
157
|
|
82
158
|
## global DSL hook
|
@@ -84,3 +160,7 @@
|
|
84
160
|
def FBomb(*args, &block)
|
85
161
|
FBomb::Command::DSL.evaluate(*args, &block)
|
86
162
|
end
|
163
|
+
|
164
|
+
##
|
165
|
+
#
|
166
|
+
Fbomb=FBomb
|
data/lib/fbomb/campfire.rb
CHANGED
@@ -2,10 +2,10 @@ module FBomb
|
|
2
2
|
class Campfire < ::Tinder::Campfire
|
3
3
|
module SearchExtension
|
4
4
|
def search(term)
|
5
|
-
|
5
|
+
flow = self
|
6
6
|
term = CGI.escape(term.to_s)
|
7
|
-
|
8
|
-
messages = connection.get("/search?term=#{ term }&
|
7
|
+
return_to_flow_id = CGI.escape(flow.id.to_s)
|
8
|
+
messages = connection.get("/search?term=#{ term }&return_to_flow_id=#{ return_to_flow_id }")
|
9
9
|
if messages and messages.is_a?(Hash)
|
10
10
|
messages = messages['messages']
|
11
11
|
end
|
@@ -39,9 +39,9 @@ module FBomb
|
|
39
39
|
module StreamExtension
|
40
40
|
def stream
|
41
41
|
@stream ||= (
|
42
|
-
|
42
|
+
flow = self
|
43
43
|
Twitter::JSONStream.connect(
|
44
|
-
:path => "/
|
44
|
+
:path => "/flow/#{ flow.id }/live.json",
|
45
45
|
:host => 'streaming.campfirenow.com',
|
46
46
|
:auth => "#{ connection.token }:x"
|
47
47
|
)
|
@@ -53,19 +53,47 @@ module FBomb
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
module UrlExtension
|
57
|
+
attr_accessor :campfire
|
58
|
+
|
59
|
+
def url
|
60
|
+
File.join(campfire.url, "flow/#{ id }")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
56
64
|
def Campfire.new(*args, &block)
|
57
65
|
allocate.tap do |instance|
|
58
66
|
instance.send(:initialize, *args, &block)
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
62
|
-
def
|
70
|
+
def flow_for(name)
|
63
71
|
name = name.to_s
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
72
|
+
flow = flows.detect{|_| _.name == name}
|
73
|
+
flow.extend(SearchExtension)
|
74
|
+
flow.extend(UserExtension)
|
75
|
+
flow.extend(StreamExtension)
|
76
|
+
flow.extend(UrlExtension)
|
77
|
+
flow.campfire = self
|
78
|
+
flow
|
79
|
+
end
|
80
|
+
|
81
|
+
attr_accessor :token
|
82
|
+
|
83
|
+
def url
|
84
|
+
if token
|
85
|
+
"#{ scheme }://#{ token }:X@#{ host }"
|
86
|
+
else
|
87
|
+
"#{ scheme }://#{ host }"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def host
|
92
|
+
connection.raw_connection.host
|
93
|
+
end
|
94
|
+
|
95
|
+
def scheme
|
96
|
+
connection.raw_connection.scheme
|
69
97
|
end
|
70
98
|
end
|
71
99
|
end
|
data/lib/fbomb/command.rb
CHANGED
@@ -5,9 +5,11 @@ module FBomb
|
|
5
5
|
class Table < ::Map
|
6
6
|
def help
|
7
7
|
map = Map.new
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
each do |key, command|
|
10
|
+
map[key] = command.description
|
10
11
|
end
|
12
|
+
|
11
13
|
map
|
12
14
|
end
|
13
15
|
end
|
@@ -15,12 +17,15 @@ module FBomb
|
|
15
17
|
class << Command
|
16
18
|
fattr(:table){ Table.new }
|
17
19
|
fattr(:dir){ File.join(File.expand_path(File.dirname(__FILE__)), 'commands') }
|
18
|
-
fattr(:
|
20
|
+
fattr(:flow)
|
21
|
+
fattr(:user)
|
22
|
+
fattr(:command_paths){ [] }
|
19
23
|
|
20
24
|
def load(*args)
|
21
25
|
args.flatten.uniq.each do |arg|
|
26
|
+
Command.command_paths << arg
|
22
27
|
case arg.to_s
|
23
|
-
when %r
|
28
|
+
when %r|^[/~]|
|
24
29
|
load_absolute_path(arg)
|
25
30
|
when %r|://|
|
26
31
|
load_uri(arg)
|
@@ -48,7 +53,7 @@ module FBomb
|
|
48
53
|
def load_uri(arg)
|
49
54
|
uri = arg.to_s
|
50
55
|
open(uri) do |fd|
|
51
|
-
open(path){|fd| load_string(fd.read)}
|
56
|
+
open(path){|fd| load_string(fd.read, uri, 1)}
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
@@ -61,22 +66,22 @@ module FBomb
|
|
61
66
|
def load_absolute_path(arg)
|
62
67
|
path = File.expand_path(arg.to_s)
|
63
68
|
path += '.rb' unless path =~ /\.rb\Z/
|
64
|
-
open(path){|fd| load_string(fd.read)}
|
69
|
+
open(path){|fd| load_string(fd.read, path, 1)}
|
65
70
|
end
|
66
71
|
|
67
|
-
def load_string(string, dangerous = true)
|
72
|
+
def load_string(string, __file__, __lineno__, dangerous = true)
|
68
73
|
Thread.new(string, dangerous) do |string, dangerous|
|
69
74
|
Thread.current.abort_on_exception = true
|
70
75
|
$SAFE = 12 unless dangerous
|
71
|
-
|
76
|
+
module_eval(string, __file__, __lineno__)
|
72
77
|
end.value
|
73
78
|
end
|
74
79
|
end
|
75
80
|
|
76
81
|
## instance methods
|
77
82
|
#
|
78
|
-
fattr(:
|
79
|
-
fattr(:
|
83
|
+
fattr(:flow){ self.class.flow }
|
84
|
+
fattr(:key)
|
80
85
|
fattr(:help)
|
81
86
|
fattr(:setup)
|
82
87
|
|
@@ -85,21 +90,53 @@ module FBomb
|
|
85
90
|
end
|
86
91
|
|
87
92
|
def call(*args, &block)
|
88
|
-
|
93
|
+
arity = @call.arity
|
94
|
+
|
95
|
+
argv =
|
96
|
+
if arity >= 0
|
97
|
+
args[0, arity]
|
98
|
+
else
|
99
|
+
head = []
|
100
|
+
tail = []
|
101
|
+
n = arity.abs - 1
|
102
|
+
head = args[0...n]
|
103
|
+
tail = args[n..-1]
|
104
|
+
[*(head + tail)]
|
105
|
+
end
|
106
|
+
|
107
|
+
argv.compact!
|
108
|
+
|
109
|
+
block ? @call=call : instance_exec(*argv, &@call)
|
89
110
|
end
|
90
111
|
|
91
112
|
def call=(call)
|
92
113
|
@call = call
|
93
114
|
end
|
94
115
|
|
95
|
-
%w( speak paste ).each do |method|
|
116
|
+
%w( speak paste upload users ).each do |method|
|
96
117
|
module_eval <<-__, __FILE__, __LINE__
|
97
118
|
def #{ method }(*args, &block)
|
98
|
-
|
119
|
+
flow ? flow.#{ method }(*args, &block) : puts(*args, &block)
|
99
120
|
end
|
100
121
|
__
|
101
122
|
end
|
102
123
|
|
124
|
+
def most_recent_comment
|
125
|
+
message =
|
126
|
+
catch(:message) do
|
127
|
+
FBomb.messages.reverse.each do |message|
|
128
|
+
next if message == FBomb.message
|
129
|
+
|
130
|
+
case message['type'].to_s
|
131
|
+
when 'TextMessage'
|
132
|
+
throw :message, message
|
133
|
+
end
|
134
|
+
end
|
135
|
+
nil
|
136
|
+
end
|
137
|
+
message['body'] if message
|
138
|
+
end
|
139
|
+
|
103
140
|
## dsl
|
104
141
|
#
|
105
142
|
class DSL
|
@@ -122,8 +159,8 @@ module FBomb
|
|
122
159
|
def command(*args, &block)
|
123
160
|
return @command if(args.empty? and block.nil?)
|
124
161
|
@command = Command.new
|
125
|
-
@command.
|
126
|
-
@commands[@command.
|
162
|
+
@command.key = Util.absolute_key_for(args.shift)
|
163
|
+
@commands[@command.key] ||= @command
|
127
164
|
evaluate(&block)
|
128
165
|
end
|
129
166
|
alias_method('Command', 'command')
|