slack-smart-bot 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/slack-smart-bot.rb +42 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 335286b4f30e6956f97a8e79b6093851a2d048da064ba2efd7c302c01e7c19ec
4
- data.tar.gz: 89b301b09b8b60e7e19dfa35ee332a5666b3ba9c2c3a6bad2a9bd79ea0c583b8
3
+ metadata.gz: 4f525626c08342efb47771ac63104863aee616dfe45b428f09c48be94d855cd0
4
+ data.tar.gz: 8cf17f028da036a7b15c418b13a5e7f8011bb3359b15b8a1d02c88e6962cb379
5
5
  SHA512:
6
- metadata.gz: 56b297b67275669063426154d0450e40930217b4de92651fbc61f9aea93b8fe7b547d1c5a491f3265a98b8ec7755b0d47b8c300edc486b95199dc363dd42e84b
7
- data.tar.gz: 898432dc2811c1e02bafb27ff44bb514f985e6c4ab554fd2ddbdf32852f2f99dc3237ac9510c884dc6e89fca6c5af34e81b80ea61351a5932b2c1c3eaa6da114
6
+ metadata.gz: 4f6b5afdcfc4cfc199e272a4f0723865d4e68dd9e4242d73d88a3f8d4051575aca028bf53215b0261243743b00f7f467842f484f423daa2a0407cb69ccde59ed
7
+ data.tar.gz: c652cdad1b97ab090131f9baf3a9f5f4f6796a8a751052285f38329a390fc8d601dc4170acaefc18479593e8359724212d17cc2b589e1fcabe68103b15d87e81
@@ -372,7 +372,25 @@ class SlackSmartBot
372
372
  @logger.info "Changed status on #{channel_name} to :#{status}"
373
373
  end
374
374
  end
375
+ when /extended the rules from (.+) to be used on (.+)\.$/i
376
+ from_name = $1
377
+ to_name = $2
378
+ if ON_MASTER_BOT and @bots_created[@channels_id[from_name]][:cloud]
379
+ @bots_created[@channels_id[from_name]][:extended] << to_name
380
+ @bots_created[@channels_id[from_name]][:extended].uniq!
381
+ update_bots_file()
382
+ end
383
+
384
+ when /removed the access to the rules of (.+) from (.+)\.$/i
385
+ from_name = $1
386
+ to_name = $2
387
+ if ON_MASTER_BOT and @bots_created[@channels_id[from_name]][:cloud]
388
+ @bots_created[@channels_id[from_name]][:extended].delete(to_name)
389
+ update_bots_file()
390
+ end
391
+
375
392
  end
393
+
376
394
  return :next #don't continue analyzing
377
395
  rescue Exception => stack
378
396
  @logger.fatal stack
@@ -560,7 +578,7 @@ class SlackSmartBot
560
578
  respond "*Commands for administrators:*\n#{help_message.scan(/#\s*help\s*admin:(.*)/).join("\n")}", dest
561
579
  end
562
580
  if ON_MASTER_BOT and (dest[0] == "C" or dest[0] == "G")
563
- respond "*Commands only on Master Channel <##{@channels_id[MASTER_CHANNEL]}>:*\n#{help_message.scan(/#\s*help\s*master:(.*)/).join("\n")}", dest
581
+ respond "*Commands only on Master Channel <##{@master_bot_id}>:*\n#{help_message.scan(/#\s*help\s*master:(.*)/).join("\n")}", dest
564
582
  end
565
583
  respond help_message.scan(/#\s*help\s*:(.*)/).join("\n"), dest
566
584
  end
@@ -645,7 +663,7 @@ class SlackSmartBot
645
663
  #help: `stop using rules from CHANNEL`
646
664
  #help: it will stop using the rules from the specified channel.
647
665
  #help:
648
- when /^stop using rules (from\s+)<#C\w+\|(.+)>/i, /^stop using rules (from\s+)(.+)/i
666
+ when /^stop using rules (from\s+)<#\w+\|(.+)>/i, /^stop using rules (from\s+)(.+)/i
649
667
  channel = $2
650
668
  if @channels_id.key?(channel)
651
669
  channel_id = @channels_id[channel]
@@ -719,7 +737,7 @@ class SlackSmartBot
719
737
  respond "Only admin users can kill me", dest
720
738
  end
721
739
  else
722
- respond "To do this you need to be an admin user in the master channel: <##{@channels_id[MASTER_CHANNEL]}>", dest
740
+ respond "To do this you need to be an admin user in the master channel: <##{@master_bot_id}>", dest
723
741
  end
724
742
 
725
743
  #helpadmin: ----------------------------------------------
@@ -770,7 +788,9 @@ class SlackSmartBot
770
788
  if version_remote != VERSION
771
789
  version_message = " There is a new available version: #{version_remote}."
772
790
  end
773
- respond "Status: #{@status}. Version: #{VERSION}.#{version_message} Rules file: #{File.basename RULES_FILE} ", dest
791
+ require 'socket'
792
+ ip_address = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
793
+ respond "*#{Socket.gethostname} (#{ip_address})*\n\tStatus: #{@status}.\n\tVersion: #{VERSION}.#{version_message}\n\tRules file: #{File.basename RULES_FILE} ", dest
774
794
  if @status == :on
775
795
  respond "I'm listening to [#{@listening.join(", ")}]", dest
776
796
  if ON_MASTER_BOT and ADMIN_USERS.include?(from)
@@ -909,7 +929,7 @@ class SlackSmartBot
909
929
  else
910
930
  @logger.info MASTER_CHANNEL
911
931
  @logger.info @channel_id.inspect
912
- respond "Sorry I cannot create bots from this channel, please visit the master channel: <##{@channels_id[MASTER_CHANNEL]}>", dest
932
+ respond "Sorry I cannot create bots from this channel, please visit the master channel: <##{@master_bot_id}>", dest
913
933
  end
914
934
 
915
935
  #helpmaster: ----------------------------------------------
@@ -947,7 +967,7 @@ class SlackSmartBot
947
967
  respond "There is no bot in this channel: #{channel}", dest
948
968
  end
949
969
  else
950
- respond "Sorry I cannot kill bots from this channel, please visit the master channel: <##{@channels_id[MASTER_CHANNEL]}>", dest
970
+ respond "Sorry I cannot kill bots from this channel, please visit the master channel: <##{@master_bot_id}>", dest
951
971
  end
952
972
 
953
973
 
@@ -986,7 +1006,7 @@ class SlackSmartBot
986
1006
  when /^bot\s+rules$/i
987
1007
  if typem == :on_extended or typem == :on_call #for the other cases above.
988
1008
  help_message_rules = ''
989
- message = "-\n\n\n===================================\n*Rules from channel <##{@channels_id[CHANNEL]}>*\n"
1009
+ message = "-\n\n\n===================================\n*Rules from channel #{CHANNEL}*\n"
990
1010
  if typem == :on_extended
991
1011
  message += "To run the commands on this extended channel, add `!` before the command.\n"
992
1012
  end
@@ -1042,7 +1062,7 @@ class SlackSmartBot
1042
1062
  respond "The channel you specified doesn't exist", dest
1043
1063
  elsif @bots_created.key?(@channels_id[channel])
1044
1064
  respond "There is a bot already running on that channel.", dest
1045
- elsif @bots_created[@channels_id[CHANNEL]][:extended].include?(channel)
1065
+ elsif @bots_created[@channel_id][:extended].include?(channel)
1046
1066
  respond "The rules are already extended to that channel.", dest
1047
1067
  elsif !members.include?(config[:nick_id])
1048
1068
  respond "You need to add first to the channel the smart bot user: #{config[:nick]}", dest
@@ -1052,11 +1072,12 @@ class SlackSmartBot
1052
1072
  channels_in_use.each do |channel_in_use|
1053
1073
  respond "The rules from channel <##{@channels_id[channel_in_use]}> are already in use on that channel", dest
1054
1074
  end
1055
- @bots_created[@channels_id[CHANNEL]][:extended] = [] unless @bots_created[@channels_id[CHANNEL]].key?(:extended)
1056
- @bots_created[@channels_id[CHANNEL]][:extended] << channel
1075
+ @bots_created[@channel_id][:extended] = [] unless @bots_created[@channel_id].key?(:extended)
1076
+ @bots_created[@channel_id][:extended] << channel
1057
1077
  update_bots_file()
1058
- respond "Now the rules from <##{@channels_id[CHANNEL]}> are available on <##{@channels_id[channel]}>", dest
1059
- respond "<@#{user.id}> extended the rules from <##{@channels_id[CHANNEL]}> to this channel so now you can talk to the Smart Bot on demand using those rules.", @channels_id[channel]
1078
+ respond "<@#{user.id}> extended the rules from #{CHANNEL} to be used on #{channel}.", @master_bot_id
1079
+ respond "Now the rules from <##{@channel_id}> are available on <##{@channels_id[channel]}>", dest
1080
+ respond "<@#{user.id}> extended the rules from <##{@channel_id}> to this channel so now you can talk to the Smart Bot on demand using those rules.", @channels_id[channel]
1060
1081
  respond "Use `!` before the command you want to run", @channels_id[channel]
1061
1082
  respond "To see the specific rules for this bot on this channel: `!bot rules`", @channels_id[channel]
1062
1083
  end
@@ -1067,20 +1088,21 @@ class SlackSmartBot
1067
1088
  #helpadmin: `stop using rules on CHANNEL_NAME`
1068
1089
  #helpadmin: it will stop using the extended rules on the specified channel.
1069
1090
  #helpadmin:
1070
- when /^stop using rules (on\s+)<#C\w+\|(.+)>/i, /^stop using rules (on\s+)(.+)/i
1091
+ when /^stop using rules (on\s+)<#\w+\|(.+)>/i, /^stop using rules (on\s+)(.+)/i
1071
1092
  unless typem == :on_extended
1072
1093
  if !ADMIN_USERS.include?(from) #not admin
1073
1094
  respond "Only admins can extend or stop using the rules. Admins on this channel: #{ADMIN_USERS}", dest
1074
1095
  else
1075
1096
  channel = $2
1076
1097
  get_bots_created()
1077
- if @bots_created[@channels_id[CHANNEL]][:extended].include?(channel)
1078
- @bots_created[@channels_id[CHANNEL]][:extended].delete(channel)
1098
+ if @bots_created[@channel_id][:extended].include?(channel)
1099
+ @bots_created[@channel_id][:extended].delete(channel)
1079
1100
  update_bots_file()
1080
- respond "The rules won't be accessible from <##{@channels_id[CHANNEL]}> from now on.", dest
1081
- respond "<@#{user.id}> removed the access to the rules of <##{@channels_id[CHANNEL]}> from this channel.", @channels_id[channel]
1101
+ respond "<@#{user.id}> removed the access to the rules of #{CHANNEL} from #{channel}.", @master_bot_id
1102
+ respond "The rules won't be accessible from <##{@channels_id[channel]}> from now on.", dest
1103
+ respond "<@#{user.id}> removed the access to the rules of <##{@channel_id}> from this channel.", @channels_id[channel]
1082
1104
  else
1083
- respond "The rules were not accessible from <##{@channels_id[channel]}>", dest
1105
+ respond "The rules were not accessible from #{@channels_id[channel]}", dest
1084
1106
  end
1085
1107
  end
1086
1108
  end
@@ -1284,7 +1306,7 @@ class SlackSmartBot
1284
1306
 
1285
1307
  def respond(msg, dest = nil)
1286
1308
  if dest.nil?
1287
- client.message(channel: @channels_id[CHANNEL], text: msg, as_user: true)
1309
+ client.message(channel: @channel_id, text: msg, as_user: true)
1288
1310
  elsif dest[0] == "C" or dest[0] == "G" # channel
1289
1311
  client.message(channel: dest, text: msg, as_user: true)
1290
1312
  elsif dest[0] == "D" # Direct message
@@ -1298,7 +1320,7 @@ class SlackSmartBot
1298
1320
  #to: user that should answer
1299
1321
  def ask(question, context, to, dest = nil)
1300
1322
  if dest.nil?
1301
- client.message(channel: @channels_id[CHANNEL], text: "#{to}: #{question}", as_user: true)
1323
+ client.message(channel: @channel_id, text: "#{to}: #{question}", as_user: true)
1302
1324
  elsif dest[0] == "C" or dest[0] == "G" # channel
1303
1325
  client.message(channel: dest, text: "#{to}: #{question}", as_user: true)
1304
1326
  elsif dest[0] == "D" #private message
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.9.3
4
+ version: 0.9.4
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-08-28 00:00:00.000000000 Z
11
+ date: 2019-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client