slack-smart-bot 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -0
  3. data/lib/slack-smart-bot.rb +61 -12
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd812140a95cb9fc2621a610c3c380ae0501b11a1fdbb2f84d632c0b1aa071fc
4
- data.tar.gz: f3a778525686d948b1316dd5c16f7ce6cbf6b1725c4e30909028e34f47024343
3
+ metadata.gz: 608a8f6f85dffb984e73c88319c4d1efda9dc7cdbbbfd31adf5207a1b9355a35
4
+ data.tar.gz: d44177e903e26b3e53ce3a3a80d65759c45efd1e80fde67405f854c488e6b111
5
5
  SHA512:
6
- metadata.gz: e668e07bb746ad498b4e11bcc3fbd0d1cab5bd9d0f8fb8656f1e5618b0a7b9d4ebd67e27d365f7cfdb0e8eb8805fff5b19054987ec7aff3d3b149b2f7a7b3aa7
7
- data.tar.gz: d003974b5a88a253e9d5021724b98495b3b548d3d76c565bc4e6698832b22aae9ba789a9fd55ba1f34d2cc5a10eb2a47472a9aed37ffb655be24be191e19a167
6
+ metadata.gz: ec02c8abcec55310d5b5088eeb3879b2310b5f04fe5318bf71869c1ff3249064f0c315dd5c08733ec9db31dd7110f79f7d584e7ef2187ef01e3c4804f090eb13
7
+ data.tar.gz: ca643989c2f909478f38662dd0bb24d2696e6a4ffbcd115ae4ecf607326eb5d1a0515df3215e0c9066161882f4e79b6f43b4fca6c2467d75b4545ee76c31c0cf
data/README.md CHANGED
@@ -119,6 +119,8 @@ Some of the commands are available always even when the bot is not listening to
119
119
 
120
120
  >Bot starts listening to you
121
121
 
122
+ >If you want to avoid a single message to be treated by the smart bot, start the message by -
123
+
122
124
  **_`Bye Bot`_**
123
125
 
124
126
  **_`Bye THE_NAME_OF_THE_BOT`_**
@@ -175,6 +177,17 @@ As soon as you save the file after editing it will become available on your chan
175
177
 
176
178
  >Only works if you are on Master channel and you created that bot or you are an admin user
177
179
 
180
+ **_`notify MESSAGE`_**
181
+
182
+ **_`notify all MESSAGE`_**
183
+
184
+ >It will send a notificaiton message to all bot channels
185
+
186
+ >It will send a notification message to all channels the bot joined and private conversations with the bot
187
+
188
+ >Only works if you are on Master channel and you are an admin user
189
+
190
+
178
191
  ### Available commands only when listening to you or on demand or in a private conversation with the Smart Bot
179
192
 
180
193
  All the commands described on here or on your specific Rules file can be used when the bot is listening to you or on demand or in a private conversation with the Smart Bot.
@@ -248,6 +261,14 @@ Apart of the specific commands you define on the rules file of the channel, you
248
261
 
249
262
  >it will stop using the rules from the specified channel.
250
263
 
264
+ ### Available commands from channels without a Smart Bot
265
+ **_`@BOT_NAME on #CHANNEL_NAME COMMAND`_**
266
+
267
+ **_`@BOT_NAME #CHANNEL_NAME COMMAND`_**
268
+
269
+ >It will run the supplied command using the rules on the channel supplied.
270
+
271
+ >You need to join the specified channel to be able to use those rules.
251
272
 
252
273
  ## Contributing
253
274
 
@@ -99,7 +99,13 @@ class SlackSmartBot
99
99
  m = "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
100
100
  puts m
101
101
  @logger.info m
102
- respond "Smart Bot started v#{VERSION}\nIf you want to know what I can do for you: `bot help`.\n`bot rules` if you want to display just the specific rules of this channel.\nYou can talk to me privately if you prefer it."
102
+ gems_remote = `gem list slack-smart-bot --remote`
103
+ version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
104
+ version_message = ''
105
+ if version_remote != VERSION
106
+ version_message = ". There is a new available version: #{version_remote}."
107
+ end
108
+ respond "Smart Bot started v#{VERSION}#{version_message}\nIf you want to know what I can do for you: `bot help`.\n`bot rules` if you want to display just the specific rules of this channel.\nYou can talk to me privately if you prefer it."
103
109
  end
104
110
 
105
111
  @status = STATUS_INIT
@@ -152,7 +158,6 @@ class SlackSmartBot
152
158
  #help: `@BOT_NAME #CHANNEL_NAME COMMAND`
153
159
  #help: It will run the supplied command using the rules on the channel supplied.
154
160
  #help: You need to join the specified channel to be able to use those rules.
155
- #help: The only
156
161
  def listen
157
162
  @salutations = [config[:nick], config[:nick_id], "bot", "smart"]
158
163
  client.on :message do |data|
@@ -164,42 +169,52 @@ class SlackSmartBot
164
169
  #todo: sometimes data.user is nil, check the problem.
165
170
  @logger.warn "!dest is nil. user: #{data.user}, channel: #{data.channel}, message: #{data.text}" if dest.nil?
166
171
  # Direct messages are treated only on the master bot
167
- @logger.info dest.inspect
168
- @logger.info data.text
169
172
  if !dest.nil? and ((dest[0] == 'D' and ON_MASTER_BOT) or (dest[0] == 'C'))
173
+ begin
174
+ #todo: when changed @questions user_id then move user_info inside the ifs to avoid calling it when not necessary
170
175
  user_info = wclient.users_info(user: data.user)
171
176
  #todo: check to remove user_info.user.name == config[:nick] since I think we will never get messages from the bot on slack
172
177
  # if Direct message or we are in the channel of the bot
173
- if dest[0]=='D' or @channels_id[CHANNEL] == data.channel or user_info.user.name == config[:nick]
178
+ if data.text.size >=2 and
179
+ ((data.text[0]=='`' and data.text[-1]=='`') or (data.text[0]=='*' and data.text[-1]=='*') or (data.text[0]=='_' and data.text[-1]=='_'))
180
+ data.text = data.text[1..-2]
181
+ end
182
+ if (dest[0]=='D' or @channels_id[CHANNEL] == data.channel or data.user == config[:nick_id]) and
183
+ data.text.size>0 and data.text[0]!="-"
184
+
174
185
  res = process_first(user_info.user, data.text, dest, data.channel)
175
- next if res.to_s == "next"
176
186
  # if @botname on #channel_rules: do something
177
187
  elsif data.text.match(/^<@#{config[:nick_id]}>\s(on\s)?<#(\w+)\|(.+)>\s*:?\s*(.+)$/i)
178
188
  channel_rules = $2
179
189
  channel_rules_name = $3
180
190
  command = $4
181
191
  command = "!" + command unless command[0]=="!"
182
-
183
192
  if @channels_id[CHANNEL] == channel_rules #to be treated only on the bot of the requested channel
184
193
  dest = data.channel
194
+
185
195
  channels = wclient.channels_list.channels
186
196
  channel_found = channels.detect { |c| c.name == channel_rules_name }
197
+ members = wclient.conversations_members(channel: @channels_id[channel_rules_name]).members unless channel_found.nil?
198
+
187
199
  if channel_found.nil?
188
200
  @logger.fatal "Not possible to find the channel #{channel_rules_name}"
189
201
  elsif channel_found.name == MASTER_CHANNEL
190
202
  respond "You cannot use the rules from Master Channel on any other channel.", dest
191
- elsif user_info.user.id == channel_found.creator or channel_found.members.include?(user_info.user.id)
203
+ elsif data.user == channel_found.creator or members.include?(data.user)
192
204
  res = process_first(user_info.user, command, dest, channel_rules)
193
- next if res.to_s == "next"
194
205
  else
195
206
  respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
196
207
  end
197
208
  end
198
- elsif @questions.keys.include?(user_info.user.name)
209
+ elsif @questions.keys.include?(user_info.user.name)
210
+ #todo: @questions key should be the id not the name. change it everywhere
199
211
  dest = data.channel
200
212
  res = process_first(user_info.user, data.text, dest, @channels_id[CHANNEL])
201
- next if res.to_s == "next"
202
213
  end
214
+ rescue Exception => stack
215
+ @logger.fatal stack
216
+ end
217
+
203
218
  end
204
219
  end
205
220
 
@@ -357,6 +372,7 @@ class SlackSmartBot
357
372
  #help: `Hello THE_NAME_OF_THE_BOT`
358
373
  #help: Also apart of Hello you can use _Hallo, Hi, Hola, What's up, Hey, Hæ_
359
374
  #help: Bot starts listening to you
375
+ #help: If you want to avoid a single message to be treated by the smart bot, start the message by -
360
376
  #help:
361
377
  when /^(Hello|Hallo|Hi|Hola|What's\sup|Hey|Hæ)\s(#{@salutations.join("|")})\s*$/i
362
378
  if @status == :on
@@ -467,7 +483,13 @@ class SlackSmartBot
467
483
  #helpadmin: If on master channel and admin user also it will display info about bots created
468
484
  #helpadmin:
469
485
  when /^bot\sstatus/i
470
- respond "Status: #{@status}. Version: #{VERSION}. Rules file: #{File.basename RULES_FILE} ", dest
486
+ gems_remote = `gem list slack-smart-bot --remote`
487
+ version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
488
+ version_message = ''
489
+ if version_remote != VERSION
490
+ version_message = " There is a new available version: #{version_remote}."
491
+ end
492
+ respond "Status: #{@status}. Version: #{VERSION}.#{version_message} Rules file: #{File.basename RULES_FILE} ", dest
471
493
  if @status == :on
472
494
  respond "I'm listening to [#{@listening.join(", ")}]", dest
473
495
  if ON_MASTER_BOT and ADMIN_USERS.include?(from)
@@ -477,6 +499,33 @@ class SlackSmartBot
477
499
  end
478
500
  end
479
501
 
502
+ #helpmaster: ----------------------------------------------
503
+ #helpmaster: `notify MESSAGE`
504
+ #helpmaster: `notify all MESSAGE`
505
+ #helpmaster: It will send a notificaiton message to all bot channels
506
+ #helpmaster: It will send a notification message to all channels the bot joined and private conversations with the bot
507
+ #helpmaster: Only works if you are on Master channel and you are an admin user
508
+ #helpmaster:
509
+ when /^notify\s+(all)?\s*(.+)\s*$/i
510
+ if ON_MASTER_BOT
511
+ if ADMIN_USERS.include?(from) #admin user
512
+ all = $1
513
+ message = $2
514
+ if all.nil?
515
+ @bots_created.each do |k,v|
516
+ respond message, k
517
+ end
518
+ respond "Bot channels have been notified", dest
519
+ else
520
+ myconv = wclient.users_conversations(exclude_archived: true, limit: 100, types: 'im, public_channel').channels
521
+ myconv.each do |c|
522
+ respond message, c.id unless c.name == MASTER_CHANNEL
523
+ end
524
+ respond "Channels and users have been notified", dest
525
+ end
526
+ end
527
+ end
528
+
480
529
  #helpmaster: ----------------------------------------------
481
530
  #helpmaster: `create bot on CHANNEL_NAME`
482
531
  #helpmaster: creates a new bot on the channel specified
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-smart-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2019-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client