slack-smart-bot 1.9.2 → 1.10.0
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/README.md +109 -11
- data/lib/slack/smart-bot/comm/ask.rb +55 -49
- data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
- data/lib/slack/smart-bot/comm/event_hello.rb +7 -3
- data/lib/slack/smart-bot/comm/get_channel_members.rb +9 -4
- data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
- data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +19 -2
- data/lib/slack/smart-bot/comm/respond.rb +217 -72
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
- data/lib/slack/smart-bot/comm/unreact.rb +22 -18
- data/lib/slack/smart-bot/comm.rb +2 -0
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +59 -32
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +10 -9
- data/lib/slack/smart-bot/commands/general/bot_status.rb +2 -4
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
- data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
- data/lib/slack/smart-bot/commands/general/use_rules.rb +7 -7
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -5
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +32 -11
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +4 -5
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +3 -5
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +2 -4
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +2 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +8 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +27 -14
- data/lib/slack/smart-bot/commands.rb +16 -0
- data/lib/slack/smart-bot/listen.rb +1 -3
- data/lib/slack/smart-bot/process.rb +212 -74
- data/lib/slack/smart-bot/process_first.rb +118 -37
- data/lib/slack/smart-bot/treat_message.rb +313 -248
- data/lib/slack/smart-bot/utils/build_help.rb +3 -3
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_help.rb +58 -68
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/has_access.rb +12 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +2 -0
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils.rb +3 -0
- data/lib/slack-smart-bot.rb +45 -4
- data/lib/slack-smart-bot_general_commands.rb +46 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +43 -17
- data/whats_new.txt +32 -20
- metadata +24 -2
@@ -2,31 +2,36 @@ class SlackSmartBot
|
|
2
2
|
|
3
3
|
# to: (String) Channel name or id
|
4
4
|
# msg: (String) message to send
|
5
|
-
def send_msg_channel(to, msg)
|
5
|
+
def send_msg_channel(to, msg, unfurl_links: true, unfurl_media: true)
|
6
6
|
unless msg == ""
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@logger.fatal "Channel: #{to} not found. Message: #{msg}"
|
14
|
-
end
|
15
|
-
if config[:simulate]
|
16
|
-
open("#{config.path}/buffer_complete.log", "a") { |f|
|
17
|
-
f.puts "|#{channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{msg}~~~"
|
18
|
-
}
|
19
|
-
else
|
20
|
-
if Thread.current[:on_thread]
|
21
|
-
client.message(channel: channel_id, text: msg, as_user: true, thread_ts: Thread.current[:thread_ts])
|
7
|
+
begin
|
8
|
+
get_channels_name_and_id() unless @channels_name.key?(to) or @channels_id.key?(to)
|
9
|
+
if @channels_name.key?(to) #it is an id
|
10
|
+
channel_id = to
|
11
|
+
elsif @channels_id.key?(to) #it is a channel name
|
12
|
+
channel_id = @channels_id[to]
|
22
13
|
else
|
23
|
-
|
14
|
+
@logger.fatal "Channel: #{to} not found. Message: #{msg}"
|
24
15
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
if config[:simulate]
|
17
|
+
open("#{config.path}/buffer_complete.log", "a") { |f|
|
18
|
+
f.puts "|#{channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{msg}~~~"
|
19
|
+
}
|
20
|
+
else
|
21
|
+
if Thread.current[:on_thread]
|
22
|
+
client.message(channel: channel_id, text: msg, as_user: true, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
23
|
+
else
|
24
|
+
client.message(channel: channel_id, text: msg, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
if config[:testing] and config.on_master_bot and !@buffered
|
28
|
+
@buffered = true
|
29
|
+
open("#{config.path}/buffer.log", "a") { |f|
|
30
|
+
f.puts "|#{channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{msg}"
|
31
|
+
}
|
32
|
+
end
|
33
|
+
rescue Exception => stack
|
34
|
+
@logger.warn stack
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -1,43 +1,68 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
3
|
#to send messages without listening for a response to users
|
4
|
-
def send_msg_user(id_user, msg)
|
5
|
-
unless msg == ""
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_media: true, blocks: [])
|
5
|
+
unless msg == "" and blocks.empty?
|
6
|
+
begin
|
7
|
+
on_thread = Thread.current[:on_thread] if on_thread.nil?
|
8
|
+
(!unfurl_links or !unfurl_media) ? web_client = true : web_client = false
|
9
|
+
web_client = true if !blocks.empty?
|
10
|
+
if id_user[0] == "D"
|
11
|
+
if config[:simulate]
|
12
|
+
open("#{config.path}/buffer_complete.log", "a") { |f|
|
13
|
+
f.puts "|#{id_user}|#{config[:nick_id]}|#{config[:nick]}|#{msg}~~~"
|
14
|
+
}
|
14
15
|
else
|
15
|
-
|
16
|
+
if web_client
|
17
|
+
if on_thread
|
18
|
+
client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
|
19
|
+
else
|
20
|
+
client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
if on_thread
|
24
|
+
client.message(channel: id_user, as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
25
|
+
else
|
26
|
+
client.message(channel: id_user, as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
27
|
+
end
|
28
|
+
end
|
16
29
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
if config[:testing] and config.on_master_bot and !@buffered
|
31
|
+
@buffered = true
|
32
|
+
open("#{config.path}/buffer.log", "a") { |f|
|
33
|
+
f.puts "|#{id_user}|#{config[:nick_id]}|#{config[:nick]}|#{msg}#{blocks.join}"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
else
|
37
|
+
if config[:simulate]
|
38
|
+
open("#{config.path}/buffer_complete.log", "a") { |f|
|
39
|
+
f.puts "|#{DIRECT[id_user.to_sym].ubot}|#{config[:nick_id]}|#{config[:nick]}|#{msg}#{blocks.join}~~~"
|
40
|
+
}
|
41
|
+
else
|
42
|
+
im = client.web_client.conversations_open(users: id_user)
|
43
|
+
if web_client
|
44
|
+
if on_thread
|
45
|
+
client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
|
46
|
+
else
|
47
|
+
client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
if on_thread
|
51
|
+
client.message(channel: im["channel"]["id"], as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
52
|
+
else
|
53
|
+
client.message(channel: im["channel"]["id"], as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
if config[:testing] and config.on_master_bot and !@buffered
|
58
|
+
@buffered = true
|
59
|
+
open("#{config.path}/buffer.log", "a") { |f|
|
60
|
+
f.puts "|#{im["channel"]["id"]}|#{config[:nick_id]}|#{config[:nick]}|#{msg}#{blocks.join}"
|
61
|
+
}
|
34
62
|
end
|
35
63
|
end
|
36
|
-
|
37
|
-
|
38
|
-
f.puts "|#{im["channel"]["id"]}|#{config[:nick_id]}|#{config[:nick]}|#{msg}"
|
39
|
-
}
|
40
|
-
end
|
64
|
+
rescue Exception => stack
|
65
|
+
@logger.warn stack
|
41
66
|
end
|
42
67
|
end
|
43
68
|
end
|
@@ -3,27 +3,31 @@ class SlackSmartBot
|
|
3
3
|
# unreact(:thumbsup)
|
4
4
|
# ts: can be true, false or a specific ts
|
5
5
|
def unreact(emoji, ts=false)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
parent = false
|
11
|
-
end
|
12
|
-
if ts.nil?
|
13
|
-
if parent or Thread.current[:ts].to_s == ''
|
14
|
-
ts = Thread.current[:thread_ts]
|
6
|
+
begin
|
7
|
+
if ts.is_a?(TrueClass) or ts.is_a?(FalseClass)
|
8
|
+
parent = ts
|
9
|
+
ts = nil
|
15
10
|
else
|
16
|
-
|
11
|
+
parent = false
|
17
12
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
if ts.nil?
|
14
|
+
if parent or Thread.current[:ts].to_s == ''
|
15
|
+
ts = Thread.current[:thread_ts]
|
16
|
+
else
|
17
|
+
ts = Thread.current[:ts]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
if ts.nil?
|
21
|
+
@logger.warn 'unreact method no ts supplied'
|
22
|
+
else
|
23
|
+
begin
|
24
|
+
client.web_client.reactions_remove(channel: Thread.current[:dest], name: emoji, timestamp: ts) unless config.simulate
|
25
|
+
rescue Exception => stack
|
26
|
+
@logger.warn stack
|
27
|
+
end
|
26
28
|
end
|
29
|
+
rescue Exception => stack
|
30
|
+
@logger.warn stack
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
data/lib/slack/smart-bot/comm.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'comm/ask'
|
2
2
|
require_relative 'comm/dont_understand'
|
3
|
+
require_relative 'comm/respond_thread'
|
3
4
|
require_relative 'comm/respond_direct'
|
4
5
|
require_relative 'comm/respond'
|
5
6
|
require_relative 'comm/send_file'
|
@@ -8,6 +9,7 @@ require_relative 'comm/send_msg_user'
|
|
8
9
|
require_relative 'comm/react'
|
9
10
|
require_relative 'comm/unreact'
|
10
11
|
require_relative 'comm/get_user_info'
|
12
|
+
require_relative 'comm/get_users'
|
11
13
|
require_relative 'comm/event_hello'
|
12
14
|
require_relative 'comm/get_channel_members'
|
13
15
|
require_relative 'comm/get_channels'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
def add_announcement(user, type, message)
|
4
|
+
save_stats(__method__)
|
5
|
+
if has_access?(__method__, user)
|
6
|
+
if Thread.current[:typem] == :on_call
|
7
|
+
channel = Thread.current[:dchannel]
|
8
|
+
else
|
9
|
+
channel = Thread.current[:dest]
|
10
|
+
end
|
11
|
+
if File.exists?("#{config.path}/announcements/#{channel}.csv") and !@announcements.key?(channel)
|
12
|
+
t = CSV.table("#{config.path}/announcements/#{channel}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
|
13
|
+
@announcements[channel] = t
|
14
|
+
num = t[:message_id].max + 1
|
15
|
+
elsif !@announcements.key?(channel)
|
16
|
+
File.open("#{config.path}/announcements/#{channel}.csv","w")
|
17
|
+
t = CSV.table("#{config.path}/announcements/#{channel}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
|
18
|
+
num = 1
|
19
|
+
@announcements[channel] = t
|
20
|
+
else
|
21
|
+
num = @announcements[channel][:message_id].max + 1
|
22
|
+
end
|
23
|
+
values = [num, '', user.name, Time.now.strftime("%Y/%m/%d"), Time.now.strftime("%H:%M"), type, message]
|
24
|
+
@announcements[channel] << values
|
25
|
+
CSV.open("#{config.path}/announcements/#{channel}.csv", "a+") do |csv|
|
26
|
+
csv << values
|
27
|
+
end
|
28
|
+
respond "The announcement has been added. (id: #{num}).\nRelated commands `see announcements`, `delete announcement ID`"
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,24 +1,9 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# help: `bot rules COMMAND`
|
8
|
-
# help: `bot help expanded`
|
9
|
-
# help: `bot rules expanded`
|
10
|
-
# help: `bot what can I do?`
|
11
|
-
# help: it will display this help. For a more detailed help call `bot help expanded` or `bot rules expanded`.
|
12
|
-
# help: if COMMAND supplied just help for that command
|
13
|
-
# help: you can use the option 'expanded' or the alias 'extended'
|
14
|
-
# help: `bot rules` will show only the specific rules for this channel.
|
15
|
-
# help:
|
16
|
-
def bot_help(user, from, dest, dchannel, specific, help_command, rules_file)
|
17
|
-
save_stats(__method__)
|
18
|
-
if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
|
19
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
20
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
21
|
-
else
|
3
|
+
def bot_help(user, from, dest, dchannel, specific, help_command, rules_file, savestats=true)
|
4
|
+
save_stats(__method__) if savestats
|
5
|
+
output = []
|
6
|
+
if has_access?(__method__, user)
|
22
7
|
help_found = false
|
23
8
|
|
24
9
|
message = ""
|
@@ -28,36 +13,65 @@ class SlackSmartBot
|
|
28
13
|
message_not_expanded = ''
|
29
14
|
else
|
30
15
|
expanded = false
|
31
|
-
message_not_expanded = "
|
32
|
-
message_not_expanded += "
|
16
|
+
message_not_expanded = "If you want to see the *expanded* version of *`bot help`* or *`bot rules`*, please call *`bot help expanded`* or *`bot rules expanded`*\n"
|
17
|
+
message_not_expanded += "Also to get specific *expanded* help for a specific command or rule call *`bot help COMMAND`*\n"
|
33
18
|
end
|
34
|
-
|
35
19
|
help_message = get_help(rules_file, dest, from, specific, expanded)
|
36
|
-
|
20
|
+
commands = []
|
21
|
+
commands_search = []
|
37
22
|
if help_command.to_s != ""
|
38
23
|
help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).each do |h|
|
39
|
-
if h.match?(/[`_]#{help_command}/i)
|
40
|
-
|
24
|
+
if h.match?(/[`_]#{help_command}/i) or h.match?(/^\s*command_id:\s+:#{help_command.gsub(' ', '_')}\s*$/)
|
25
|
+
output << h
|
41
26
|
help_found = true
|
27
|
+
commands << h
|
28
|
+
elsif !h.match?(/\A\s*\*/) and !h.match?(/\A\s*=+/) #to avoid general messages for bot help *General commands...*
|
29
|
+
all_found = true
|
30
|
+
help_command.to_s.split(' ') do |hc|
|
31
|
+
unless hc.match?(/^\s*\z/)
|
32
|
+
if !h.match?(/#{hc}/i)
|
33
|
+
all_found = false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
commands_search << h if all_found
|
42
38
|
end
|
43
39
|
end
|
44
40
|
else
|
45
41
|
if Thread.current[:using_channel]!=''
|
46
42
|
message += "*You are using rules from another channel: <##{Thread.current[:using_channel]}>. These are the specific commands for that channel:*"
|
47
43
|
end
|
48
|
-
|
44
|
+
output << message
|
49
45
|
end
|
50
46
|
|
51
47
|
if (help_command.to_s == "")
|
52
48
|
help_message.split(/^\s*=========*$/).each do |h|
|
53
|
-
|
49
|
+
unless h.match?(/\A\s*\z/)
|
50
|
+
output << "#{"=" * 35}\n#{h}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
if Thread.current[:typem] == :on_pg or Thread.current[:typem] == :on_pub
|
54
|
+
if @bots_created.size>0
|
55
|
+
txt = "\nThese are the *SmartBots* running on this Slack workspace: *<##{@master_bot_id}>, <##{@bots_created.keys.join('>, <#')}>*\n"
|
56
|
+
txt += "Join one channel and call *`bot rules`* to see specific commands for that channel or *`bot help`* to see all commands for that channel.\n"
|
57
|
+
output << txt
|
58
|
+
end
|
54
59
|
end
|
55
60
|
else
|
61
|
+
if commands.size < 10 and help_command.to_s!='' and commands_search.size > 0
|
62
|
+
commands_search.shuffle!
|
63
|
+
(10-commands.size).times do |n|
|
64
|
+
unless commands_search[n].nil?
|
65
|
+
output << commands_search[n]
|
66
|
+
help_found = true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
56
70
|
unless help_found
|
57
71
|
if specific
|
58
|
-
|
72
|
+
output << "I didn't find any rule with `#{help_command}`"
|
59
73
|
else
|
60
|
-
|
74
|
+
output << "I didn't find any command with `#{help_command}`"
|
61
75
|
end
|
62
76
|
end
|
63
77
|
end
|
@@ -69,7 +83,7 @@ class SlackSmartBot
|
|
69
83
|
end
|
70
84
|
end
|
71
85
|
if defined?(git_project) && (git_project.to_s != "") && (help_command.to_s == "")
|
72
|
-
|
86
|
+
output << "Git project: #{git_project}"
|
73
87
|
else
|
74
88
|
def git_project
|
75
89
|
""
|
@@ -80,9 +94,22 @@ class SlackSmartBot
|
|
80
94
|
end
|
81
95
|
end
|
82
96
|
elsif help_command.to_s == ""
|
83
|
-
|
97
|
+
output << "Slack Smart Bot Github project: https://github.com/MarioRuiz/slack-smart-bot"
|
98
|
+
end
|
99
|
+
unless expanded
|
100
|
+
output << message_not_expanded
|
101
|
+
end
|
102
|
+
end
|
103
|
+
if output.join("\n").lines.count > 50 and dest[0]!='D'
|
104
|
+
dest = :on_thread
|
105
|
+
output.unshift('Since there are many lines returned the results are returned on a thread by default.')
|
106
|
+
end
|
107
|
+
output.each do |h|
|
108
|
+
msg = h.gsub(/^\s*command_id:\s+:\w+\s*$/,'')
|
109
|
+
unless msg.match?(/\A\s*\z/)
|
110
|
+
respond msg, dest, unfurl_links: false, unfurl_media: false
|
84
111
|
end
|
85
|
-
respond message_not_expanded unless expanded
|
86
112
|
end
|
113
|
+
return output.join("\n")
|
87
114
|
end
|
88
115
|
end
|
@@ -28,6 +28,7 @@ class SlackSmartBot
|
|
28
28
|
# help: _bot stats #sales today_
|
29
29
|
# help: _bot stats #sales from 2020-01-01 monthly_
|
30
30
|
# help: _bot stats exclude routines masters from 2021/01/01 monthly_
|
31
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
31
32
|
# help:
|
32
33
|
def bot_stats(dest, from_user, typem, channel_id, from, to, user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data)
|
33
34
|
require 'csv'
|
@@ -81,16 +82,16 @@ class SlackSmartBot
|
|
81
82
|
end
|
82
83
|
|
83
84
|
if user!=''
|
84
|
-
user_info =
|
85
|
-
if users_id_name.key?(user_info.
|
86
|
-
user_name = users_id_name[user_info.
|
85
|
+
user_info = @users.select{|u| u.id == user or (u.key?(:enterprise_user) and u.enterprise_user.id == user)}[-1]
|
86
|
+
if users_id_name.key?(user_info.id)
|
87
|
+
user_name = users_id_name[user_info.id]
|
87
88
|
else
|
88
|
-
user_name = user_info.
|
89
|
+
user_name = user_info.name
|
89
90
|
end
|
90
|
-
if users_name_id.key?(user_info.
|
91
|
-
user_id = users_name_id[user_info.
|
91
|
+
if users_name_id.key?(user_info.name)
|
92
|
+
user_id = users_name_id[user_info.name]
|
92
93
|
else
|
93
|
-
user_id = user_info.
|
94
|
+
user_id = user_info.id
|
94
95
|
end
|
95
96
|
end
|
96
97
|
master_admins = config.masters.dup
|
@@ -105,7 +106,7 @@ class SlackSmartBot
|
|
105
106
|
end
|
106
107
|
|
107
108
|
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
108
|
-
if file >= "#{config.stats_path}.#{from_file}.log"
|
109
|
+
if file >= "#{config.stats_path}.#{from_file}.log" and file <= "#{config.stats_path}.#{to_file}.log"
|
109
110
|
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
110
111
|
row[:date] = row[:date].to_s
|
111
112
|
if row[:dest_channel_id].to_s[0]=='D'
|
@@ -125,7 +126,7 @@ class SlackSmartBot
|
|
125
126
|
if !exclude_routines or (exclude_routines and !row[:user_name].match?(/^routine\//) )
|
126
127
|
if exclude_command == '' or (exclude_command!='' and row[:command]!=exclude_command)
|
127
128
|
if st_command == '' or (st_command != '' and row[:command] == st_command)
|
128
|
-
if row[:bot_channel_id] == channel_id or channel_id == ''
|
129
|
+
if row[:bot_channel_id] == channel_id or channel_id == '' or row[:dest_channel_id] == channel_id
|
129
130
|
if row[:date] >= from and row[:date] <= to
|
130
131
|
count_users[row[:user_id]] ||= 0
|
131
132
|
count_users[row[:user_id]] += 1
|