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
@@ -18,16 +18,13 @@ class SlackSmartBot
|
|
18
18
|
# help: _sc spanish account_
|
19
19
|
# help: _shortcut Spanish Account_
|
20
20
|
# help: _Spanish Account_
|
21
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#shortcuts|more info>
|
21
22
|
# help:
|
22
23
|
def add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
|
23
24
|
save_stats(__method__)
|
24
25
|
unless typem == :on_extended
|
25
26
|
from = user.name
|
26
|
-
if
|
27
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
28
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
29
|
-
else
|
30
|
-
|
27
|
+
if has_access?(__method__, user)
|
31
28
|
if global
|
32
29
|
if !config.on_master_bot or typem != :on_master
|
33
30
|
respond "It is only possible to add global shortcuts from Master channel"
|
@@ -3,7 +3,9 @@ class SlackSmartBot
|
|
3
3
|
# helpadmin: `add routine NAME every NUMBER PERIOD COMMAND`
|
4
4
|
# helpadmin: `add routine NAME every NUMBER PERIOD #CHANNEL COMMAND`
|
5
5
|
# helpadmin: `add routine NAME every NUMBER PERIOD`
|
6
|
+
# helpadmin: `add bgroutine NAME every NUMBER PERIOD`
|
6
7
|
# helpadmin: `add silent routine NAME every NUMBER PERIOD`
|
8
|
+
# helpadmin: `add silent bgroutine NAME every NUMBER PERIOD`
|
7
9
|
# helpadmin: `create routine NAME every NUMBER PERIOD`
|
8
10
|
# helpadmin: `add routine NAME at TIME COMMAND`
|
9
11
|
# helpadmin: `add routine NAME at TIME #CHANNEL COMMAND`
|
@@ -14,23 +16,27 @@ class SlackSmartBot
|
|
14
16
|
# helpadmin: `create routine NAME at TIME`
|
15
17
|
# helpadmin: It will execute the command/rule supplied. Only for Admin and Master Admins.
|
16
18
|
# helpadmin: If no COMMAND supplied, then it will be necessary to attach a file with the code to be run and add this command as message to the file. ONLY for MASTER ADMINS.
|
19
|
+
# helpadmin: In case *bgroutine* then the results of the run won't be published. To see the results call: `see result routine NAME`
|
17
20
|
# helpadmin: In case *silent* provided then when executed will be only displayed if the routine returns a message
|
18
21
|
# helpadmin: NAME: one word to identify the routine
|
19
22
|
# helpadmin: NUMBER: Integer
|
20
23
|
# helpadmin: PERIOD: days, d, hours, h, minutes, mins, min, m, seconds, secs, sec, s
|
21
24
|
# helpadmin: TIME: time at format HH:MM:SS
|
22
|
-
# helpadmin: DAYWEEK: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. And their plurals.
|
25
|
+
# helpadmin: DAYWEEK: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. And their plurals. Also possible to be used 'weekdays' and 'weekends'
|
23
26
|
# helpadmin: #CHANNEL: the destination channel where the results will be published. If not supplied then the bot channel by default or a DM if the command is run from a DM.
|
24
27
|
# helpadmin: COMMAND: any valid smart bot command or rule
|
28
|
+
# helpadmin: It is possible to add a script directly. Only master admins can do it.
|
25
29
|
# helpadmin: Examples:
|
26
|
-
# helpadmin: _add routine example every 30s ruby puts 'a'_
|
27
|
-
# helpadmin: _add
|
28
|
-
# helpadmin: _add routine example at 17:05 ruby puts 'a'_
|
30
|
+
# helpadmin: _add routine example every 30s !ruby puts 'a'_
|
31
|
+
# helpadmin: _add bgroutine example every 3 days !ruby puts 'a'_
|
32
|
+
# helpadmin: _add routine example at 17:05 !ruby puts 'a'_
|
29
33
|
# helpadmin: _create silent routine Example every 12 hours !Run customer tests_
|
30
|
-
# helpadmin: _add
|
34
|
+
# helpadmin: _add bgroutine example on Mondays at 05:00 !run customer tests_
|
31
35
|
# helpadmin: _add routine example on Tuesdays at 09:00 #SREChannel !run db cleanup_
|
36
|
+
# helpadmin: _add routine example on weekdays at 22:00 suggest command_
|
37
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
|
32
38
|
# helpadmin:
|
33
|
-
def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel)
|
39
|
+
def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel, routine_type)
|
34
40
|
save_stats(__method__)
|
35
41
|
if files.nil? or files.size == 0 or (files.size > 0 and config.masters.include?(from))
|
36
42
|
if config.admins.include?(from)
|
@@ -61,8 +67,9 @@ class SlackSmartBot
|
|
61
67
|
every = "#{number_time} seconds"
|
62
68
|
every_in_seconds = number_time.to_i
|
63
69
|
else # time
|
64
|
-
if type != 'at'
|
70
|
+
if type != 'at' and type!='weekday' and type!='weekend'
|
65
71
|
dayweek = type.downcase
|
72
|
+
|
66
73
|
days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday']
|
67
74
|
incr = days.index(dayweek) - Time.now.wday
|
68
75
|
if incr < 0
|
@@ -72,6 +79,14 @@ class SlackSmartBot
|
|
72
79
|
end
|
73
80
|
days = incr/(24*60*60)
|
74
81
|
every_in_seconds = 7 * 24 * 60 * 60 # one week
|
82
|
+
elsif type=='weekend'
|
83
|
+
dayweek = type.downcase
|
84
|
+
days = 0
|
85
|
+
every_in_seconds = 24 * 60 * 60 # one day
|
86
|
+
elsif type=='weekday'
|
87
|
+
dayweek = type.downcase
|
88
|
+
days = 0
|
89
|
+
every_in_seconds = 24 * 60 * 60 # one day
|
75
90
|
else
|
76
91
|
days = 0
|
77
92
|
every_in_seconds = 24 * 60 * 60 # one day
|
@@ -95,8 +110,14 @@ class SlackSmartBot
|
|
95
110
|
if files[0].filetype == "ruby" and files[0].name.scan(/[^\.]+(\.\w+$)/).join == ''
|
96
111
|
file_path += ".rb"
|
97
112
|
end
|
98
|
-
|
99
|
-
|
113
|
+
if files[0].key?(:content)
|
114
|
+
File.open(file_path, 'w') do |f|
|
115
|
+
f.write files[0].content
|
116
|
+
end
|
117
|
+
else
|
118
|
+
http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" }, log_headers: :partial)
|
119
|
+
http.get(files[0].url_private_download, save_data: file_path)
|
120
|
+
end
|
100
121
|
system("chmod +x #{file_path}")
|
101
122
|
end
|
102
123
|
get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
|
@@ -114,10 +135,10 @@ class SlackSmartBot
|
|
114
135
|
every: every, every_in_seconds: every_in_seconds, at: at, dayweek: dayweek, file_path: file_path,
|
115
136
|
command: command_to_run.to_s.strip, silent: silent,
|
116
137
|
next_run: next_run.to_s, dest: channel_id, last_run: "", last_elapsed: "",
|
117
|
-
running: false }
|
138
|
+
running: false, routine_type: routine_type}
|
118
139
|
update_routines
|
119
140
|
respond "Added routine *`#{name}`* to the channel", dest
|
120
|
-
create_routine_thread(name)
|
141
|
+
create_routine_thread(name, @routines[@channel_id][name])
|
121
142
|
end
|
122
143
|
end
|
123
144
|
else
|
@@ -4,6 +4,7 @@ class SlackSmartBot
|
|
4
4
|
# helpadmin: `extend rules to CHANNEL_NAME`
|
5
5
|
# helpadmin: `use rules on CHANNEL_NAME`
|
6
6
|
# helpadmin: It will allow to use the specific rules from this channel on the CHANNEL_NAME
|
7
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#extending-rules-to-other-channels|more info>
|
7
8
|
# helpadmin:
|
8
9
|
def extend_rules(dest, user, from, channel, typem)
|
9
10
|
save_stats(__method__)
|
@@ -15,6 +16,7 @@ class SlackSmartBot
|
|
15
16
|
else
|
16
17
|
#todo: add pagination for case more than 1000 channels on the workspace
|
17
18
|
channels = get_channels()
|
19
|
+
channel = @channels_name[channel] if @channels_name.key?(channel)
|
18
20
|
|
19
21
|
channel_found = channels.detect { |c| c.name == channel }
|
20
22
|
get_channels_name_and_id()
|
@@ -5,6 +5,7 @@ class SlackSmartBot
|
|
5
5
|
# helpadmin: `pause this bot`
|
6
6
|
# helpadmin: the bot will pause so it will listen only to admin commands
|
7
7
|
# helpadmin: You can use this command only if you are an admin user
|
8
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
8
9
|
# helpadmin:
|
9
10
|
def pause_bot(dest, from)
|
10
11
|
save_stats(__method__)
|
@@ -12,11 +13,12 @@ class SlackSmartBot
|
|
12
13
|
respond "This bot is paused from now on. You can start it again: start this bot", dest
|
13
14
|
respond "zZzzzzZzzzzZZZZZZzzzzzzzz", dest
|
14
15
|
@status = :paused
|
15
|
-
@bots_created[@channel_id][:status] = :paused
|
16
|
-
update_bots_file()
|
17
16
|
unless config.on_master_bot
|
17
|
+
@bots_created[@channel_id][:status] = :paused
|
18
|
+
update_bots_file()
|
18
19
|
send_msg_channel config.master_channel, "Changed status on #{config.channel} to :paused"
|
19
20
|
end
|
21
|
+
save_status :off, :paused, 'The admin paused this bot'
|
20
22
|
else
|
21
23
|
respond "Only admin users can put me on pause", dest
|
22
24
|
end
|
@@ -6,6 +6,7 @@ class SlackSmartBot
|
|
6
6
|
# helpadmin: NAME: one word to identify the routine
|
7
7
|
# helpadmin: Examples:
|
8
8
|
# helpadmin: _pause routine example_
|
9
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
|
9
10
|
# helpadmin:
|
10
11
|
def pause_routine(dest, from, name)
|
11
12
|
save_stats(__method__)
|
@@ -9,13 +9,12 @@ class SlackSmartBot
|
|
9
9
|
# helpadmin: NAME: one word to identify the routine
|
10
10
|
# helpadmin: Examples:
|
11
11
|
# helpadmin: _kill routine example_
|
12
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
|
12
13
|
# helpadmin:
|
13
14
|
def remove_routine(dest, from, name)
|
14
15
|
save_stats(__method__)
|
15
16
|
if config.admins.include?(from) #admin user
|
16
|
-
if
|
17
|
-
respond "It's only possible to remove routines from MASTER channel from a direct message with the bot.", dest
|
18
|
-
elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
|
17
|
+
if @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
|
19
18
|
@routines[@channel_id][name][:thread].exit
|
20
19
|
@routines[@channel_id].delete(name)
|
21
20
|
update_routines()
|
@@ -8,6 +8,7 @@ class SlackSmartBot
|
|
8
8
|
# helpadmin: NAME: one word to identify the routine
|
9
9
|
# helpadmin: Examples:
|
10
10
|
# helpadmin: _run routine example_
|
11
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
|
11
12
|
# helpadmin:
|
12
13
|
|
13
14
|
def run_routine(dest, from, name)
|
@@ -16,6 +17,7 @@ class SlackSmartBot
|
|
16
17
|
if !config.on_master_bot and dest[0] == "D"
|
17
18
|
respond "It's only possible to run routines from MASTER channel from a direct message with the bot.", dest
|
18
19
|
elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
|
20
|
+
File.delete "#{config.path}/routines/#{@channel_id}/#{name}_output.txt" if File.exists?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
|
19
21
|
if @routines[@channel_id][name][:file_path] != ""
|
20
22
|
if @routines[@channel_id][name][:file_path].match?(/\.rb$/i)
|
21
23
|
ruby = "ruby "
|
@@ -40,7 +42,10 @@ class SlackSmartBot
|
|
40
42
|
treat_message({ channel: @routines[@channel_id][name][:dest],
|
41
43
|
user: @routines[@channel_id][name][:creator_id],
|
42
44
|
text: @routines[@channel_id][name][:command],
|
43
|
-
files: nil
|
45
|
+
files: nil,
|
46
|
+
routine_name: name,
|
47
|
+
routine_type: @routines[@channel_id][name][:routine_type],
|
48
|
+
routine: true })
|
44
49
|
end
|
45
50
|
@routines[@channel_id][name][:last_elapsed] = (Time.now - started)
|
46
51
|
@routines[@channel_id][name][:last_run] = started.to_s
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
# helpadmin: ----------------------------------------------
|
4
|
+
# helpadmin: `see routine result NAME`
|
5
|
+
# helpadmin: `see result routine NAME`
|
6
|
+
# helpadmin: `result routine NAME`
|
7
|
+
# helpadmin: It will display the last result of the routine run.
|
8
|
+
# helpadmin: You can use this command only if you are an admin user
|
9
|
+
# helpadmin: NAME: one word to identify the routine
|
10
|
+
# helpadmin: Examples:
|
11
|
+
# helpadmin: _see routine result example_
|
12
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
|
13
|
+
# helpadmin:
|
14
|
+
def see_result_routine(dest, from, name)
|
15
|
+
save_stats(__method__)
|
16
|
+
if config.admins.include?(from) #admin user
|
17
|
+
if @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
|
18
|
+
if File.exist?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
|
19
|
+
msg = "*Results from routine run #{File.mtime("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")}*\n"
|
20
|
+
msg += File.read("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
|
21
|
+
respond msg, dest
|
22
|
+
else
|
23
|
+
respond "The routine *`#{name}`* doesn't have any result yet.", dest
|
24
|
+
end
|
25
|
+
else
|
26
|
+
respond "There isn't a routine with that name: *`#{name}`*.\nCall `see routines` to see added routines", dest
|
27
|
+
end
|
28
|
+
else
|
29
|
+
respond "Only admin users can see the routines results", dest
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -5,6 +5,7 @@ class SlackSmartBot
|
|
5
5
|
# helpadmin: It will show the routines of the channel
|
6
6
|
# helpadmin: In case of `all` and on the master channel, it will show all the routines from all channels
|
7
7
|
# helpadmin: You can use this command only if you are an admin user
|
8
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
|
8
9
|
# helpadmin:
|
9
10
|
def see_routines(dest, from, user, all)
|
10
11
|
save_stats(__method__)
|
@@ -23,8 +24,8 @@ class SlackSmartBot
|
|
23
24
|
routines = @routines.dup
|
24
25
|
end
|
25
26
|
else
|
26
|
-
if @rules_imported.key?(user.
|
27
|
-
file_conf = IO.readlines("#{config.path}/routines/routines_#{@rules_imported[user.
|
27
|
+
if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name) and dest[0] == "D"
|
28
|
+
file_conf = IO.readlines("#{config.path}/routines/routines_#{@rules_imported[user.name][user.name]}.rb").join
|
28
29
|
routines = eval(file_conf)
|
29
30
|
else
|
30
31
|
routines = @routines.dup
|
@@ -57,6 +58,7 @@ class SlackSmartBot
|
|
57
58
|
msg << "\tCommand: #{v[:command]}" unless v[:command].to_s.strip == ''
|
58
59
|
msg << "\tFile: #{v[:file_path]}" unless v[:file_path] == ''
|
59
60
|
msg << "\tSilent: #{v[:silent]}" unless !v[:silent]
|
61
|
+
msg << "\tType: #{v[:routine_type]}" if v[:routine_type].to_s == 'bgroutine'
|
60
62
|
respond msg.join("\n"), dest
|
61
63
|
end
|
62
64
|
end
|
@@ -5,17 +5,19 @@ class SlackSmartBot
|
|
5
5
|
# helpadmin: `start this bot`
|
6
6
|
# helpadmin: the bot will start to listen
|
7
7
|
# helpadmin: You can use this command only if you are an admin user
|
8
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
8
9
|
# helpadmin:
|
9
10
|
def start_bot(dest, from)
|
10
11
|
save_stats(__method__)
|
11
12
|
if config.admins.include?(from) #admin user
|
12
13
|
respond "This bot is running and listening from now on. You can pause again: pause this bot", dest
|
13
14
|
@status = :on
|
14
|
-
@bots_created[@channel_id][:status] = :on
|
15
|
-
update_bots_file()
|
16
15
|
unless config.on_master_bot
|
16
|
+
@bots_created[@channel_id][:status] = :on
|
17
|
+
update_bots_file()
|
17
18
|
send_msg_channel config.master_channel, "Changed status on #{config.channel} to :on"
|
18
19
|
end
|
20
|
+
save_status :on, :started, 'The admin started this bot'
|
19
21
|
else
|
20
22
|
respond "Only admin users can change my status", dest
|
21
23
|
end
|
@@ -7,6 +7,7 @@ class SlackSmartBot
|
|
7
7
|
# helpadmin: NAME: one word to identify the routine
|
8
8
|
# helpadmin: Examples:
|
9
9
|
# helpadmin: _start routine example_
|
10
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
|
10
11
|
# helpadmin:
|
11
12
|
|
12
13
|
def start_routine(dest, from, name)
|
@@ -3,6 +3,7 @@ class SlackSmartBot
|
|
3
3
|
# helpadmin: ----------------------------------------------
|
4
4
|
# helpadmin: `stop using rules on CHANNEL_NAME`
|
5
5
|
# helpadmin: it will stop using the extended rules on the specified channel.
|
6
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#extending-rules-to-other-channels|more info>
|
6
7
|
# helpadmin:
|
7
8
|
|
8
9
|
def stop_using_rules_on(dest, user, from, channel, typem)
|
@@ -12,6 +13,7 @@ class SlackSmartBot
|
|
12
13
|
respond "Only admins can extend or stop using the rules. Admins on this channel: #{config.admins}", dest
|
13
14
|
else
|
14
15
|
get_bots_created()
|
16
|
+
channel = @channels_name[channel] if @channels_name.key?(channel)
|
15
17
|
if @bots_created[@channel_id][:extended].include?(channel)
|
16
18
|
@bots_created[@channel_id][:extended].delete(channel)
|
17
19
|
update_bots_file()
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
# helpadmin: ----------------------------------------------
|
4
|
+
# helpadmin: `react to #CHANNEL_NAME THREAD_ID EMOJIS`
|
5
|
+
# helpadmin: It will send the specified reactions as SmartBot
|
6
|
+
# helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
|
7
|
+
# helpadmin: Examples:
|
8
|
+
# helpadmin: _react to #sales 1622550707.012100 :thumbsup:_
|
9
|
+
# helpadmin: _react to #sales p1622550707012100 :thumbsup:_
|
10
|
+
# helpadmin: _react to #sales p1622550707012100 :thumbsup: :heavy_check_mark: :bathtub:_
|
11
|
+
# helpadmin:
|
12
|
+
def react_to(dest, from, typem, to, thread_ts, emojis)
|
13
|
+
save_stats(__method__)
|
14
|
+
if config.masters.include?(from) and typem==:on_dm #master admin user
|
15
|
+
succs = []
|
16
|
+
emojis.split(' ').each do |emoji|
|
17
|
+
succs << (react emoji, thread_ts, to)
|
18
|
+
end
|
19
|
+
succs.uniq!
|
20
|
+
if succs.size == 1 and succs[0] == true
|
21
|
+
react :heavy_check_mark
|
22
|
+
elsif succs.size == 2
|
23
|
+
react :exclamation
|
24
|
+
else
|
25
|
+
react :x
|
26
|
+
end
|
27
|
+
else
|
28
|
+
respond "Only master admin users on a `pr`ivate conversation with the SmartBot can send reactions as SmartBot.", dest
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
# helpadmin: ----------------------------------------------
|
4
|
+
# helpadmin: `send message to @USER_NAME : MESSAGE`
|
5
|
+
# helpadmin: `send message to #CHANNEL_NAME : MESSAGE`
|
6
|
+
# helpadmin: `send message to #CHANNEL_NAME THREAD_ID : MESSAGE`
|
7
|
+
# helpadmin: It will send the specified message as SmartBot
|
8
|
+
# helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
|
9
|
+
# helpadmin:
|
10
|
+
def send_message(dest, from, typem, to, thread_ts, message)
|
11
|
+
save_stats(__method__)
|
12
|
+
if config.masters.include?(from) and typem==:on_dm #master admin user
|
13
|
+
succ = (respond message, to, thread_ts: thread_ts, web_client: true)
|
14
|
+
if succ
|
15
|
+
react :heavy_check_mark
|
16
|
+
else
|
17
|
+
react :x
|
18
|
+
end
|
19
|
+
else
|
20
|
+
respond "Only master admin users on a private conversation with the SmartBot can send messages as SmartBot.", dest
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -5,14 +5,12 @@ class SlackSmartBot
|
|
5
5
|
# help: `remove repl SESSION_NAME`
|
6
6
|
# help: Will delete the specified REPL
|
7
7
|
# help: Only the creator of the REPL or an admin can delete REPLs
|
8
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#repl|more info>
|
8
9
|
# help:
|
9
10
|
def delete_repl(dest, user, session_name)
|
10
11
|
#todo: add tests
|
11
12
|
save_stats(__method__)
|
12
|
-
if
|
13
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
14
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
15
|
-
else
|
13
|
+
if has_access?(__method__, user)
|
16
14
|
if @repls.key?(session_name)
|
17
15
|
Dir.mkdir("#{config.path}/repl") unless Dir.exist?("#{config.path}/repl")
|
18
16
|
if config.admins.include?(user.name) or @repls[session_name].creator_name == user.name
|
@@ -5,16 +5,14 @@ class SlackSmartBot
|
|
5
5
|
# help: `delete global sc NAME`
|
6
6
|
# help: It will delete the shortcut with the supplied name
|
7
7
|
# help: 'global' or 'generic' can only be used on Master channel.
|
8
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#shortcuts|more info>
|
8
9
|
# help:
|
9
10
|
|
10
11
|
def delete_shortcut(dest, user, shortcut, typem, command, global)
|
11
12
|
save_stats(__method__)
|
12
13
|
unless typem == :on_extended
|
13
14
|
from = user.name
|
14
|
-
if
|
15
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
16
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
17
|
-
else
|
15
|
+
if has_access?(__method__, user)
|
18
16
|
deleted = false
|
19
17
|
|
20
18
|
if global
|
@@ -4,14 +4,12 @@ class SlackSmartBot
|
|
4
4
|
# help: `get irb SESSION_NAME`
|
5
5
|
# help: `get live SESSION_NAME`
|
6
6
|
# help: Will get the Ruby commands sent on that SESSION_NAME.
|
7
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#repl|more info>
|
7
8
|
# help:
|
8
9
|
def get_repl(dest, user, session_name)
|
9
10
|
#todo: add tests
|
10
11
|
save_stats(__method__)
|
11
|
-
if
|
12
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
13
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
14
|
-
else
|
12
|
+
if has_access?(__method__, user)
|
15
13
|
Dir.mkdir("#{config.path}/repl") unless Dir.exist?("#{config.path}/repl")
|
16
14
|
Dir.mkdir("#{config.path}/repl/#{@channel_id}") unless Dir.exist?("#{config.path}/repl/#{@channel_id}")
|
17
15
|
if File.exist?("#{config.path}/repl/#{@channel_id}/#{session_name}.run")
|
@@ -19,7 +19,7 @@ class SlackSmartBot
|
|
19
19
|
# help: Send _quit_, _bye_ or _exit_ to finish the session.
|
20
20
|
# help: Send puts, print, p or pp if you want to print out something when using `run repl` later.
|
21
21
|
# help: After 30 minutes of no communication with the Smart Bot the session will be dismissed.
|
22
|
-
# help: If you declare on your rules file a method called
|
22
|
+
# help: If you declare on your rules file a method called 'project_folder' returning the path for the project folder, the code will be executed from that folder.
|
23
23
|
# help: By default it will be automatically loaded the gems: string_pattern, nice_hash and nice_http
|
24
24
|
# help: To pre-execute some ruby when starting the session add the code to .smart-bot-repl file on the project root folder defined on project_folder
|
25
25
|
# help: If you want to see the methods of a class or module you created use _ls TheModuleOrClass_
|
@@ -29,14 +29,12 @@ class SlackSmartBot
|
|
29
29
|
# help: _repl CreateCustomer: "It creates a random customer for testing" LOCATION=spain HOST='https://10.30.40.50:8887'_
|
30
30
|
# help: _repl delete_logs_
|
31
31
|
# help: _private repl random-ssn_
|
32
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#repl|more info>
|
32
33
|
# help:
|
33
34
|
def repl(dest, user, session_name, env_vars, rules_file, command, description, type)
|
34
35
|
#todo: add more tests
|
35
36
|
from = user.name
|
36
|
-
if
|
37
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
38
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
39
|
-
else
|
37
|
+
if has_access?(__method__, user)
|
40
38
|
if !@repl_sessions.key?(from)
|
41
39
|
save_stats(__method__)
|
42
40
|
Dir.mkdir("#{config.path}/repl") unless Dir.exist?("#{config.path}/repl")
|
@@ -147,7 +145,7 @@ class SlackSmartBot
|
|
147
145
|
rescue Exception => resp_repl
|
148
146
|
error = true
|
149
147
|
end
|
150
|
-
|
148
|
+
unless error
|
151
149
|
if code_to_run_repl.match?(/^\s*p\s+/i)
|
152
150
|
open(\"' + File.expand_path(config.path) + '/repl/' + @channel_id + '/' + session_name + '.output\", \"a+\") {|f|
|
153
151
|
f.puts \"\`\`\`\n#{resp_repl.inspect}\n\`\`\`\"
|
@@ -157,7 +155,7 @@ class SlackSmartBot
|
|
157
155
|
f.puts \"\`\`\`\n#{resp_repl.ai}\n\`\`\`\"
|
158
156
|
}
|
159
157
|
end
|
160
|
-
unless
|
158
|
+
unless !add_to_run_repl
|
161
159
|
open(\"' + File.expand_path(config.path) + '/repl/' + @channel_id + '/' + session_name + '.run\", \"a+\") {|f|
|
162
160
|
f.puts code_to_run_repl
|
163
161
|
}
|