class SlackSmartBot
def add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
save_stats(__method__)
unless typem == :on_extended
from = user.name
team_id_user = user.team_id + '_' + from
if has_access?(__method__, user)
shortcut_name.strip!
if global
if !config.on_master_bot or typem != :on_master
respond "It is only possible to add global shortcuts from Master channel"
else
@shortcuts_global[team_id_user] = Hash.new() unless @shortcuts_global.keys.include?(team_id_user)
found_other = false
if for_all.to_s != ""
@shortcuts_global.each { |sck, scv|
if sck != :all and sck != team_id_user and scv.key?(shortcut_name)
found_other = true
end
}
end
if @shortcuts_global[:all].include?(shortcut_name) or @shortcuts_global[team_id_user].include?(shortcut_name)
respond "Global shortcut name already in use. Please use another shortcut name."
elsif found_other
respond "You cannot create a global shortcut for all with the same name than other user is using."
elsif !@shortcuts_global[team_id_user].include?(shortcut_name)
@shortcuts_global[team_id_user][shortcut_name] = command_to_run
@shortcuts_global[:all][shortcut_name] = command_to_run if for_all.to_s != ""
update_shortcuts_file()
respond "global shortcut added"
else
respond "Not possible to add the global shortcut" end
end
else
@shortcuts[team_id_user] = Hash.new() unless @shortcuts.keys.include?(team_id_user)
found_other = false
if for_all.to_s != ""
@shortcuts.each { |sck, scv|
if sck != :all and sck != team_id_user and scv.key?(shortcut_name)
found_other = true
end
}
end
if !is_admin?(user) and @shortcuts[:all].include?(shortcut_name) and !@shortcuts[team_id_user].include?(shortcut_name)
respond "Only the creator of the shortcut can modify it", dest
elsif found_other
respond "You cannot create a shortcut for all with the same name than other user is using", dest
elsif !@shortcuts[team_id_user].include?(shortcut_name)
@shortcuts[team_id_user][shortcut_name] = command_to_run
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
update_shortcuts_file()
respond "shortcut added", dest
else
if answer.empty?
ask("The shortcut already exists, are you sure you want to overwrite it?", command, team_id_user, dest)
else
case answer
when /^(yes|yep)/i
@shortcuts[team_id_user][shortcut_name] = command_to_run
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
update_shortcuts_file()
respond "shortcut added", dest
answer_delete(team_id_user)
when /^no/i
respond "ok, I won't add it", dest
answer_delete(team_id_user)
else
ask "I don't understand, yes or no?", command, team_id_user, dest
end
end
end
end
end
end
end
end