slackbot_frd 0.0.1 → 0.0.2
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/bin/slackbot-frd +51 -12
- data/lib/slackbot_frd/initializer/bot_starter.rb +3 -3
- data/lib/slackbot_frd/lib/slack_connection.rb +4 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13a08ffadb9cd54f73c63639c08a1ea18ec13433
|
4
|
+
data.tar.gz: cc02227f5e2563e12055fa7acbdab07d36b68921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c931ec908432fd850989608a8009842daa1dec90bcd4bc82bb240efa84fe32c9904a99e2bd2825b46e0e391e533e25577a3cef15d99a3bbd64695dbfc250fa
|
7
|
+
data.tar.gz: 646772e155bff7d015d64df6a78524a46dda856ccf05fd68b3031afdbc2c1f44d5efa74b5ced7a61ea4715e92b14da38a85ac5cace09346aecc9c814ccee7e84
|
data/bin/slackbot-frd
CHANGED
@@ -17,7 +17,7 @@ DEBUG = true
|
|
17
17
|
PID_FILE_WATCHER = "/tmp/slackbot-frd-watcher.pid"
|
18
18
|
PID_FILE_CONNECTION = "/tmp/slackbot-frd-connection.pid"
|
19
19
|
BOT_LIST_FILE = "/tmp/slackbot-frd-bot-list.pid"
|
20
|
-
ERROR_FILE = "/tmp/slackbot-frd
|
20
|
+
ERROR_FILE = "/tmp/slackbot-frd.errors"
|
21
21
|
DEFAULT_CONFIG_FILE = "slackbot-frd.conf"
|
22
22
|
LOG_FILE = "slackbot-frd.log"
|
23
23
|
|
@@ -32,6 +32,22 @@ class SlackbotFrdBin < Thor
|
|
32
32
|
# TODO
|
33
33
|
end
|
34
34
|
|
35
|
+
desc "genconfig", "Generate a skeleton config file"
|
36
|
+
long_desc <<-LONGDESC
|
37
|
+
genconfig will generate a skeleton config file that
|
38
|
+
can be customized
|
39
|
+
LONGDESC
|
40
|
+
def genconfig
|
41
|
+
File.write(config_file_location, <<-CONFIG_FILE_SKELETON)
|
42
|
+
{
|
43
|
+
"token" : "<put-token-here>",
|
44
|
+
"botdir" : ".",
|
45
|
+
"daemonize" : false,
|
46
|
+
"bots" : []
|
47
|
+
}
|
48
|
+
CONFIG_FILE_SKELETON
|
49
|
+
end
|
50
|
+
|
35
51
|
desc "start [bot1] [bot2] [botx...]", "Start all specified bots, or all bots"
|
36
52
|
long_desc <<-LONGDESC
|
37
53
|
start [bot1] [bot2] [botx...] will start the specified bots.
|
@@ -47,8 +63,16 @@ class SlackbotFrdBin < Thor
|
|
47
63
|
option 'config-file'.to_sym, type: :string, aliases: 'c'
|
48
64
|
option :token, type: :string, aliases: 't'
|
49
65
|
def start(*bots)
|
66
|
+
if running?(watcher_pid)
|
67
|
+
SlackbotFrd::Log.warn("Already running. Not starting again")
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
delete_pid_files
|
72
|
+
delfile(ERROR_FILE)
|
73
|
+
|
50
74
|
config_file = options['config-file'.to_sym]
|
51
|
-
config_file =
|
75
|
+
config_file = config_file_location unless config_file
|
52
76
|
json = config_file_json(config_file) if config_file
|
53
77
|
json ||= {}
|
54
78
|
|
@@ -92,6 +116,9 @@ class SlackbotFrdBin < Thor
|
|
92
116
|
# first kill the watcher, then kill the connection
|
93
117
|
kill_pid(watcher_pid)
|
94
118
|
kill_pid(connection_pid)
|
119
|
+
|
120
|
+
delete_pid_files
|
121
|
+
delfile(ERROR_FILE)
|
95
122
|
end
|
96
123
|
|
97
124
|
desc "restart", "Stop all bots and restart them"
|
@@ -104,6 +131,10 @@ class SlackbotFrdBin < Thor
|
|
104
131
|
stop
|
105
132
|
start(set_bots)
|
106
133
|
end
|
134
|
+
private
|
135
|
+
def config_file_location
|
136
|
+
"#{Dir.pwd}/#{DEFAULT_CONFIG_FILE}"
|
137
|
+
end
|
107
138
|
|
108
139
|
private
|
109
140
|
def config_file_json(config_file)
|
@@ -137,27 +168,33 @@ class SlackbotFrdBin < Thor
|
|
137
168
|
|
138
169
|
private
|
139
170
|
def watch_connection(bots, token, botdir, daemonize = false)
|
171
|
+
Process.daemon if daemonize
|
140
172
|
until errors
|
141
|
-
pid = Process.fork
|
142
|
-
Process.daemon if daemonize
|
143
|
-
loop { BotStarter.start_bots(ERROR_FILE, token, botdir, bots) }
|
144
|
-
end
|
173
|
+
pid = Process.fork { BotStarter.start_bots(ERROR_FILE, token, botdir, bots) }
|
145
174
|
set_connection_pid(pid)
|
146
175
|
Process.wait(pid)
|
147
176
|
end
|
148
177
|
if errors
|
149
|
-
|
178
|
+
SlackbotFrd::Log.error("Slack connection encountered errors: #{errors}")
|
179
|
+
delfile(ERROR_FILE)
|
150
180
|
end
|
181
|
+
delete_pid_files
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
def delfile(file)
|
186
|
+
File.delete(file) if File.exists?(file)
|
151
187
|
end
|
152
188
|
|
153
189
|
private
|
154
190
|
def errors
|
155
|
-
return File.read(ERROR_FILE).split if File.exists?(ERROR_FILE)
|
191
|
+
return File.read(ERROR_FILE).split("\n") if File.exists?(ERROR_FILE)
|
156
192
|
nil
|
157
193
|
end
|
158
194
|
|
159
195
|
private
|
160
196
|
def running?(pid)
|
197
|
+
return false unless pid
|
161
198
|
begin
|
162
199
|
Process.getpgid(pid.to_i)
|
163
200
|
return true
|
@@ -168,12 +205,14 @@ class SlackbotFrdBin < Thor
|
|
168
205
|
|
169
206
|
private
|
170
207
|
def watcher_pid
|
171
|
-
File.read(PID_FILE_WATCHER).to_i
|
208
|
+
File.read(PID_FILE_WATCHER).to_i if File.exists?(PID_FILE_WATCHER)
|
209
|
+
nil
|
172
210
|
end
|
173
211
|
|
174
212
|
private
|
175
213
|
def connection_pid
|
176
|
-
File.read(PID_FILE_CONNECTION).to_i
|
214
|
+
File.read(PID_FILE_CONNECTION).to_i if File.exists?(PID_FILE_CONNECTION)
|
215
|
+
nil
|
177
216
|
end
|
178
217
|
|
179
218
|
private
|
@@ -188,8 +227,8 @@ class SlackbotFrdBin < Thor
|
|
188
227
|
|
189
228
|
private
|
190
229
|
def delete_pid_files
|
191
|
-
|
192
|
-
|
230
|
+
delfile(PID_FILE_WATCHER)
|
231
|
+
delfile(PID_FILE_CONNECTION)
|
193
232
|
end
|
194
233
|
end
|
195
234
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'file-append'
|
3
4
|
require 'thor'
|
4
5
|
|
5
6
|
require 'slackbot_frd/lib/slack_connection'
|
@@ -15,7 +16,7 @@ class BotStarter
|
|
15
16
|
bot_enabled = ->(bot) { bots.empty? || bots.include?(bot) }
|
16
17
|
|
17
18
|
# Create a new Connection to pass to the bot classes
|
18
|
-
slack_connection = SlackbotFrd::SlackConnection.new(token)
|
19
|
+
slack_connection = SlackbotFrd::SlackConnection.new(token, errors_file)
|
19
20
|
|
20
21
|
load_bot_files(botdir)
|
21
22
|
|
@@ -32,9 +33,8 @@ class BotStarter
|
|
32
33
|
end
|
33
34
|
|
34
35
|
if bots.count == 0
|
35
|
-
@error ||= []
|
36
|
-
@error.push("No bots loaded")
|
37
36
|
SlackbotFrd::Log.error("Not starting: no bots found")
|
37
|
+
File.append(errors_file, "Not starting: no bots found")
|
38
38
|
else
|
39
39
|
SlackbotFrd::Log.debug("Starting SlackConnection")
|
40
40
|
slack_connection.start
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'faye/websocket'
|
2
2
|
require 'eventmachine'
|
3
|
+
require 'file-append'
|
3
4
|
require 'json'
|
4
5
|
|
5
6
|
require 'slackbot_frd/lib/errors'
|
@@ -22,13 +23,14 @@ module SlackbotFrd
|
|
22
23
|
|
23
24
|
attr_accessor :token
|
24
25
|
|
25
|
-
def initialize(token)
|
26
|
+
def initialize(token, errors_file)
|
26
27
|
unless token
|
27
28
|
SlackbotFrd::Log::error("No token passed to #{self.class}")
|
28
29
|
raise NoTokenError.new
|
29
30
|
end
|
30
31
|
|
31
32
|
@token = token
|
33
|
+
@errors_file = errors_file
|
32
34
|
@event_id = 0
|
33
35
|
@on_connected_callbacks = []
|
34
36
|
@on_disconnected_callbacks = []
|
@@ -57,7 +59,7 @@ module SlackbotFrd
|
|
57
59
|
unless wss_url
|
58
60
|
str = "No Real Time stream opened by slack. Check for correct authentication token"
|
59
61
|
SlackbotFrd::Log.error(str)
|
60
|
-
File.append(@errors_file, str)
|
62
|
+
File.append(@errors_file, "#{str}\n") if @errors_file
|
61
63
|
return
|
62
64
|
end
|
63
65
|
@ws = Faye::WebSocket::Client.new(wss_url)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slackbot_frd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Porter
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: file-append
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: byebug
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,7 +177,7 @@ files:
|
|
163
177
|
- lib/slackbot_frd/slack_methods/im_channels_list.rb
|
164
178
|
- lib/slackbot_frd/slack_methods/rtm_start.rb
|
165
179
|
- lib/slackbot_frd/slack_methods/users_list.rb
|
166
|
-
homepage:
|
180
|
+
homepage: https://github.com/FreedomBen/slackbot_frd
|
167
181
|
licenses:
|
168
182
|
- MIT
|
169
183
|
metadata: {}
|