slack-smart-bot 1.7.0 → 1.9.2
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 +24 -12
- data/lib/slack-smart-bot.rb +53 -43
- data/lib/slack-smart-bot_general_rules.rb +7 -4
- data/lib/slack-smart-bot_rules.rb +8 -6
- data/lib/slack/smart-bot/comm.rb +6 -1
- data/lib/slack/smart-bot/comm/ask.rb +12 -5
- data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
- data/lib/slack/smart-bot/comm/event_hello.rb +30 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +8 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +20 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +16 -0
- data/lib/slack/smart-bot/comm/react.rb +21 -8
- data/lib/slack/smart-bot/comm/respond.rb +38 -12
- data/lib/slack/smart-bot/comm/send_file.rb +1 -1
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
- data/lib/slack/smart-bot/comm/send_msg_user.rb +4 -4
- data/lib/slack/smart-bot/comm/unreact.rb +29 -0
- data/lib/slack/smart-bot/commands.rb +3 -1
- data/lib/slack/smart-bot/commands/general/bot_help.rb +16 -3
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +313 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +1 -1
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +1 -1
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +1 -1
- data/lib/slack/smart-bot/commands/general/use_rules.rb +6 -9
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +65 -33
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +42 -9
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +3 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +9 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +52 -21
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +5 -5
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +50 -18
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +34 -9
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +27 -9
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +14 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +41 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +4 -8
- data/lib/slack/smart-bot/listen.rb +6 -5
- data/lib/slack/smart-bot/process.rb +230 -186
- data/lib/slack/smart-bot/process_first.rb +104 -87
- data/lib/slack/smart-bot/treat_message.rb +128 -52
- data/lib/slack/smart-bot/utils.rb +2 -0
- 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 +48 -8
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +79 -17
- data/lib/slack/smart-bot/utils/save_stats.rb +21 -8
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/whats_new.txt +24 -0
- metadata +23 -13
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -135
@@ -14,7 +14,7 @@ class SlackSmartBot
|
|
14
14
|
gems_remote = `gem list slack-smart-bot --remote`
|
15
15
|
version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
|
16
16
|
version_message = ""
|
17
|
-
if version_remote
|
17
|
+
if Gem::Version.new(version_remote) > Gem::Version.new(VERSION)
|
18
18
|
version_message = " There is a new available version: #{version_remote}."
|
19
19
|
end
|
20
20
|
require "socket"
|
@@ -4,8 +4,8 @@ class SlackSmartBot
|
|
4
4
|
# help: `Bye Bot`
|
5
5
|
# help: `Bye Smart`
|
6
6
|
# help: `Bye NAME_OF_THE_BOT`
|
7
|
-
# help: Also apart of Bye you can use _Bæ, Good Bye, Adiós, Ciao, Bless, Bless Bless, Adeu_
|
8
7
|
# help: Bot stops listening to you
|
8
|
+
# help: Also apart of Bye you can use _Bæ, Good Bye, Adiós, Ciao, Bless, Bless Bless, Adeu_
|
9
9
|
# help:
|
10
10
|
def bye_bot(dest, from, display_name)
|
11
11
|
if @status == :on
|
@@ -5,9 +5,9 @@ class SlackSmartBot
|
|
5
5
|
# help: `Hi Smart`
|
6
6
|
# help: `Hello Bot` `Hola Bot` `Hallo Bot` `What's up Bot` `Hey Bot` `Hæ Bot`
|
7
7
|
# help: `Hello THE_NAME_OF_THE_BOT`
|
8
|
-
# help: Also apart of Hello you can use _Hallo, Hi, Hola, What's up, Hey, Hæ_
|
9
8
|
# help: Bot starts listening to you
|
10
9
|
# help: After that if you want to avoid a single message to be treated by the smart bot, start the message by -
|
10
|
+
# help: Also apart of Hello you can use _Hallo, Hi, Hola, What's up, Hey, Hæ_
|
11
11
|
# help:
|
12
12
|
def hi_bot(user, dest, dchannel, from, display_name)
|
13
13
|
if @status == :on
|
@@ -15,17 +15,14 @@ class SlackSmartBot
|
|
15
15
|
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
16
16
|
else
|
17
17
|
#todo: add pagination for case more than 1000 channels on the workspace
|
18
|
-
channels =
|
19
|
-
|
20
|
-
limit: "1000",
|
21
|
-
exclude_archived: "true",
|
22
|
-
).channels
|
23
|
-
|
18
|
+
channels = get_channels()
|
19
|
+
channel.gsub!('#','') # for the case the channel name is in plain text including #
|
24
20
|
channel_found = channels.detect { |c| c.name == channel }
|
25
|
-
|
21
|
+
get_channels_name_and_id() unless @channels_id.key?(channel)
|
22
|
+
members = get_channel_members(@channels_id[channel]) unless channel_found.nil? or !@channels_id.key?(channel)
|
26
23
|
|
27
|
-
if channel_found.nil?
|
28
|
-
respond "The channel you are trying to use doesn't exist", dest
|
24
|
+
if channel_found.nil? or !@channels_id.key?(channel)
|
25
|
+
respond "The channel you are trying to use doesn't exist or cannot be found.", dest
|
29
26
|
elsif channel_found.name == config.master_channel
|
30
27
|
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
31
28
|
elsif !@bots_created.key?(@channels_id[channel])
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
# help: ----------------------------------------------
|
4
|
+
# help: `What's new`
|
5
|
+
# help: It will display the last user changes on Slack Smart Bot
|
6
|
+
# help:
|
7
|
+
def whats_new(user, dest, dchannel, from, display_name)
|
8
|
+
if @status == :on
|
9
|
+
save_stats(__method__)
|
10
|
+
whats_new_file = (__FILE__).gsub(/lib\/slack\/smart-bot\/commands\/general\/whats_new\.rb$/, "whats_new.txt")
|
11
|
+
whats_new = File.read(whats_new_file)
|
12
|
+
whats_new.split(/^\-\-\-\-\-\-+$/).each do |msg|
|
13
|
+
respond msg
|
14
|
+
sleep 0.3
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -7,8 +7,10 @@ class SlackSmartBot
|
|
7
7
|
# help: `add sc for all NAME: COMMAND`
|
8
8
|
# help: `shortcut NAME: COMMAND`
|
9
9
|
# help: `shortcut for all NAME: COMMAND`
|
10
|
+
# help: `add global sc for all NAME: COMMAND`
|
10
11
|
# help: It will add a shortcut that will execute the command we supply.
|
11
12
|
# help: In case we supply 'for all' then the shorcut will be available for everybody
|
13
|
+
# help: If 'global' or 'generic' supplied and in Master channel then the shortcut will be available in all Bot channels.
|
12
14
|
# help: If you want to use a shortcut as a inline shortcut inside a command you can do it by adding a $ fex: _!run tests $cust1_
|
13
15
|
# help: Example:
|
14
16
|
# help: _add shortcut for all Spanish account: code require 'iso/iban'; 10.times {puts ISO::IBAN.random('ES')}_
|
@@ -17,7 +19,7 @@ class SlackSmartBot
|
|
17
19
|
# help: _shortcut Spanish Account_
|
18
20
|
# help: _Spanish Account_
|
19
21
|
# help:
|
20
|
-
def add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run)
|
22
|
+
def add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
|
21
23
|
save_stats(__method__)
|
22
24
|
unless typem == :on_extended
|
23
25
|
from = user.name
|
@@ -25,43 +27,73 @@ class SlackSmartBot
|
|
25
27
|
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
26
28
|
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
27
29
|
else
|
28
|
-
@shortcuts[from] = Hash.new() unless @shortcuts.keys.include?(from)
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
if global
|
32
|
+
if !config.on_master_bot or typem != :on_master
|
33
|
+
respond "It is only possible to add global shortcuts from Master channel"
|
34
|
+
else
|
35
|
+
@shortcuts_global[from] = Hash.new() unless @shortcuts_global.keys.include?(from)
|
36
|
+
found_other = false
|
37
|
+
if for_all.to_s != ""
|
38
|
+
@shortcuts_global.each { |sck, scv|
|
39
|
+
if sck != :all and sck != from and scv.key?(shortcut_name)
|
40
|
+
found_other = true
|
41
|
+
end
|
42
|
+
}
|
35
43
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
if @shortcuts_global[:all].include?(shortcut_name) or @shortcuts_global[from].include?(shortcut_name)
|
45
|
+
respond "Global shortcut name already in use. Please use another shortcut name."
|
46
|
+
elsif found_other
|
47
|
+
respond "You cannot create a global shortcut for all with the same name than other user is using."
|
48
|
+
elsif !@shortcuts_global[from].include?(shortcut_name)
|
49
|
+
#new shortcut
|
50
|
+
@shortcuts_global[from][shortcut_name] = command_to_run
|
51
|
+
@shortcuts_global[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
52
|
+
update_shortcuts_file()
|
53
|
+
respond "global shortcut added"
|
54
|
+
else
|
55
|
+
respond "Not possible to add the global shortcut" #todo: check if this is ever gonna be the case
|
56
|
+
end
|
57
|
+
end
|
48
58
|
else
|
49
|
-
|
50
|
-
|
51
|
-
|
59
|
+
@shortcuts[from] = Hash.new() unless @shortcuts.keys.include?(from)
|
60
|
+
|
61
|
+
found_other = false
|
62
|
+
if for_all.to_s != ""
|
63
|
+
@shortcuts.each { |sck, scv|
|
64
|
+
if sck != :all and sck != from and scv.key?(shortcut_name)
|
65
|
+
found_other = true
|
66
|
+
end
|
67
|
+
}
|
68
|
+
end
|
69
|
+
if !config.admins.include?(from) and @shortcuts[:all].include?(shortcut_name) and !@shortcuts[from].include?(shortcut_name)
|
70
|
+
respond "Only the creator of the shortcut can modify it", dest
|
71
|
+
elsif found_other
|
72
|
+
respond "You cannot create a shortcut for all with the same name than other user is using", dest
|
73
|
+
elsif !@shortcuts[from].include?(shortcut_name)
|
74
|
+
#new shortcut
|
75
|
+
@shortcuts[from][shortcut_name] = command_to_run
|
76
|
+
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
77
|
+
update_shortcuts_file()
|
78
|
+
respond "shortcut added", dest
|
52
79
|
else
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
57
|
-
update_shortcuts_file()
|
58
|
-
respond "shortcut added", dest
|
59
|
-
@questions.delete(from)
|
60
|
-
when /^no/i
|
61
|
-
respond "ok, I won't add it", dest
|
62
|
-
@questions.delete(from)
|
80
|
+
#are you sure? to avoid overwriting existing
|
81
|
+
if answer.empty?
|
82
|
+
ask("The shortcut already exists, are you sure you want to overwrite it?", command, from, dest)
|
63
83
|
else
|
64
|
-
|
84
|
+
case answer
|
85
|
+
when /^(yes|yep)/i
|
86
|
+
@shortcuts[from][shortcut_name] = command_to_run
|
87
|
+
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
88
|
+
update_shortcuts_file()
|
89
|
+
respond "shortcut added", dest
|
90
|
+
answer_delete(from)
|
91
|
+
when /^no/i
|
92
|
+
respond "ok, I won't add it", dest
|
93
|
+
answer_delete(from)
|
94
|
+
else
|
95
|
+
ask "I don't understand, yes or no?", command, from, dest
|
96
|
+
end
|
65
97
|
end
|
66
98
|
end
|
67
99
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
# helpadmin: ----------------------------------------------
|
3
3
|
# helpadmin: `add routine NAME every NUMBER PERIOD COMMAND`
|
4
|
+
# helpadmin: `add routine NAME every NUMBER PERIOD #CHANNEL COMMAND`
|
4
5
|
# helpadmin: `add routine NAME every NUMBER PERIOD`
|
5
6
|
# helpadmin: `add silent routine NAME every NUMBER PERIOD`
|
6
7
|
# helpadmin: `create routine NAME every NUMBER PERIOD`
|
7
8
|
# helpadmin: `add routine NAME at TIME COMMAND`
|
9
|
+
# helpadmin: `add routine NAME at TIME #CHANNEL COMMAND`
|
10
|
+
# helpadmin: `add routine NAME on DAYWEEK at TIME COMMAND`
|
11
|
+
# helpadmin: `add routine NAME on DAYWEEK at TIME #CHANNEL COMMAND`
|
8
12
|
# helpadmin: `add routine NAME at TIME`
|
9
13
|
# helpadmin: `add silent routine NAME at TIME`
|
10
14
|
# helpadmin: `create routine NAME at TIME`
|
@@ -15,14 +19,18 @@ class SlackSmartBot
|
|
15
19
|
# helpadmin: NUMBER: Integer
|
16
20
|
# helpadmin: PERIOD: days, d, hours, h, minutes, mins, min, m, seconds, secs, sec, s
|
17
21
|
# helpadmin: TIME: time at format HH:MM:SS
|
22
|
+
# helpadmin: DAYWEEK: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. And their plurals.
|
23
|
+
# 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.
|
18
24
|
# helpadmin: COMMAND: any valid smart bot command or rule
|
19
25
|
# helpadmin: Examples:
|
20
26
|
# helpadmin: _add routine example every 30s ruby puts 'a'_
|
21
27
|
# helpadmin: _add routine example every 3 days ruby puts 'a'_
|
22
28
|
# helpadmin: _add routine example at 17:05 ruby puts 'a'_
|
23
|
-
# helpadmin: _create silent routine every 12 hours !Run customer tests_
|
29
|
+
# helpadmin: _create silent routine Example every 12 hours !Run customer tests_
|
30
|
+
# helpadmin: _add routine example on Mondays at 05:00 !run customer tests_
|
31
|
+
# helpadmin: _add routine example on Tuesdays at 09:00 #SREChannel !run db cleanup_
|
24
32
|
# helpadmin:
|
25
|
-
def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent)
|
33
|
+
def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel)
|
26
34
|
save_stats(__method__)
|
27
35
|
if files.nil? or files.size == 0 or (files.size > 0 and config.masters.include?(from))
|
28
36
|
if config.admins.include?(from)
|
@@ -30,13 +38,14 @@ class SlackSmartBot
|
|
30
38
|
respond "I'm sorry but there is already a routine with that name.\nCall `see routines` to see added routines", dest
|
31
39
|
else
|
32
40
|
number_time += ":00" if number_time.split(":").size == 2
|
33
|
-
if (type
|
41
|
+
if (type != "every") && !number_time.match?(/^[01][0-9]:[0-5][0-9]:[0-5][0-9]$/) &&
|
34
42
|
!number_time.match?(/^2[0-3]:[0-5][0-9]:[0-5][0-9]$/)
|
35
43
|
respond "Wrong time specified: *#{number_time}*"
|
36
44
|
else
|
37
45
|
file_path = ""
|
38
46
|
every = ""
|
39
47
|
at = ""
|
48
|
+
dayweek = ''
|
40
49
|
next_run = Time.now
|
41
50
|
case period.downcase
|
42
51
|
when "days", "d"
|
@@ -52,16 +61,31 @@ class SlackSmartBot
|
|
52
61
|
every = "#{number_time} seconds"
|
53
62
|
every_in_seconds = number_time.to_i
|
54
63
|
else # time
|
64
|
+
if type != 'at'
|
65
|
+
dayweek = type.downcase
|
66
|
+
days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday']
|
67
|
+
incr = days.index(dayweek) - Time.now.wday
|
68
|
+
if incr < 0
|
69
|
+
incr = (7+incr)*24*60*60
|
70
|
+
else
|
71
|
+
incr = incr * 24 * 60 * 60
|
72
|
+
end
|
73
|
+
days = incr/(24*60*60)
|
74
|
+
every_in_seconds = 7 * 24 * 60 * 60 # one week
|
75
|
+
else
|
76
|
+
days = 0
|
77
|
+
every_in_seconds = 24 * 60 * 60 # one day
|
78
|
+
end
|
79
|
+
|
55
80
|
at = number_time
|
56
|
-
if next_run.strftime("%H:%M:%S") < number_time
|
81
|
+
if next_run.strftime("%H:%M:%S") < number_time and days == 0
|
57
82
|
nt = number_time.split(":")
|
58
83
|
next_run = Time.new(next_run.year, next_run.month, next_run.day, nt[0], nt[1], nt[2])
|
59
84
|
else
|
60
|
-
next_run += (24 * 60 * 60) # one more
|
85
|
+
next_run += ((24 * 60 * 60) * days) # one or more days
|
61
86
|
nt = number_time.split(":")
|
62
87
|
next_run = Time.new(next_run.year, next_run.month, next_run.day, nt[0], nt[1], nt[2])
|
63
88
|
end
|
64
|
-
every_in_seconds = 24 * 60 * 60
|
65
89
|
end
|
66
90
|
Dir.mkdir("#{config.path}/routines/#{@channel_id}") unless Dir.exist?("#{config.path}/routines/#{@channel_id}")
|
67
91
|
|
@@ -75,12 +99,21 @@ class SlackSmartBot
|
|
75
99
|
http.get(files[0].url_private_download, save_data: file_path)
|
76
100
|
system("chmod +x #{file_path}")
|
77
101
|
end
|
78
|
-
|
102
|
+
get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
|
103
|
+
channel_id = nil
|
104
|
+
if @channels_name.key?(channel) #it is an id
|
105
|
+
channel_id = channel
|
106
|
+
channel = @channels_name[channel_id]
|
107
|
+
elsif @channels_id.key?(channel) #it is a channel name
|
108
|
+
channel_id = @channels_id[channel]
|
109
|
+
end
|
110
|
+
|
111
|
+
channel_id = dest if channel_id.to_s == ''
|
79
112
|
@routines[@channel_id] = {} unless @routines.key?(@channel_id)
|
80
113
|
@routines[@channel_id][name] = { channel_name: config.channel, creator: from, creator_id: user.id, status: :on,
|
81
|
-
every: every, every_in_seconds: every_in_seconds, at: at, file_path: file_path,
|
114
|
+
every: every, every_in_seconds: every_in_seconds, at: at, dayweek: dayweek, file_path: file_path,
|
82
115
|
command: command_to_run.to_s.strip, silent: silent,
|
83
|
-
next_run: next_run.to_s, dest:
|
116
|
+
next_run: next_run.to_s, dest: channel_id, last_run: "", last_elapsed: "",
|
84
117
|
running: false }
|
85
118
|
update_routines
|
86
119
|
respond "Added routine *`#{name}`* to the channel", dest
|
@@ -14,15 +14,11 @@ class SlackSmartBot
|
|
14
14
|
respond "Only admins can extend the rules. Admins on this channel: #{config.admins}", dest
|
15
15
|
else
|
16
16
|
#todo: add pagination for case more than 1000 channels on the workspace
|
17
|
-
channels =
|
18
|
-
types: "private_channel,public_channel",
|
19
|
-
limit: "1000",
|
20
|
-
exclude_archived: "true",
|
21
|
-
).channels
|
17
|
+
channels = get_channels()
|
22
18
|
|
23
19
|
channel_found = channels.detect { |c| c.name == channel }
|
24
20
|
get_channels_name_and_id()
|
25
|
-
members =
|
21
|
+
members = get_channel_members(@channels_id[channel]) unless channel_found.nil?
|
26
22
|
get_bots_created()
|
27
23
|
channels_in_use = []
|
28
24
|
@bots_created.each do |k, v|
|
@@ -39,7 +35,7 @@ class SlackSmartBot
|
|
39
35
|
elsif !members.include?(user.id)
|
40
36
|
respond "You need to join that channel first", dest
|
41
37
|
elsif !members.include?(config[:nick_id])
|
42
|
-
respond "You need to add first to the channel the smart bot user:
|
38
|
+
respond "You need to add first to the channel the smart bot user: <@#{config[:nick_id]}>", dest
|
43
39
|
else
|
44
40
|
channels_in_use.each do |channel_in_use|
|
45
41
|
respond "The rules from channel <##{@channels_id[channel_in_use]}> are already in use on that channel", dest
|
@@ -13,6 +13,7 @@ class SlackSmartBot
|
|
13
13
|
respond "zZzzzzZzzzzZZZZZZzzzzzzzz", dest
|
14
14
|
@status = :paused
|
15
15
|
@bots_created[@channel_id][:status] = :paused
|
16
|
+
update_bots_file()
|
16
17
|
unless config.on_master_bot
|
17
18
|
send_msg_channel config.master_channel, "Changed status on #{config.channel} to :paused"
|
18
19
|
end
|
@@ -38,12 +38,19 @@ class SlackSmartBot
|
|
38
38
|
respond "Routines on channel *#{rout_ch.get_values(:channel_name).values.flatten.uniq[0]}*", dest
|
39
39
|
rout_ch.each do |k, v|
|
40
40
|
msg = []
|
41
|
-
|
42
|
-
|
41
|
+
if v[:dest][0] == 'D'
|
42
|
+
extram = " (*DM to #{v[:creator]}*)"
|
43
|
+
elsif v[:dest] != ch
|
44
|
+
extram = " (*publish on <##{v[:dest]}>*)"
|
45
|
+
else
|
46
|
+
extram = ''
|
47
|
+
end
|
48
|
+
msg << "*`#{k}`*#{extram}"
|
43
49
|
msg << "\tCreator: #{v[:creator]}"
|
44
50
|
msg << "\tStatus: #{v[:status]}"
|
45
51
|
msg << "\tEvery: #{v[:every]}" unless v[:every] == ""
|
46
52
|
msg << "\tAt: #{v[:at]}" unless v[:at] == ""
|
53
|
+
msg << "\tOn: #{v[:dayweek]}" unless !v.key?(:dayweek) or v[:dayweek].to_s == ""
|
47
54
|
msg << "\tNext Run: #{v[:next_run]}"
|
48
55
|
msg << "\tLast Run: #{v[:last_run]}"
|
49
56
|
msg << "\tTime consumed on last run: #{v[:last_elapsed]}" unless v[:command] !=''
|
@@ -12,6 +12,7 @@ class SlackSmartBot
|
|
12
12
|
respond "This bot is running and listening from now on. You can pause again: pause this bot", dest
|
13
13
|
@status = :on
|
14
14
|
@bots_created[@channel_id][:status] = :on
|
15
|
+
update_bots_file()
|
15
16
|
unless config.on_master_bot
|
16
17
|
send_msg_channel config.master_channel, "Changed status on #{config.channel} to :on"
|
17
18
|
end
|
@@ -3,7 +3,6 @@ class SlackSmartBot
|
|
3
3
|
# help: `delete repl SESSION_NAME`
|
4
4
|
# help: `delete irb SESSION_NAME`
|
5
5
|
# help: `remove repl SESSION_NAME`
|
6
|
-
# help:
|
7
6
|
# help: Will delete the specified REPL
|
8
7
|
# help: Only the creator of the REPL or an admin can delete REPLs
|
9
8
|
# help:
|
@@ -20,6 +19,7 @@ class SlackSmartBot
|
|
20
19
|
@repls.delete(session_name)
|
21
20
|
update_repls()
|
22
21
|
File.rename("#{config.path}/repl/#{@channel_id}/#{session_name}.input", "#{config.path}/repl/#{@channel_id}/#{session_name}_#{Time.now.strftime("%Y%m%d%H%M%S%N")}.deleted")
|
22
|
+
File.delete("#{config.path}/repl/#{@channel_id}/#{session_name}.output") if File.exist?("#{config.path}/repl/#{@channel_id}/#{session_name}.output")
|
23
23
|
File.delete("#{config.path}/repl/#{@channel_id}/#{session_name}.run") if File.exist?("#{config.path}/repl/#{@channel_id}/#{session_name}.run")
|
24
24
|
respond "REPL #{session_name} deleted"
|
25
25
|
else
|
@@ -2,10 +2,12 @@ class SlackSmartBot
|
|
2
2
|
# help: ----------------------------------------------
|
3
3
|
# help: `delete shortcut NAME`
|
4
4
|
# help: `delete sc NAME`
|
5
|
+
# help: `delete global sc NAME`
|
5
6
|
# help: It will delete the shortcut with the supplied name
|
7
|
+
# help: 'global' or 'generic' can only be used on Master channel.
|
6
8
|
# help:
|
7
9
|
|
8
|
-
def delete_shortcut(dest, user, shortcut, typem, command)
|
10
|
+
def delete_shortcut(dest, user, shortcut, typem, command, global)
|
9
11
|
save_stats(__method__)
|
10
12
|
unless typem == :on_extended
|
11
13
|
from = user.name
|
@@ -15,32 +17,61 @@ class SlackSmartBot
|
|
15
17
|
else
|
16
18
|
deleted = false
|
17
19
|
|
18
|
-
if
|
19
|
-
|
20
|
-
|
21
|
-
(config.admins.include?(from) and @shortcuts[:all].include?(shortcut))
|
22
|
-
#are you sure? to avoid deleting by mistake
|
23
|
-
unless @questions.keys.include?(from)
|
24
|
-
ask("are you sure you want to delete it?", command, from, dest)
|
20
|
+
if global
|
21
|
+
if !config.on_master_bot or typem != :on_master
|
22
|
+
respond "It is only possible to delete global shortcuts from Master channel"
|
25
23
|
else
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
if !config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut) and
|
25
|
+
(!@shortcuts_global.key?(from) or !@shortcuts_global[from].include?(shortcut))
|
26
|
+
respond "Only the creator of the shortcut or an admin user can delete it"
|
27
|
+
elsif (@shortcuts_global.key?(from) and @shortcuts_global[from].keys.include?(shortcut)) or
|
28
|
+
(config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut))
|
29
|
+
|
30
|
+
respond "global shortcut deleted!", dest
|
31
|
+
if @shortcuts_global.key?(from) and @shortcuts_global[from].key?(shortcut)
|
32
|
+
respond("#{shortcut}: #{@shortcuts_global[from][shortcut]}", dest)
|
33
|
+
elsif @shortcuts_global.key?(:all) and @shortcuts_global[:all].key?(shortcut)
|
34
|
+
respond("#{shortcut}: #{@shortcuts_global[:all][shortcut]}", dest)
|
35
|
+
end
|
36
|
+
@shortcuts_global[from].delete(shortcut) if @shortcuts_global.key?(from) and @shortcuts_global[from].key?(shortcut)
|
37
|
+
@shortcuts_global[:all].delete(shortcut) if @shortcuts_global.key?(:all) and @shortcuts_global[:all].key?(shortcut)
|
34
38
|
update_shortcuts_file()
|
35
|
-
when /^no/i
|
36
|
-
@questions.delete(from)
|
37
|
-
respond "ok, I won't delete it", dest
|
38
39
|
else
|
39
|
-
|
40
|
+
respond 'shortcut not found'
|
40
41
|
end
|
41
42
|
end
|
42
43
|
else
|
43
|
-
|
44
|
+
if !config.admins.include?(from) and @shortcuts[:all].include?(shortcut) and
|
45
|
+
(!@shortcuts.key?(from) or !@shortcuts[from].include?(shortcut))
|
46
|
+
respond "Only the creator of the shortcut or an admin user can delete it", dest
|
47
|
+
elsif (@shortcuts.keys.include?(from) and @shortcuts[from].keys.include?(shortcut)) or
|
48
|
+
(config.admins.include?(from) and @shortcuts[:all].include?(shortcut))
|
49
|
+
#are you sure? to avoid deleting by mistake
|
50
|
+
if answer.empty?
|
51
|
+
ask("are you sure you want to delete it?", command, from, dest)
|
52
|
+
else
|
53
|
+
case answer
|
54
|
+
when /^(yes|yep)/i
|
55
|
+
answer_delete(from)
|
56
|
+
respond "shortcut deleted!", dest
|
57
|
+
if @shortcuts.key?(from) and @shortcuts[from].key?(shortcut)
|
58
|
+
respond("#{shortcut}: #{@shortcuts[from][shortcut]}", dest)
|
59
|
+
elsif @shortcuts.key?(:all) and @shortcuts[:all].key?(shortcut)
|
60
|
+
respond("#{shortcut}: #{@shortcuts[:all][shortcut]}", dest)
|
61
|
+
end
|
62
|
+
@shortcuts[from].delete(shortcut) if @shortcuts.key?(from) and @shortcuts[from].key?(shortcut)
|
63
|
+
@shortcuts[:all].delete(shortcut) if @shortcuts.key?(:all) and @shortcuts[:all].key?(shortcut)
|
64
|
+
update_shortcuts_file()
|
65
|
+
when /^no/i
|
66
|
+
answer_delete(from)
|
67
|
+
respond "ok, I won't delete it", dest
|
68
|
+
else
|
69
|
+
ask("I don't understand, are you sure you want to delete it? (yes or no)", command, from, dest)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
else
|
73
|
+
respond "shortcut not found", dest
|
74
|
+
end
|
44
75
|
end
|
45
76
|
end
|
46
77
|
end
|