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
if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
else
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[from] = Hash.new() unless @shortcuts_global.keys.include?(from)
found_other = false
if for_all.to_s != ""
@shortcuts_global.each { |sck, scv|
if sck != :all and sck != from and scv.key?(shortcut_name)
found_other = true
end
}
end
if @shortcuts_global[:all].include?(shortcut_name) or @shortcuts_global[from].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[from].include?(shortcut_name)
@shortcuts_global[from][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[from] = Hash.new() unless @shortcuts.keys.include?(from)
found_other = false
if for_all.to_s != ""
@shortcuts.each { |sck, scv|
if sck != :all and sck != from and scv.key?(shortcut_name)
found_other = true
end
}
end
if !config.admins.include?(from) and @shortcuts[:all].include?(shortcut_name) and !@shortcuts[from].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[from].include?(shortcut_name)
@shortcuts[from][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, from, dest)
else
case answer
when /^(yes|yep)/i
@shortcuts[from][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(from)
when /^no/i
respond "ok, I won't add it", dest
answer_delete(from)
else
ask "I don't understand, yes or no?", command, from, dest
end
end
end
end
end
end
end
end