slack-smart-bot 1.8.1 → 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 +127 -21
- data/lib/slack/smart-bot/comm/ask.rb +55 -42
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +34 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +35 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +38 -8
- data/lib/slack/smart-bot/comm/respond.rb +219 -48
- 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 +24 -7
- data/lib/slack/smart-bot/comm.rb +7 -1
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +68 -28
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +314 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +3 -5
- 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 +13 -16
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +67 -38
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +49 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -1
- 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 +12 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -1
- 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 +3 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +54 -25
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +7 -9
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +55 -25
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +36 -13
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +29 -13
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +55 -9
- 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 +5 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- 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 +49 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +30 -21
- data/lib/slack/smart-bot/commands.rb +19 -1
- data/lib/slack/smart-bot/listen.rb +7 -8
- data/lib/slack/smart-bot/process.rb +373 -192
- data/lib/slack/smart-bot/process_first.rb +202 -104
- data/lib/slack/smart-bot/treat_message.rb +325 -186
- data/lib/slack/smart-bot/utils/answer.rb +18 -0
- data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
- data/lib/slack/smart-bot/utils/build_help.rb +57 -5
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +83 -30
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +87 -35
- 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 +23 -8
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/lib/slack/smart-bot/utils.rb +5 -0
- data/lib/slack-smart-bot.rb +88 -47
- 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 +49 -23
- data/whats_new.txt +36 -0
- metadata +44 -13
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
@@ -7,42 +7,46 @@ class SlackSmartBot
|
|
7
7
|
#send_file(dest, 'the message', "myfile.rb", 'message to be sent', 'text/plain', "ruby", content: "the content to be sent when no file supplied")
|
8
8
|
def send_file(to, msg, file, title, format, type = "text", content: '')
|
9
9
|
unless config[:simulate]
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
begin
|
11
|
+
file = 'myfile' if file.to_s == '' and content!=''
|
12
|
+
if to[0] == "U" or to[0] == "W" #user
|
13
|
+
im = client.web_client.conversations_open(users: id_user)
|
14
|
+
channel = im["channel"]["id"]
|
15
|
+
else
|
16
|
+
channel = to
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
if Thread.current[:on_thread]
|
20
|
+
ts = Thread.current[:thread_ts]
|
21
|
+
else
|
22
|
+
ts = nil
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
25
|
+
if content.to_s == ''
|
26
|
+
client.web_client.files_upload(
|
27
|
+
channels: channel,
|
28
|
+
as_user: true,
|
29
|
+
file: Faraday::UploadIO.new(file, format),
|
30
|
+
title: title,
|
31
|
+
filename: file,
|
32
|
+
filetype: type,
|
33
|
+
initial_comment: msg,
|
34
|
+
thread_ts: ts
|
35
|
+
)
|
36
|
+
else
|
37
|
+
client.web_client.files_upload(
|
38
|
+
channels: channel,
|
39
|
+
as_user: true,
|
40
|
+
content: content,
|
41
|
+
title: title,
|
42
|
+
filename: file,
|
43
|
+
filetype: type,
|
44
|
+
initial_comment: msg,
|
45
|
+
thread_ts: ts
|
46
|
+
)
|
47
|
+
end
|
48
|
+
rescue Exception => stack
|
49
|
+
@logger.warn stack
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
@@ -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]}|#{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]}|#{msg}"
|
39
|
-
}
|
40
|
-
end
|
64
|
+
rescue Exception => stack
|
65
|
+
@logger.warn stack
|
41
66
|
end
|
42
67
|
end
|
43
68
|
end
|
@@ -1,14 +1,31 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
# list of available emojis: https://www.webfx.com/tools/emoji-cheat-sheet/
|
3
3
|
# unreact(:thumbsup)
|
4
|
-
|
5
|
-
|
6
|
-
ts = Thread.current[:thread_ts]
|
7
|
-
else
|
8
|
-
ts = Thread.current[:ts]
|
9
|
-
end
|
4
|
+
# ts: can be true, false or a specific ts
|
5
|
+
def unreact(emoji, ts=false)
|
10
6
|
begin
|
11
|
-
|
7
|
+
if ts.is_a?(TrueClass) or ts.is_a?(FalseClass)
|
8
|
+
parent = ts
|
9
|
+
ts = nil
|
10
|
+
else
|
11
|
+
parent = false
|
12
|
+
end
|
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
|
28
|
+
end
|
12
29
|
rescue Exception => stack
|
13
30
|
@logger.warn stack
|
14
31
|
end
|
data/lib/slack/smart-bot/comm.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
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'
|
6
7
|
require_relative 'comm/send_msg_channel'
|
7
8
|
require_relative 'comm/send_msg_user'
|
8
9
|
require_relative 'comm/react'
|
9
|
-
require_relative 'comm/unreact'
|
10
|
+
require_relative 'comm/unreact'
|
11
|
+
require_relative 'comm/get_user_info'
|
12
|
+
require_relative 'comm/get_users'
|
13
|
+
require_relative 'comm/event_hello'
|
14
|
+
require_relative 'comm/get_channel_members'
|
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,51 +1,77 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# help: `bot rules COMMAND`
|
8
|
-
# help: `bot what can I do?`
|
9
|
-
# help: it will display this help
|
10
|
-
# help: if COMMAND supplied just help for that command
|
11
|
-
# help: `bot rules` will show only the specific rules for this channel.
|
12
|
-
# help:
|
13
|
-
def bot_help(user, from, dest, dchannel, specific, help_command, rules_file)
|
14
|
-
save_stats(__method__)
|
15
|
-
if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
|
16
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
17
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
18
|
-
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)
|
19
7
|
help_found = false
|
20
8
|
|
21
9
|
message = ""
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
if help_command.to_s != ''
|
11
|
+
help_command = '' if help_command.to_s.match?(/^\s*expanded\s*$/i) or help_command.to_s.match?(/^\s*extended\s*$/i)
|
12
|
+
expanded = true
|
13
|
+
message_not_expanded = ''
|
14
|
+
else
|
15
|
+
expanded = false
|
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"
|
18
|
+
end
|
19
|
+
help_message = get_help(rules_file, dest, from, specific, expanded)
|
20
|
+
commands = []
|
21
|
+
commands_search = []
|
25
22
|
if help_command.to_s != ""
|
26
23
|
help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).each do |h|
|
27
|
-
if h.match?(/[`_]#{help_command}/i)
|
28
|
-
|
24
|
+
if h.match?(/[`_]#{help_command}/i) or h.match?(/^\s*command_id:\s+:#{help_command.gsub(' ', '_')}\s*$/)
|
25
|
+
output << h
|
29
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
|
30
38
|
end
|
31
39
|
end
|
32
40
|
else
|
33
41
|
if Thread.current[:using_channel]!=''
|
34
|
-
message
|
42
|
+
message += "*You are using rules from another channel: <##{Thread.current[:using_channel]}>. These are the specific commands for that channel:*"
|
35
43
|
end
|
36
|
-
|
44
|
+
output << message
|
37
45
|
end
|
38
46
|
|
39
47
|
if (help_command.to_s == "")
|
40
48
|
help_message.split(/^\s*=========*$/).each do |h|
|
41
|
-
|
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
|
42
59
|
end
|
43
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
|
44
70
|
unless help_found
|
45
71
|
if specific
|
46
|
-
|
72
|
+
output << "I didn't find any rule with `#{help_command}`"
|
47
73
|
else
|
48
|
-
|
74
|
+
output << "I didn't find any command with `#{help_command}`"
|
49
75
|
end
|
50
76
|
end
|
51
77
|
end
|
@@ -57,7 +83,7 @@ class SlackSmartBot
|
|
57
83
|
end
|
58
84
|
end
|
59
85
|
if defined?(git_project) && (git_project.to_s != "") && (help_command.to_s == "")
|
60
|
-
|
86
|
+
output << "Git project: #{git_project}"
|
61
87
|
else
|
62
88
|
def git_project
|
63
89
|
""
|
@@ -68,8 +94,22 @@ class SlackSmartBot
|
|
68
94
|
end
|
69
95
|
end
|
70
96
|
elsif help_command.to_s == ""
|
71
|
-
|
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
|
72
111
|
end
|
73
112
|
end
|
113
|
+
return output.join("\n")
|
74
114
|
end
|
75
115
|
end
|