slack-smart-bot 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slack-smart-bot.rb +15 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de2e23162b674076d5e475671a8736db3fe3f0ebc50db8284bfda453008413e1
|
4
|
+
data.tar.gz: 8b47643c8cd75d7efc36b5b6b13db45af782dd41cb6093b100116fba5b516eb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a3152be4feb408f72442952a144055032a07df4a5d6de0e5ac4adf74728eacc12e8ae60514d408bddc09a58613270e4ac2000c59a52862a492e9f465f37a6a4
|
7
|
+
data.tar.gz: 336750bcac43c800c7b2cc1edeae4f8d43026126e3e10e6f159ad5f7c47662ed7a6c747fba6136779d06625e1edab0fd6430875316a3d271617375899ac96964
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -28,7 +28,7 @@ end
|
|
28
28
|
SHORTCUTS_FILE = "slack-smart-bot_shortcuts_#{CHANNEL}.rb".gsub(" ", "_")
|
29
29
|
|
30
30
|
class SlackSmartBot
|
31
|
-
attr_accessor :config, :client
|
31
|
+
attr_accessor :config, :client
|
32
32
|
VERSION = Gem.loaded_specs.values.select { |x| x.name == "slack-smart-bot" }[0].version.to_s
|
33
33
|
|
34
34
|
def initialize(config)
|
@@ -47,7 +47,6 @@ class SlackSmartBot
|
|
47
47
|
Slack.configure do |conf|
|
48
48
|
conf.token = config[:token]
|
49
49
|
end
|
50
|
-
self.wclient = Slack::Web::Client.new
|
51
50
|
self.client = Slack::RealTime::Client.new(start_method: :rtm_connect)
|
52
51
|
|
53
52
|
@listening = Array.new
|
@@ -87,10 +86,9 @@ class SlackSmartBot
|
|
87
86
|
@rules_imported = eval(file_conf)
|
88
87
|
end
|
89
88
|
end
|
90
|
-
wclient.auth_test
|
91
89
|
|
92
90
|
begin
|
93
|
-
user_info =
|
91
|
+
user_info = client.web_client.users_info(user: "#{"@" if config[:nick][0] != "@"}#{config[:nick]}")
|
94
92
|
config[:nick_id] = user_info.user.id
|
95
93
|
rescue Exception => stack
|
96
94
|
@logger.fatal stack
|
@@ -154,7 +152,7 @@ class SlackSmartBot
|
|
154
152
|
end
|
155
153
|
|
156
154
|
def get_channels_name_and_id
|
157
|
-
channels =
|
155
|
+
channels = client.web_client.channels_list.channels
|
158
156
|
@channels_id = Hash.new()
|
159
157
|
@channels_name = Hash.new()
|
160
158
|
channels.each do |ch|
|
@@ -189,7 +187,7 @@ class SlackSmartBot
|
|
189
187
|
if !dest.nil? and ((dest[0] == "D" and ON_MASTER_BOT) or (dest[0] == "C")) and data.user.to_s != ""
|
190
188
|
begin
|
191
189
|
#todo: when changed @questions user_id then move user_info inside the ifs to avoid calling it when not necessary
|
192
|
-
user_info =
|
190
|
+
user_info = client.web_client.users_info(user: data.user)
|
193
191
|
#todo: check to remove user_info.user.name == config[:nick] since I think we will never get messages from the bot on slack
|
194
192
|
# if Direct message or we are in the channel of the bot
|
195
193
|
if data.text.size >= 2 and
|
@@ -217,9 +215,9 @@ class SlackSmartBot
|
|
217
215
|
if @channels_id[CHANNEL] == channel_rules #to be treated only on the bot of the requested channel
|
218
216
|
dest = data.channel
|
219
217
|
|
220
|
-
channels =
|
218
|
+
channels = client.web_client.channels_list.channels
|
221
219
|
channel_found = channels.detect { |c| c.name == channel_rules_name }
|
222
|
-
members =
|
220
|
+
members = client.web_client.conversations_members(channel: @channels_id[channel_rules_name]).members unless channel_found.nil?
|
223
221
|
if channel_found.nil?
|
224
222
|
@logger.fatal "Not possible to find the channel #{channel_rules_name}"
|
225
223
|
elsif channel_found.name == MASTER_CHANNEL
|
@@ -281,13 +279,11 @@ class SlackSmartBot
|
|
281
279
|
end
|
282
280
|
end
|
283
281
|
|
284
|
-
|
285
|
-
|
286
282
|
#todo: verify if on slack on anytime nick == config[:nick]
|
287
283
|
if nick == config[:nick] #if message is coming from the bot
|
288
284
|
begin
|
289
285
|
case text
|
290
|
-
when /^Bot has been killed by/
|
286
|
+
when /^Bot has been (closed|killed) by/i
|
291
287
|
@logger.info "#{nick}: #{text}"
|
292
288
|
exit!
|
293
289
|
when /^Changed status on (.+) to :(.+)/i
|
@@ -586,7 +582,7 @@ class SlackSmartBot
|
|
586
582
|
end
|
587
583
|
respond "Bot channels have been notified", dest
|
588
584
|
else
|
589
|
-
myconv =
|
585
|
+
myconv = client.web_client.users_conversations(exclude_archived: true, limit: 100, types: "im, public_channel").channels
|
590
586
|
myconv.each do |c|
|
591
587
|
respond message, c.id unless c.name == MASTER_CHANNEL
|
592
588
|
end
|
@@ -612,9 +608,9 @@ class SlackSmartBot
|
|
612
608
|
elsif @channels_id.key?(channel) #it is a channel name
|
613
609
|
channel_id = @channels_id[channel]
|
614
610
|
end
|
615
|
-
channels =
|
611
|
+
channels = client.web_client.channels_list.channels
|
616
612
|
channel_found = channels.detect { |c| c.name == channel }
|
617
|
-
members =
|
613
|
+
members = client.web_client.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
|
618
614
|
|
619
615
|
if channel_id.nil?
|
620
616
|
respond "There is no channel with that name: #{channel}, please be sure is written exactly the same", dest
|
@@ -719,9 +715,9 @@ class SlackSmartBot
|
|
719
715
|
#help:
|
720
716
|
when /^use rules (from\s+)?<#C\w+\|(.+)>/i, /^use rules (from\s+)?(.+)/i
|
721
717
|
channel = $2
|
722
|
-
channels =
|
718
|
+
channels = client.web_client.channels_list.channels
|
723
719
|
channel_found = channels.detect { |c| c.name == channel }
|
724
|
-
members =
|
720
|
+
members = client.web_client.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
|
725
721
|
|
726
722
|
if channel_found.nil?
|
727
723
|
respond "The channel you are trying to use doesn't exist", dest
|
@@ -1087,7 +1083,7 @@ class SlackSmartBot
|
|
1087
1083
|
if id_user[0] == "D"
|
1088
1084
|
client.message(channel: id_user, as_user: true, text: msg)
|
1089
1085
|
else
|
1090
|
-
im =
|
1086
|
+
im = client.web_client.im_open(user: id_user)
|
1091
1087
|
client.message(channel: im["channel"]["id"], as_user: true, text: msg)
|
1092
1088
|
end
|
1093
1089
|
end
|
@@ -1096,13 +1092,13 @@ class SlackSmartBot
|
|
1096
1092
|
#to send a file to an user or channel
|
1097
1093
|
def send_file(to, msg, file, title, format, type='text')
|
1098
1094
|
if to[0] == "U" #user
|
1099
|
-
im =
|
1095
|
+
im = client.web_client.im_open(user: to)
|
1100
1096
|
channel = im["channel"]["id"]
|
1101
1097
|
else
|
1102
1098
|
channel = to
|
1103
1099
|
end
|
1104
1100
|
|
1105
|
-
|
1101
|
+
client.web_client.files_upload(
|
1106
1102
|
channels: channel,
|
1107
1103
|
as_user: true,
|
1108
1104
|
file: Faraday::UploadIO.new(file, format),
|