class SlackSmartBot
def see_routines(dest, from, user, all, , regexp)
save_stats(__method__)
if is_admin?
react :running
if all
routines = {}
if config.on_master_bot
Dir["#{config.path}/routines/routines_*.yaml"].each do |rout|
routine = YAML.load(File.read(rout))
unless routine.is_a?(FalseClass)
routines.merge!(routine)
end
end
else
respond "To see all routines on all channels you need to run the command on the master channel.\nI'll display only the routines on this channel.", dest
routines = @routines
end
else
if @rules_imported.key?("#{user.team_id}_#{user.name}") and @rules_imported["#{user.team_id}_#{user.name}"].key?(user.name) and dest[0] == "D"
routines = YAML.load(File.read("#{config.path}/routines/routines_#{@rules_imported["#{user.team_id}_#{user.name}"][user.name]}.yaml"))
routines = {} if routines.is_a?(FalseClass)
else
routines = @routines
end
end
if != ''
routines_filtered = {}
routines.each do |ch, rout_ch|
routines_filtered[ch] = rout_ch.dup
rout_ch.each do |k, v|
if == 'name'
if k.match(/#{regexp}/i).nil?
routines_filtered[ch].delete(k)
end
elsif v[.to_sym].to_s.match(/#{regexp}/i).nil?
routines_filtered[ch].delete(k)
end
end
end
routines = routines_filtered
end
if routines.get_values(:channel_name).size == 0
if != ''
respond "There are no routines added that match the header *#{}* and the regexp *#{regexp}*.", dest
else
respond "There are no routines added.", dest
end
else
routines.each do |ch, rout_ch|
if != ''
respond "Routines on channel *#{rout_ch.get_values(:channel_name).values.flatten.uniq[0]}* that match the header *#{}* and the regexp *#{regexp}*", dest
else
respond "Routines on channel *#{rout_ch.get_values(:channel_name).values.flatten.uniq[0]}*", dest
end
rout_ch.each do |k, v|
msg = []
if v[:dest][0] == 'D'
= " (*DM to #{v[:creator]}*)"
elsif v[:dest] != ch
= " (*publish on <##{v[:dest]}>*)"
else
= ''
end
msg << "*`#{k}`*#{}"
msg << "\tCreator: #{v[:creator]}"
msg << "\tStatus: #{v[:status]}"
msg << "\tEvery: #{v[:every]}" unless v[:every] == ""
msg << "\tAt: #{v[:at]}" unless v[:at] == ""
msg << "\tOn: #{v[:dayweek]}" unless !v.key?(:dayweek) or v[:dayweek].to_s == ""
msg << "\tNext Run: #{v[:next_run]}"
msg << "\tLast Run: #{v[:last_run]}"
msg << "\tTime consumed on last run: #{v[:last_elapsed]}" unless v[:command] !=''
msg << "\tCommand: #{v[:command]}" unless v[:command].to_s.strip == ''
msg << "\tFile: #{v[:file_path]}" unless v[:file_path] == ''
msg << "\tSilent: #{v[:silent]}" unless !v[:silent]
msg << "\tType: #{v[:routine_type]}" if v[:routine_type].to_s == 'bgroutine'
respond msg.join("\n"), dest
end
end
end
unreact :running
else
respond "Only admin users can use this command", dest
end
end
end