babot 0.1.5 → 0.2.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/babot.gemspec +1 -1
- data/bin/babot +11 -5
- data/lib/babot.rb +34 -30
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b6b19753e0a50827eb7d2423bd654a7bcecceae
|
4
|
+
data.tar.gz: 5dc21ac5617ba8b07f4e1bf413d21f995b6702be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c1c0a8d7fd364e5a8e0a1ab1e6c5a53f2754f4aebe69f8997d6b3c65187dfe6ee25a0daad046d30458ad457b2a57bfdf85649fc0447e2134d9d6ff58dfff16
|
7
|
+
data.tar.gz: 3be4b33f9fdf2a47e06f6749b68bc8ec39c0fb2499282e719b9516c26da8913f2eb12e7df322f35f43572231664a1ee26d4f17e43974fb8119fddbe0143d2d46
|
data/Gemfile.lock
CHANGED
data/babot.gemspec
CHANGED
data/bin/babot
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'boson/runner'
|
4
|
-
require 'pathname'
|
5
4
|
|
6
5
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
7
6
|
require 'babot'
|
8
7
|
|
8
|
+
FileUtils.mkdir_p [Babot.root.join("config"),
|
9
|
+
Babot.root.join("bots")]
|
10
|
+
|
9
11
|
class BabotRunner < Boson::Runner
|
10
|
-
desc "Update
|
11
|
-
def update
|
12
|
-
Babot.update
|
12
|
+
desc "Update bot [name]"
|
13
|
+
def update(name)
|
14
|
+
Babot.update(name)
|
13
15
|
end
|
14
16
|
|
15
17
|
desc "Update crontab"
|
@@ -31,7 +33,6 @@ class BabotRunner < Boson::Runner
|
|
31
33
|
def add(name, repository)
|
32
34
|
Babot.add name, repository
|
33
35
|
Babot.configure name
|
34
|
-
Babot.update
|
35
36
|
end
|
36
37
|
|
37
38
|
desc "Delete bot [name]"
|
@@ -43,6 +44,11 @@ class BabotRunner < Boson::Runner
|
|
43
44
|
def configure(name)
|
44
45
|
Babot.configure name
|
45
46
|
end
|
47
|
+
|
48
|
+
desc "List bots"
|
49
|
+
def list
|
50
|
+
puts Babot.list
|
51
|
+
end
|
46
52
|
end
|
47
53
|
|
48
54
|
BabotRunner.start
|
data/lib/babot.rb
CHANGED
@@ -4,34 +4,41 @@ require 'twitter'
|
|
4
4
|
require 'pathname'
|
5
5
|
require 'yaml'
|
6
6
|
require 'tempfile'
|
7
|
+
require 'whenever'
|
7
8
|
require 'active_support/core_ext/string/inflections'
|
9
|
+
require 'bundler/cli'
|
8
10
|
|
9
11
|
class Babot
|
10
12
|
|
11
13
|
class << self
|
12
14
|
|
13
|
-
def update
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def update(name)
|
16
|
+
git = Git.open(root.join("bots", name), :log => Logger.new(STDOUT))
|
17
|
+
git.fetch "origin"
|
18
|
+
git.merge "origin", "master"
|
19
|
+
system "cd #{root.join('bots', name)} && bundle install"
|
17
20
|
end
|
18
21
|
|
19
22
|
def schedule
|
20
|
-
File.open
|
21
|
-
|
22
|
-
|
23
|
-
schedule.puts <<-eos
|
23
|
+
cron = File.open root.join("schedule.rb"), "w"
|
24
|
+
list.map { |name| instanciate(name) }.each do |bot|
|
25
|
+
cron.puts <<-eos
|
24
26
|
every '#{bot.when}' do
|
25
|
-
|
27
|
+
command 'cd #{root.join('bots', bot.name)} && bundle exec babot call #{bot.name}'
|
26
28
|
end
|
27
29
|
eos
|
28
|
-
end
|
29
|
-
Whenever::CommandLine.execute(file: schedule.path, write: true)
|
30
30
|
end
|
31
|
+
cron.close
|
32
|
+
|
33
|
+
Whenever::CommandLine.execute(file: cron.path, write: true)
|
31
34
|
end
|
32
35
|
|
33
36
|
def add(name, repository)
|
34
|
-
|
37
|
+
if repository =~ /\//
|
38
|
+
FileUtils.ln_s repository, root.join("bots", name)
|
39
|
+
else
|
40
|
+
Git.clone repository, root.join("bots", name)
|
41
|
+
end
|
35
42
|
File.open(root.join("config", name).to_s, 'w') do |config|
|
36
43
|
config.write({ 'consumer_key' => "",
|
37
44
|
'consumer_secret' => "",
|
@@ -41,8 +48,8 @@ class Babot
|
|
41
48
|
end
|
42
49
|
|
43
50
|
def delete(name)
|
44
|
-
FileUtils.rm_rf
|
45
|
-
FileUtils.rm_f
|
51
|
+
FileUtils.rm_rf root.join("bots", name)
|
52
|
+
FileUtils.rm_f root.join("config", name)
|
46
53
|
end
|
47
54
|
|
48
55
|
def configure(name)
|
@@ -53,14 +60,19 @@ class Babot
|
|
53
60
|
Twitter.update dry(name)
|
54
61
|
end
|
55
62
|
|
63
|
+
def list
|
64
|
+
Dir.entries(root.join "bots").reject { |name| name =~ /^\./ }
|
65
|
+
end
|
66
|
+
|
56
67
|
def dry(name)
|
57
|
-
instanciate(name
|
68
|
+
instanciate(name).call
|
58
69
|
end
|
59
70
|
|
60
|
-
def instanciate(name
|
61
|
-
require Babot.
|
71
|
+
def instanciate(name)
|
72
|
+
require Babot.root.join("bots", name, 'lib', name)
|
62
73
|
|
63
|
-
|
74
|
+
options = YAML.load_file(root.join("config", name))
|
75
|
+
Babot::const_get(name.camelize).new(name, options)
|
64
76
|
rescue StandardError, ScriptError => error
|
65
77
|
puts error, error.backtrace
|
66
78
|
end
|
@@ -68,21 +80,13 @@ class Babot
|
|
68
80
|
def root
|
69
81
|
Pathname.new(ENV["HOME"]).join ".babot"
|
70
82
|
end
|
83
|
+
end
|
71
84
|
|
72
|
-
|
73
|
-
root.join("bots")
|
74
|
-
end
|
75
|
-
|
76
|
-
def config_root
|
77
|
-
root.join("config")
|
78
|
-
end
|
85
|
+
attr_accessor :name
|
79
86
|
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
87
|
+
def initialize(name, options)
|
88
|
+
@name = name
|
84
89
|
|
85
|
-
def initialize(options)
|
86
90
|
Twitter.configure do |config|
|
87
91
|
config.consumer_key = options['consumer_key']
|
88
92
|
config.consumer_secret = options['consumer_secret']
|