slackbot_frd 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/slackbot-frd +1 -1
- data/lib/slackbot_frd/lib/slack_connection.rb +36 -24
- data/lib/slackbot_frd/slack_methods/channels_invite.rb +35 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8e1ae54ee35f6483bf1a209d5c233dc94e2b937
|
4
|
+
data.tar.gz: c8dbcc68b6a1dfcebb81226c0a16455792acae6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a180c87abea6a0e14aacd4a280274458cdef7ef224649c2a58b464630d5462f74c0fed7beebd5ea344afeefe2ea87802721fbc2fcd1d9231fba6a2fb5d096c04
|
7
|
+
data.tar.gz: be3640e1231e738f9e5304096745437bb0759880b6726307c274fbfe193995878fc3485b5bc8bffd2873277f39a28681d88e4055eeabf49b6d90fb01679d1786
|
data/bin/slackbot-frd
CHANGED
@@ -109,7 +109,7 @@ class SlackbotFrdBin < Thor
|
|
109
109
|
option 'log-file', type: :string, aliases: 'lf'
|
110
110
|
def start(*bots)
|
111
111
|
if running?(watcher_pid)
|
112
|
-
SlackbotFrd::Log.warn("Already running. Not starting again")
|
112
|
+
SlackbotFrd::Log.warn("Already running (watcher pid: '#{watcher_pid}'). Not starting again")
|
113
113
|
return
|
114
114
|
end
|
115
115
|
|
@@ -45,14 +45,14 @@ module SlackbotFrd
|
|
45
45
|
@channel_name_to_id = {}
|
46
46
|
|
47
47
|
restrict_actions_to_channels_joined
|
48
|
-
SlackbotFrd::Log
|
48
|
+
SlackbotFrd::Log.debug("Done initializing #{self.class}")
|
49
49
|
end
|
50
50
|
|
51
51
|
def start
|
52
52
|
# Write pid file
|
53
53
|
File.write(PID_FILE_NAME, "#{Process.pid}")
|
54
54
|
|
55
|
-
SlackbotFrd::Log
|
55
|
+
SlackbotFrd::Log.info("#{self.class}: starting event machine")
|
56
56
|
|
57
57
|
EM.run do
|
58
58
|
begin
|
@@ -75,7 +75,7 @@ module SlackbotFrd
|
|
75
75
|
@ws.on(:close) { |event| File.delete(PID_FILE_NAME) }
|
76
76
|
end
|
77
77
|
|
78
|
-
SlackbotFrd::Log
|
78
|
+
SlackbotFrd::Log.debug("#{self.class}: event machine started")
|
79
79
|
end
|
80
80
|
|
81
81
|
def event_id
|
@@ -116,7 +116,7 @@ module SlackbotFrd
|
|
116
116
|
log_and_add_to_error_file("Cannot send message '#{message}' as user to channel '#{channel}' because not connected to wss stream")
|
117
117
|
end
|
118
118
|
|
119
|
-
SlackbotFrd::Log
|
119
|
+
SlackbotFrd::Log.debug("#{self.class}: Sending message '#{message}' as user to channel '#{channel}'")
|
120
120
|
|
121
121
|
begin
|
122
122
|
resp = @ws.send({
|
@@ -126,14 +126,14 @@ module SlackbotFrd
|
|
126
126
|
text: message
|
127
127
|
}.to_json)
|
128
128
|
|
129
|
-
SlackbotFrd::Log
|
129
|
+
SlackbotFrd::Log.debug("#{self.class}: Received response: #{resp}")
|
130
130
|
rescue SocketError => e
|
131
131
|
log_and_add_to_error_file(socket_error_message(e))
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
def send_message_as_user(channel, message, username, avatar, avatar_is_emoji)
|
136
|
-
SlackbotFrd::Log
|
136
|
+
SlackbotFrd::Log.debug("#{self.class}: Sending message '#{message}' as user '#{username}' to channel '#{channel}'")
|
137
137
|
|
138
138
|
resp = SlackbotFrd::SlackMethods::ChatPostMessage.postMessage(
|
139
139
|
@token,
|
@@ -144,7 +144,19 @@ module SlackbotFrd
|
|
144
144
|
avatar_is_emoji
|
145
145
|
)
|
146
146
|
|
147
|
-
SlackbotFrd::Log
|
147
|
+
SlackbotFrd::Log.debug("#{self.class}: Received response: #{resp}")
|
148
|
+
end
|
149
|
+
|
150
|
+
def invite_user(user, channel)
|
151
|
+
SlackbotFrd::Log.debug("#{self.class}: Inviting user '#{user}' to channel '#{channel}'")
|
152
|
+
|
153
|
+
resp = SlackbotFrd::SlackMethods::ChannelsInvite.invite(
|
154
|
+
@token,
|
155
|
+
user_name_to_id(user),
|
156
|
+
channel_name_to_id(channel),
|
157
|
+
)
|
158
|
+
|
159
|
+
SlackbotFrd::Log.debug("#{self.class}: Received response: #{resp}")
|
148
160
|
end
|
149
161
|
|
150
162
|
def restrict_actions_to_channels_joined(value = true)
|
@@ -156,19 +168,19 @@ module SlackbotFrd
|
|
156
168
|
a.map{ |id| user_id_to_name(id) }
|
157
169
|
end
|
158
170
|
|
159
|
-
def user_ids(
|
171
|
+
def user_ids(_force_refresh = false)
|
160
172
|
@user_id_to_name.keys
|
161
173
|
end
|
162
174
|
|
163
|
-
def user_names(
|
175
|
+
def user_names(_force_refresh = false)
|
164
176
|
@user_name_to_id.keys
|
165
177
|
end
|
166
178
|
|
167
|
-
def channel_ids(
|
179
|
+
def channel_ids(_force_refresh = false)
|
168
180
|
@user_id_to_name.keys
|
169
181
|
end
|
170
182
|
|
171
|
-
def channel_names(
|
183
|
+
def channel_names(_force_refresh = false)
|
172
184
|
@channel_name_to_id.keys
|
173
185
|
end
|
174
186
|
|
@@ -177,7 +189,7 @@ module SlackbotFrd
|
|
177
189
|
unless @user_id_to_name && @user_id_to_name.has_key?(user_id)
|
178
190
|
refresh_user_info
|
179
191
|
end
|
180
|
-
SlackbotFrd::Log
|
192
|
+
SlackbotFrd::Log.warn("#{self.class}: User id '#{user_id}' not found") unless @user_id_to_name.include?(user_id)
|
181
193
|
@user_id_to_name[user_id]
|
182
194
|
end
|
183
195
|
|
@@ -186,7 +198,7 @@ module SlackbotFrd
|
|
186
198
|
unless @user_name_to_id && @user_name_to_id.has_key?(user_name)
|
187
199
|
refresh_user_info
|
188
200
|
end
|
189
|
-
SlackbotFrd::Log
|
201
|
+
SlackbotFrd::Log.warn("#{self.class}: User name '#{user_name}' not found") unless @user_name_to_id.include?(user_name)
|
190
202
|
@user_name_to_id[user_name]
|
191
203
|
end
|
192
204
|
|
@@ -194,7 +206,7 @@ module SlackbotFrd
|
|
194
206
|
unless @channel_id_to_name && @channel_id_to_name.has_key?(channel_id)
|
195
207
|
refresh_channel_info
|
196
208
|
end
|
197
|
-
SlackbotFrd::Log
|
209
|
+
SlackbotFrd::Log.warn("#{self.class}: Channel id '#{channel_id}' not found") unless @channel_id_to_name.include?(channel_id)
|
198
210
|
@channel_id_to_name[channel_id]
|
199
211
|
end
|
200
212
|
|
@@ -204,7 +216,7 @@ module SlackbotFrd
|
|
204
216
|
unless @channel_name_to_id && @channel_name_to_id.has_key?(nc)
|
205
217
|
refresh_channel_info
|
206
218
|
end
|
207
|
-
SlackbotFrd::Log
|
219
|
+
SlackbotFrd::Log.warn("#{self.class}: Channel name '#{nc}' not found") unless @channel_name_to_id.include?(nc)
|
208
220
|
@channel_name_to_id[nc]
|
209
221
|
end
|
210
222
|
|
@@ -228,7 +240,7 @@ module SlackbotFrd
|
|
228
240
|
private
|
229
241
|
def process_message_received(event)
|
230
242
|
message = JSON.parse(event.data)
|
231
|
-
SlackbotFrd::Log
|
243
|
+
SlackbotFrd::Log.verbose("#{self.class}: Message received: #{message}")
|
232
244
|
if message["type"] == "message"
|
233
245
|
if message["subtype"] == "channel_join"
|
234
246
|
process_join_message(message)
|
@@ -244,13 +256,13 @@ module SlackbotFrd
|
|
244
256
|
|
245
257
|
private
|
246
258
|
def process_file_share(message)
|
247
|
-
SlackbotFrd::Log
|
248
|
-
SlackbotFrd::Log
|
259
|
+
SlackbotFrd::Log.verbose("#{self.class}: Processing file share: #{message}")
|
260
|
+
SlackbotFrd::Log.debug("#{self.class}: Not processing file share because it is not implemented:")
|
249
261
|
end
|
250
262
|
|
251
263
|
private
|
252
264
|
def process_chat_message(message)
|
253
|
-
SlackbotFrd::Log
|
265
|
+
SlackbotFrd::Log.verbose("#{self.class}: Processing chat message: #{message}")
|
254
266
|
|
255
267
|
user = message["user"]
|
256
268
|
user = :bot if message["subtype"] == "bot_message"
|
@@ -258,12 +270,12 @@ module SlackbotFrd
|
|
258
270
|
text = message["text"]
|
259
271
|
|
260
272
|
unless user
|
261
|
-
SlackbotFrd::Log
|
273
|
+
SlackbotFrd::Log.warn("#{self.class}: Chat message doesn't include user! message: #{message}")
|
262
274
|
return
|
263
275
|
end
|
264
276
|
|
265
277
|
unless channel
|
266
|
-
SlackbotFrd::Log
|
278
|
+
SlackbotFrd::Log.warn("#{self.class}: Chat message doesn't include channel! message: #{message}")
|
267
279
|
return
|
268
280
|
end
|
269
281
|
|
@@ -281,7 +293,7 @@ module SlackbotFrd
|
|
281
293
|
|
282
294
|
private
|
283
295
|
def process_join_message(message)
|
284
|
-
SlackbotFrd::Log
|
296
|
+
SlackbotFrd::Log.verbose("#{self.class}: Processing join message: #{message}")
|
285
297
|
user = message["user"]
|
286
298
|
user = :bot if message["subtype"] == "bot_message"
|
287
299
|
channel = message["channel"]
|
@@ -292,7 +304,7 @@ module SlackbotFrd
|
|
292
304
|
|
293
305
|
private
|
294
306
|
def process_leave_message(message)
|
295
|
-
SlackbotFrd::Log
|
307
|
+
SlackbotFrd::Log.verbose("#{self.class}: Processing leave message: #{message}")
|
296
308
|
user = message["user"]
|
297
309
|
user = :bot if message["subtype"] == "bot_message"
|
298
310
|
channel = message["channel"]
|
@@ -334,7 +346,7 @@ module SlackbotFrd
|
|
334
346
|
|
335
347
|
private
|
336
348
|
def log_and_add_to_error_file(err)
|
337
|
-
SlackbotFrd::Log
|
349
|
+
SlackbotFrd::Log.error(err)
|
338
350
|
File.append(@errors_file, "#{err}\n")
|
339
351
|
end
|
340
352
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module SlackbotFrd
|
5
|
+
module SlackMethods
|
6
|
+
class ChannelsInvite
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'https://slack.com/api/channels.invite'
|
9
|
+
|
10
|
+
attr_reader :response
|
11
|
+
|
12
|
+
def self.invite(token, user, channel)
|
13
|
+
ChannelsInvite.new(token, user, channel).run
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(token, user, channel)
|
17
|
+
@token = token
|
18
|
+
@user = user
|
19
|
+
@channel = channel
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
@response = JSON.parse(
|
24
|
+
self.class.post(
|
25
|
+
'',
|
26
|
+
body: {
|
27
|
+
token: @token, channel: @channel, user: @user
|
28
|
+
}
|
29
|
+
).body
|
30
|
+
)
|
31
|
+
@response
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/slackbot_frd/lib/slack_connection.rb
|
174
174
|
- lib/slackbot_frd/lib/user_channel_callbacks.rb
|
175
175
|
- lib/slackbot_frd/slack_methods/channels_info.rb
|
176
|
+
- lib/slackbot_frd/slack_methods/channels_invite.rb
|
176
177
|
- lib/slackbot_frd/slack_methods/channels_list.rb
|
177
178
|
- lib/slackbot_frd/slack_methods/chat_post_message.rb
|
178
179
|
- lib/slackbot_frd/slack_methods/im_channels_list.rb
|
@@ -198,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
199
|
version: '0'
|
199
200
|
requirements: []
|
200
201
|
rubyforge_project:
|
201
|
-
rubygems_version: 2.2.
|
202
|
+
rubygems_version: 2.2.3
|
202
203
|
signing_key:
|
203
204
|
specification_version: 4
|
204
205
|
summary: slackbot_frd provides a dirt-simple framework for implementing one or more
|