slack-smart-bot 0.9.3 → 0.9.4
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/lib/slack-smart-bot.rb +42 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f525626c08342efb47771ac63104863aee616dfe45b428f09c48be94d855cd0
|
4
|
+
data.tar.gz: 8cf17f028da036a7b15c418b13a5e7f8011bb3359b15b8a1d02c88e6962cb379
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f6b5afdcfc4cfc199e272a4f0723865d4e68dd9e4242d73d88a3f8d4051575aca028bf53215b0261243743b00f7f467842f484f423daa2a0407cb69ccde59ed
|
7
|
+
data.tar.gz: c652cdad1b97ab090131f9baf3a9f5f4f6796a8a751052285f38329a390fc8d601dc4170acaefc18479593e8359724212d17cc2b589e1fcabe68103b15d87e81
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -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 <##{@
|
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+)
|
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: <##{@
|
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
|
-
|
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: <##{@
|
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: <##{@
|
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
|
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[@
|
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[@
|
1056
|
-
@bots_created[@
|
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 "
|
1059
|
-
respond "
|
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+)
|
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[@
|
1078
|
-
@bots_created[@
|
1098
|
+
if @bots_created[@channel_id][:extended].include?(channel)
|
1099
|
+
@bots_created[@channel_id][:extended].delete(channel)
|
1079
1100
|
update_bots_file()
|
1080
|
-
respond "
|
1081
|
-
respond "
|
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
|
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: @
|
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: @
|
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.
|
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-
|
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
|